SlideShare a Scribd company logo
ParallelStreams
Concurrent data processing in Java 8
David Gómez G.
@dgomezg
dgomezg@autentia.com
Do you remember?
use stream()
for (int i = 0; i < 100; i++) {

long start = System.currentTimeMillis();

List<Integer> even = numbers.parallelStream()

.filter(n -> n % 2 == 0)

.sorted()

.collect(toList());


System.out.printf(
"%d elements computed in %5d msecs with %d threadsn”,

even.size(), System.currentTimeMillis() - start,
Thread.activeCount());

}
4999299 elements computed in 225 msecs with 9 threads
4999299 elements computed in 230 msecs with 9 threads
4999299 elements computed in 250 msecs with 9 threads
@dgomezg
Previously on…
Streams?
What’s that?
A Stream is…
An convenience method to iterate over
collections in a declarative way
List<Integer>  numbers  =  new  ArrayList<Integer>();

for  (int  i=  0;  i  <  100  ;  i++)  {

   numbers.add(i);

}  
List<Integer> evenNumbers = numbers.stream()

.filter(n -> n % 2 == 0)

.collect(toList());
@dgomezg
Anatomy of a Stream
Source
Intermediate
Operations
filter
map
order
function
Final
operation
pipeline
@dgomezg
Iterating a Stream
List<Integer> evenNumbers = numbers.stream()

.filter(n -> n % 2 == 0)

.collect(toList());
Internal Iteration
- No manual Iterators handling
- Concise
- Fluent API: chain sequence processing
Elements computed only when needed
@dgomezg
Iterating a Stream
List<Integer> evenNumbers = numbers.parallelStream()

.filter(n -> n % 2 == 0)

.collect(toList());
Easily Parallelism
- Concurrency is hard to be done right!
- Uses ForkJoin
- Process steps should be
- stateless
- independent
@dgomezg
Parallel Streams
use stream()
List<Integer> numbers = new ArrayList<>();

for (int i= 0; i < 10_000_000 ; i++) {

numbers.add((int)Math.round(Math.random()*100));

}
//This will use just a single thread
Stream<Integer> evenNumbers = numbers.stream();
or parallelStream()
//Automatically select the optimum number of threads
Stream<Integer> evenNumbers = numbers.parallelStream();
@dgomezg
Let’s test it
use stream()
for (int i = 0; i < 100; i++) {

long start = System.currentTimeMillis();

List<Integer> even = numbers.stream()

.filter(n -> n % 2 == 0)

.sorted()

.collect(toList());


System.out.printf(
"%d elements computed in %5d msecs with %d threadsn”,

even.size(), System.currentTimeMillis() - start,
Thread.activeCount());

}
5001983 elements computed in 828 msecs with 2 threads
5001983 elements computed in 843 msecs with 2 threads
5001983 elements computed in 675 msecs with 2 threads
5001983 elements computed in 795 msecs with 2 threads
@dgomezg
Going parallel
use stream()
for (int i = 0; i < 100; i++) {

long start = System.currentTimeMillis();

List<Integer> even = numbers.parallelStream()

.filter(n -> n % 2 == 0)

.sorted()

.collect(toList());


System.out.printf(
"%d elements computed in %5d msecs with %d threadsn”,

even.size(), System.currentTimeMillis() - start,
Thread.activeCount());

}
4999299 elements computed in 225 msecs with 9 threads
4999299 elements computed in 230 msecs with 9 threads
4999299 elements computed in 250 msecs with 9 threads
@dgomezg
Previously on…
http://www.slideshare.net/dgomezg/streams-en-java-8
Parallelism
Under the hood
Fork/Join Framework
Proposed by Doug Lea
"a style of parallel programming in
which problems are solved by
(recursively) splitting them into
subtasks that are solved in parallel."
Available in Java 7
Used by ParallelStreams
The F/J algorithm
Result solve(Problem problem)
{
if (problem is small)
directly solve problem
else
{
split problem into independent parts
fork new subtasks to solve each part
join all subtasks
compose result from subresults
}
}
as proposed by Doug Lea
ForkJoinPool
ExecutorService implementation that
• has a defined number of Workers (threads)
• executes ForkJoinTasks
• submitted by execute(ForkJoinTask  
task)  
• or by invoke(ForkJoinTask  task)
ForkJoinTask
Abstract class that represents a task to be run
concurrently
Every ForkJoinTask could be splitted (if not small
enough) and solved Recursively
Two concrete implementations
• RecursiveAction  if not returning value
• RecursiveTask  if returning a value
ForkJoinWorkerThread
Any of the threads created by the ForkJoinPool
Executes ForkJoinTasks
Everyone has a Dequeue for tasks (allows task
stealing)
ForkJoinWorkerThread
Result solve(Problem problem)
{
if (problem is small)
directly solve problem
else
{
split problem into independent parts
fork new subtasks to solve each part
join all subtasks
compose result from subresults
}
}
the F/J algorithm
plus Task Stealing.
Fork/Join. When to use?
For computations that could be splitted into smaller
tasks
aka ‘divide and conquer’ algorithms
Independent
Reduction with no contention.
ParallelStreams
in action!
ParallellStreams
for (int i = 0; i < 100; i++) {

long start = System.currentTimeMillis();

List<Integer> even = numbers.parallelStream()

.filter(n -> n % 2 == 0)

.sorted()

.collect(toList());


System.out.printf(
"%d elements computed in %5d msecs with %d threadsn”,

even.size(), System.currentTimeMillis() - start,
Thread.activeCount());

}
4999299 elements computed in 225 msecs with 9 threads
4999299 elements computed in 230 msecs with 9 threads
4999299 elements computed in 250 msecs with 9 threads
Thread.activeCount not accurate
for (int i = 0; i < 100; i++) {

long start = System.currentTimeMillis();

List<Integer> even = numbers.parallelStream()

.filter(n -> n % 2 == 0)

.sorted()

.collect(toList());


System.out.printf(
"%d elements computed in %5d msecs with %d threadsn”,

even.size(), System.currentTimeMillis() - start,
Thread.activeCount());

}
Thread.activeCount() does not show the effective
number of threads processing the stream
Better count threads involved
Set<String> workerThreadNames = new ConcurrentSet<>();

for (int i = 0; i < 100; i++) {

long start = System.currentTimeMillis();

List<Integer> even = numbers.stream()

.filter(n -> n % 2 == 0)

.peek(n -> workerThreadNames.add(
Thread.currentThread().getName()))

.sorted()

.collect(toList());



System.out.printf(
"%d elements computed in %5d msecs with %d threadsn”,

even.size(), System.currentTimeMillis() - start,
workerThreadNames.size());

}
Threads usage
ParallelStreams use the common ForkJoinPool
Number of worker threads configured with
-­‐Djava.util.concurrent.ForkJoinPool.common.parallelism=n
Useful to keep CPU parallelism under control…
…but …
Limiting parallelism
for (int i = 0; i < 100; i++) {

long start = System.currentTimeMillis();

List<Integer> even = numbers.stream()

.filter(n -> n % 2 == 0)

.peek(n -> workerThreadNames.add(
Thread.currentThread().getName()))

.sorted()

.collect(toList());



System.out.printf(
"%d elements computed in %5d msecs with %d threadsn”,

even.size(), System.currentTimeMillis() - start,
workerThreadNames.size());

}
-­‐Djava.util.concurrent.ForkJoinPool.common.parallelism=4
5001069 elements computed in 269 msecs with 5 threads
WTF
Limiting parallelism
for (int i = 0; i < 100; i++) {

long start = System.currentTimeMillis();

List<Integer> even = numbers.stream()

.filter(n -> n % 2 == 0)

.peek(n -> workerThreadNames.add(
Thread.currentThread().getName()))

.sorted()

.collect(toList());



System.out.printf(
"%d elements computed in %5d msecs with %d threadsn”,

even.size(), System.currentTimeMillis() - start,
workerThreadNames.size());

}
System.out.println("credits to threads: “
+ workerThreadNames);
5001069 elements computed in 269 msecs with 5 threads
credits to threads:
ForkJoinPool.commonPool-worker-0,
ForkJoinPool.commonPool-worker-1,
ForkJoinPool.commonPool-worker-2,
ForkJoinPool.commonPool-worker-3, main
WTF
Threads Involved in ParallelStream
ParallelStreams use the common ForkJoinPool
Thread invoking ParallelStream also used as
Worker
Caveats:
•ParallelStream processing is synchronous for
invoking thread
•Other Threads using common ForkJoinPool
could be affected
ParallelStream Hack
ParallelStream can be forced to use a custom
ForkJoinPool
ForkJoinPool forkJoinPool = new ForkJoinPool(4);



long start = System.currentTimeMillis();

numbers.parallelStream()

.filter(n -> n % 2 == 0)

.sorted()

.collect(toList());



ParallelStream Hack
ParallelStream can be forced to use a custom
ForkJoinPool
ForkJoinPool forkJoinPool = new ForkJoinPool(4);



long start = System.currentTimeMillis();

ForkJoinTask<List<Integer>> task =

forkJoinPool.submit(() -> {

return numbers.parallelStream()

.filter(n -> n % 2 == 0)

.sorted()

.collect(toList());

}

);
List<Integer> even = task.get();
ParallelStream Hack
ParallelStream can be forced to use a custom
ForkJoinPool
ForkJoinPool forkJoinPool = new ForkJoinPool(4);



ForkJoinTask<List<Integer>> task =

forkJoinPool.submit(() -> {

return numbers.parallelStream()

.filter(n -> n % 2 == 0)

.sorted()

.collect(toList());

}

);
List<Integer> even = task.get();
Task submitted in 1 msecs
5000805 elements computed in 328 msecs with 4 threads
ParallelStream Hack benefits
A custom ExecutorService
• Does not affect other ParallelStreams
• Does not affect Common ForkJoinPool users
• Reduces unpredictable latency due to other
CommonForkJoin Pool load
• Invoking thread not used as worker (async
parallel process)
Problems derived from
Common ForkJoinPool
Blocking for IO
If firsts URLs stuck on a ConnectionTimeOut, overall
performance could be affected
Stream<String> urls =
Files.lines(Paths.get("urlsToCheck.txt"));



List<String> errors = urls.parallel().filter(url -> {

//Connect to URL and wait for 200 response or timeout

return true;

}).collect(toList());

Nested parallelStreams
Outer parallelStream could exhaust ForkJoin
Workers:
long start = System.currentTimeMillis();

IntStream.range(0, 10_000).parallel()
.forEach(i -> {

results[i][0] = (int) Math.round(Math.random() * 100);



IntStream.range(1, 9_999)
.parallel().forEach((int j) ->
results[i][j] =
(int) Math.round(Math.random() * 1000));



});

Process finalized in 22974 msecs
Process finalized in 22575 msecs
Process finalized in 22606 msecs
Nested parallelStreams
Outer parallelStream could exhaust ForkJoin
Workers:
long start = System.currentTimeMillis();

IntStream.range(0, 10_000).parallel()
.forEach(i -> {

results[i][0] = (int) Math.round(Math.random() * 100);



IntStream.range(1, 9_999)
.sequential().forEach((int j) ->
results[i][j] =
(int) Math.round(Math.random() * 1000));



});

Process finalized in 12491 msecs
Process finalized in 12589 msecs
Process finalized in 12798 msecs
Other performance
problems
Too much Auto(un)boxing
outboxing and boxing of Integers in every filter call
List<Integer> even = numbers.parallelStream()

.filter(n -> n % 2 == 0)

.sorted()

.collect(toList());

4999464 elements computed in 290 msecs with 8 threads
4999464 elements computed in 276 msecs with 8 threads
4999464 elements computed in 257 msecs with 8 threads
4999464 elements computed in 265 msecs with 8 threads
Less Auto(un)boxing
outboxing and boxing of Integers in every filter call
List<Integer> even = numbers.parallelStream()

.mapToInt(n -> n)

.filter(n -> n % 2 == 0)

.sorted()

.boxed()

.collect(toList());
4999460 elements computed in 160 msecs with 8 threads
4999460 elements computed in 243 msecs with 8 threads
4999460 elements computed in 144 msecs with 8 threads
4999460 elements computed in 140 msecs with 8 threads
Conclusions
Conclusions
ParallelStreams eases concurrent processing but:
• Understand how it works
• Don’t abuse the default common ForkJoinPool
• Don’t use when blocking by IO
• Or use a custom ForkJoinPool
• Avoid unnecessary autoboxing
• Don’t add contention or synchronisation
• Be careful with nested parallel streams
• Use method references when sorting
Thank You.
@dgomezg
dgomezg@autentia.com

More Related Content

What's hot

Collections - Maps
Collections - Maps Collections - Maps
Collections - Maps
Hitesh-Java
 
Java exception
Java exception Java exception
Java exception
Arati Gadgil
 
C++ Memory Management
C++ Memory ManagementC++ Memory Management
C++ Memory Management
Anil Bapat
 
File handling in C++
File handling in C++File handling in C++
File handling in C++
Hitesh Kumar
 
Java(Polymorphism)
Java(Polymorphism)Java(Polymorphism)
Java(Polymorphism)
harsh kothari
 
Stack data structure
Stack data structureStack data structure
Stack data structureTech_MX
 
String and string buffer
String and string bufferString and string buffer
String and string bufferkamal kotecha
 
Java 8 Lambda Expressions
Java 8 Lambda ExpressionsJava 8 Lambda Expressions
Java 8 Lambda Expressions
Scott Leberknight
 
Object-oriented Programming-with C#
Object-oriented Programming-with C#Object-oriented Programming-with C#
Object-oriented Programming-with C#Doncho Minkov
 
Polymorphism in C++
Polymorphism in C++Polymorphism in C++
Polymorphism in C++
Rabin BK
 
Java constructors
Java constructorsJava constructors
Java constructors
QUONTRASOLUTIONS
 
String in java
String in javaString in java
Java Input Output and File Handling
Java Input Output and File HandlingJava Input Output and File Handling
Java Input Output and File Handling
Sunil OS
 
[OOP - Lec 19] Static Member Functions
[OOP - Lec 19] Static Member Functions[OOP - Lec 19] Static Member Functions
[OOP - Lec 19] Static Member Functions
Muhammad Hammad Waseem
 
Threading Made Easy! A Busy Developer’s Guide to Kotlin Coroutines
Threading Made Easy! A Busy Developer’s Guide to Kotlin CoroutinesThreading Made Easy! A Busy Developer’s Guide to Kotlin Coroutines
Threading Made Easy! A Busy Developer’s Guide to Kotlin Coroutines
Lauren Yew
 
Python
PythonPython
Optimizing Apache Spark SQL Joins
Optimizing Apache Spark SQL JoinsOptimizing Apache Spark SQL Joins
Optimizing Apache Spark SQL Joins
Databricks
 
L11 array list
L11 array listL11 array list
L11 array list
teach4uin
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in javaTech_MX
 
Python Collections Tutorial | Edureka
Python Collections Tutorial | EdurekaPython Collections Tutorial | Edureka
Python Collections Tutorial | Edureka
Edureka!
 

What's hot (20)

Collections - Maps
Collections - Maps Collections - Maps
Collections - Maps
 
Java exception
Java exception Java exception
Java exception
 
C++ Memory Management
C++ Memory ManagementC++ Memory Management
C++ Memory Management
 
File handling in C++
File handling in C++File handling in C++
File handling in C++
 
Java(Polymorphism)
Java(Polymorphism)Java(Polymorphism)
Java(Polymorphism)
 
Stack data structure
Stack data structureStack data structure
Stack data structure
 
String and string buffer
String and string bufferString and string buffer
String and string buffer
 
Java 8 Lambda Expressions
Java 8 Lambda ExpressionsJava 8 Lambda Expressions
Java 8 Lambda Expressions
 
Object-oriented Programming-with C#
Object-oriented Programming-with C#Object-oriented Programming-with C#
Object-oriented Programming-with C#
 
Polymorphism in C++
Polymorphism in C++Polymorphism in C++
Polymorphism in C++
 
Java constructors
Java constructorsJava constructors
Java constructors
 
String in java
String in javaString in java
String in java
 
Java Input Output and File Handling
Java Input Output and File HandlingJava Input Output and File Handling
Java Input Output and File Handling
 
[OOP - Lec 19] Static Member Functions
[OOP - Lec 19] Static Member Functions[OOP - Lec 19] Static Member Functions
[OOP - Lec 19] Static Member Functions
 
Threading Made Easy! A Busy Developer’s Guide to Kotlin Coroutines
Threading Made Easy! A Busy Developer’s Guide to Kotlin CoroutinesThreading Made Easy! A Busy Developer’s Guide to Kotlin Coroutines
Threading Made Easy! A Busy Developer’s Guide to Kotlin Coroutines
 
Python
PythonPython
Python
 
Optimizing Apache Spark SQL Joins
Optimizing Apache Spark SQL JoinsOptimizing Apache Spark SQL Joins
Optimizing Apache Spark SQL Joins
 
L11 array list
L11 array listL11 array list
L11 array list
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
 
Python Collections Tutorial | Edureka
Python Collections Tutorial | EdurekaPython Collections Tutorial | Edureka
Python Collections Tutorial | Edureka
 

Viewers also liked

Concurrency Utilities in Java 8
Concurrency Utilities in Java 8Concurrency Utilities in Java 8
Concurrency Utilities in Java 8Martin Toshev
 
Concurrency with java
Concurrency with javaConcurrency with java
Concurrency with java
James Wong
 
Java 7 - Fork/Join
Java 7 - Fork/JoinJava 7 - Fork/Join
Java 7 - Fork/Join
Zenika
 
Java concurrency - Thread pools
Java concurrency - Thread poolsJava concurrency - Thread pools
Java concurrency - Thread pools
maksym220889
 
Java Concurrency, Memory Model, and Trends
Java Concurrency, Memory Model, and TrendsJava Concurrency, Memory Model, and Trends
Java Concurrency, Memory Model, and Trends
Carol McDonald
 
Working With Concurrency In Java 8
Working With Concurrency In Java 8Working With Concurrency In Java 8
Working With Concurrency In Java 8
Heartin Jacob
 
Java 8 Streams
Java 8 StreamsJava 8 Streams
Java 8 Streams
Manvendra Singh
 
Java9 Beyond Modularity - Java 9 más allá de la modularidad
Java9 Beyond Modularity - Java 9 más allá de la modularidadJava9 Beyond Modularity - Java 9 más allá de la modularidad
Java9 Beyond Modularity - Java 9 más allá de la modularidad
David Gómez García
 
Java 9, JShell, and Modularity
Java 9, JShell, and ModularityJava 9, JShell, and Modularity
Java 9, JShell, and Modularity
Mohammad Hossein Rimaz
 
Lambda Expressions in Java 8
Lambda Expressions in Java 8Lambda Expressions in Java 8
Lambda Expressions in Java 8
icarter09
 
Java 8 Stream API. A different way to process collections.
Java 8 Stream API. A different way to process collections.Java 8 Stream API. A different way to process collections.
Java 8 Stream API. A different way to process collections.
David Gómez García
 
Java SE 9 modules (JPMS) - an introduction
Java SE 9 modules (JPMS) - an introductionJava SE 9 modules (JPMS) - an introduction
Java SE 9 modules (JPMS) - an introduction
Stephen Colebourne
 
Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose
Java 9 Modules: The Duke Yet Lives That OSGi Shall DeposeJava 9 Modules: The Duke Yet Lives That OSGi Shall Depose
Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose
Nikita Lipsky
 
Lambda Expressions in Java
Lambda Expressions in JavaLambda Expressions in Java
Lambda Expressions in Java
Erhan Bagdemir
 
Java 8 Lambda Expressions & Streams
Java 8 Lambda Expressions & StreamsJava 8 Lambda Expressions & Streams
Java 8 Lambda Expressions & Streams
NewCircle Training
 
The do's and don'ts with java 9 (Devoxx 2017)
The do's and don'ts with java 9 (Devoxx 2017)The do's and don'ts with java 9 (Devoxx 2017)
The do's and don'ts with java 9 (Devoxx 2017)
Robert Scholte
 
Real World Java 9
Real World Java 9Real World Java 9
Real World Java 9
Trisha Gee
 

Viewers also liked (17)

Concurrency Utilities in Java 8
Concurrency Utilities in Java 8Concurrency Utilities in Java 8
Concurrency Utilities in Java 8
 
Concurrency with java
Concurrency with javaConcurrency with java
Concurrency with java
 
Java 7 - Fork/Join
Java 7 - Fork/JoinJava 7 - Fork/Join
Java 7 - Fork/Join
 
Java concurrency - Thread pools
Java concurrency - Thread poolsJava concurrency - Thread pools
Java concurrency - Thread pools
 
Java Concurrency, Memory Model, and Trends
Java Concurrency, Memory Model, and TrendsJava Concurrency, Memory Model, and Trends
Java Concurrency, Memory Model, and Trends
 
Working With Concurrency In Java 8
Working With Concurrency In Java 8Working With Concurrency In Java 8
Working With Concurrency In Java 8
 
Java 8 Streams
Java 8 StreamsJava 8 Streams
Java 8 Streams
 
Java9 Beyond Modularity - Java 9 más allá de la modularidad
Java9 Beyond Modularity - Java 9 más allá de la modularidadJava9 Beyond Modularity - Java 9 más allá de la modularidad
Java9 Beyond Modularity - Java 9 más allá de la modularidad
 
Java 9, JShell, and Modularity
Java 9, JShell, and ModularityJava 9, JShell, and Modularity
Java 9, JShell, and Modularity
 
Lambda Expressions in Java 8
Lambda Expressions in Java 8Lambda Expressions in Java 8
Lambda Expressions in Java 8
 
Java 8 Stream API. A different way to process collections.
Java 8 Stream API. A different way to process collections.Java 8 Stream API. A different way to process collections.
Java 8 Stream API. A different way to process collections.
 
Java SE 9 modules (JPMS) - an introduction
Java SE 9 modules (JPMS) - an introductionJava SE 9 modules (JPMS) - an introduction
Java SE 9 modules (JPMS) - an introduction
 
Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose
Java 9 Modules: The Duke Yet Lives That OSGi Shall DeposeJava 9 Modules: The Duke Yet Lives That OSGi Shall Depose
Java 9 Modules: The Duke Yet Lives That OSGi Shall Depose
 
Lambda Expressions in Java
Lambda Expressions in JavaLambda Expressions in Java
Lambda Expressions in Java
 
Java 8 Lambda Expressions & Streams
Java 8 Lambda Expressions & StreamsJava 8 Lambda Expressions & Streams
Java 8 Lambda Expressions & Streams
 
The do's and don'ts with java 9 (Devoxx 2017)
The do's and don'ts with java 9 (Devoxx 2017)The do's and don'ts with java 9 (Devoxx 2017)
The do's and don'ts with java 9 (Devoxx 2017)
 
Real World Java 9
Real World Java 9Real World Java 9
Real World Java 9
 

Similar to Parallel streams in java 8

اسلاید ارائه اول جلسه ۱۰ کلاس پایتون برای هکر های قانونی
اسلاید ارائه اول جلسه ۱۰ کلاس پایتون برای هکر های قانونی اسلاید ارائه اول جلسه ۱۰ کلاس پایتون برای هکر های قانونی
اسلاید ارائه اول جلسه ۱۰ کلاس پایتون برای هکر های قانونی
Mohammad Reza Kamalifard
 
Effective Modern C++ - Item 35 & 36
Effective Modern C++ - Item 35 & 36Effective Modern C++ - Item 35 & 36
Effective Modern C++ - Item 35 & 36
Chih-Hsuan Kuo
 
Java programming lab manual
Java programming lab manualJava programming lab manual
Java programming lab manual
sameer farooq
 
CBStreams - Java Streams for ColdFusion (CFML)
CBStreams - Java Streams for ColdFusion (CFML)CBStreams - Java Streams for ColdFusion (CFML)
CBStreams - Java Streams for ColdFusion (CFML)
Ortus Solutions, Corp
 
ITB2019 CBStreams : Accelerate your Functional Programming with the power of ...
ITB2019 CBStreams : Accelerate your Functional Programming with the power of ...ITB2019 CBStreams : Accelerate your Functional Programming with the power of ...
ITB2019 CBStreams : Accelerate your Functional Programming with the power of ...
Ortus Solutions, Corp
 
The Ring programming language version 1.5 book - Part 8 of 31
The Ring programming language version 1.5 book - Part 8 of 31The Ring programming language version 1.5 book - Part 8 of 31
The Ring programming language version 1.5 book - Part 8 of 31
Mahmoud Samir Fayed
 
Python testing using mock and pytest
Python testing using mock and pytestPython testing using mock and pytest
Python testing using mock and pytest
Suraj Deshmukh
 
Boredom comes to_those_who_wait
Boredom comes to_those_who_waitBoredom comes to_those_who_wait
Boredom comes to_those_who_wait
Ricardo Bánffy
 
Celery with python
Celery with pythonCelery with python
Celery with python
Alexandre González Rodríguez
 
Josh Patterson MLconf slides
Josh Patterson MLconf slidesJosh Patterson MLconf slides
Josh Patterson MLconf slides
MLconf
 
Pick up the low-hanging concurrency fruit
Pick up the low-hanging concurrency fruitPick up the low-hanging concurrency fruit
Pick up the low-hanging concurrency fruit
Vaclav Pech
 
The Ring programming language version 1.7 book - Part 48 of 196
The Ring programming language version 1.7 book - Part 48 of 196The Ring programming language version 1.7 book - Part 48 of 196
The Ring programming language version 1.7 book - Part 48 of 196
Mahmoud Samir Fayed
 
Threads, Queues, and More: Async Programming in iOS
Threads, Queues, and More: Async Programming in iOSThreads, Queues, and More: Async Programming in iOS
Threads, Queues, and More: Async Programming in iOS
TechWell
 
Performance
PerformancePerformance
Performance
Cary Millsap
 
query-optimization-techniques_talk.pdf
query-optimization-techniques_talk.pdfquery-optimization-techniques_talk.pdf
query-optimization-techniques_talk.pdf
garos1
 
JVM Mechanics
JVM MechanicsJVM Mechanics
JVM Mechanics
Doug Hawkins
 
Profiling ruby
Profiling rubyProfiling ruby
Profiling rubynasirj
 
LvivPy4 - Threading vs asyncio
LvivPy4 - Threading vs asyncioLvivPy4 - Threading vs asyncio
LvivPy4 - Threading vs asyncio
Roman Rader
 
CONFidence 2015: DTrace + OSX = Fun - Andrzej Dyjak
CONFidence 2015: DTrace + OSX = Fun - Andrzej Dyjak   CONFidence 2015: DTrace + OSX = Fun - Andrzej Dyjak
CONFidence 2015: DTrace + OSX = Fun - Andrzej Dyjak
PROIDEA
 

Similar to Parallel streams in java 8 (20)

اسلاید ارائه اول جلسه ۱۰ کلاس پایتون برای هکر های قانونی
اسلاید ارائه اول جلسه ۱۰ کلاس پایتون برای هکر های قانونی اسلاید ارائه اول جلسه ۱۰ کلاس پایتون برای هکر های قانونی
اسلاید ارائه اول جلسه ۱۰ کلاس پایتون برای هکر های قانونی
 
Effective Modern C++ - Item 35 & 36
Effective Modern C++ - Item 35 & 36Effective Modern C++ - Item 35 & 36
Effective Modern C++ - Item 35 & 36
 
Java programming lab manual
Java programming lab manualJava programming lab manual
Java programming lab manual
 
CBStreams - Java Streams for ColdFusion (CFML)
CBStreams - Java Streams for ColdFusion (CFML)CBStreams - Java Streams for ColdFusion (CFML)
CBStreams - Java Streams for ColdFusion (CFML)
 
ITB2019 CBStreams : Accelerate your Functional Programming with the power of ...
ITB2019 CBStreams : Accelerate your Functional Programming with the power of ...ITB2019 CBStreams : Accelerate your Functional Programming with the power of ...
ITB2019 CBStreams : Accelerate your Functional Programming with the power of ...
 
The Ring programming language version 1.5 book - Part 8 of 31
The Ring programming language version 1.5 book - Part 8 of 31The Ring programming language version 1.5 book - Part 8 of 31
The Ring programming language version 1.5 book - Part 8 of 31
 
Python testing using mock and pytest
Python testing using mock and pytestPython testing using mock and pytest
Python testing using mock and pytest
 
Boredom comes to_those_who_wait
Boredom comes to_those_who_waitBoredom comes to_those_who_wait
Boredom comes to_those_who_wait
 
Celery with python
Celery with pythonCelery with python
Celery with python
 
Josh Patterson MLconf slides
Josh Patterson MLconf slidesJosh Patterson MLconf slides
Josh Patterson MLconf slides
 
Pick up the low-hanging concurrency fruit
Pick up the low-hanging concurrency fruitPick up the low-hanging concurrency fruit
Pick up the low-hanging concurrency fruit
 
The Ring programming language version 1.7 book - Part 48 of 196
The Ring programming language version 1.7 book - Part 48 of 196The Ring programming language version 1.7 book - Part 48 of 196
The Ring programming language version 1.7 book - Part 48 of 196
 
Threads, Queues, and More: Async Programming in iOS
Threads, Queues, and More: Async Programming in iOSThreads, Queues, and More: Async Programming in iOS
Threads, Queues, and More: Async Programming in iOS
 
Performance
PerformancePerformance
Performance
 
query-optimization-techniques_talk.pdf
query-optimization-techniques_talk.pdfquery-optimization-techniques_talk.pdf
query-optimization-techniques_talk.pdf
 
JVM Mechanics
JVM MechanicsJVM Mechanics
JVM Mechanics
 
Profiling ruby
Profiling rubyProfiling ruby
Profiling ruby
 
LvivPy4 - Threading vs asyncio
LvivPy4 - Threading vs asyncioLvivPy4 - Threading vs asyncio
LvivPy4 - Threading vs asyncio
 
CONFidence 2015: DTrace + OSX = Fun - Andrzej Dyjak
CONFidence 2015: DTrace + OSX = Fun - Andrzej Dyjak   CONFidence 2015: DTrace + OSX = Fun - Andrzej Dyjak
CONFidence 2015: DTrace + OSX = Fun - Andrzej Dyjak
 
Process scheduling linux
Process scheduling linuxProcess scheduling linux
Process scheduling linux
 

More from David Gómez García

Leverage CompletableFutures to handle async queries. DevNexus 2022
Leverage CompletableFutures to handle async queries. DevNexus 2022Leverage CompletableFutures to handle async queries. DevNexus 2022
Leverage CompletableFutures to handle async queries. DevNexus 2022
David Gómez García
 
Building Modular monliths that could scale to microservices (only if they nee...
Building Modular monliths that could scale to microservices (only if they nee...Building Modular monliths that could scale to microservices (only if they nee...
Building Modular monliths that could scale to microservices (only if they nee...
David Gómez García
 
Building modular monoliths that could scale to microservices (only if they ne...
Building modular monoliths that could scale to microservices (only if they ne...Building modular monoliths that could scale to microservices (only if they ne...
Building modular monoliths that could scale to microservices (only if they ne...
David Gómez García
 
Leveraging Completable Futures to handle your query results Asynchrhonously
Leveraging Completable Futures to handle your query results AsynchrhonouslyLeveraging Completable Futures to handle your query results Asynchrhonously
Leveraging Completable Futures to handle your query results Asynchrhonously
David Gómez García
 
Builiding Modular monoliths that can scale to microservices. JBCNConf 2021
Builiding Modular monoliths that can scale to microservices. JBCNConf 2021Builiding Modular monoliths that can scale to microservices. JBCNConf 2021
Builiding Modular monoliths that can scale to microservices. JBCNConf 2021
David Gómez García
 
Cdm mil-18 - hypermedia ap is for headless platforms and data integration
Cdm mil-18 - hypermedia ap is for headless platforms and data integrationCdm mil-18 - hypermedia ap is for headless platforms and data integration
Cdm mil-18 - hypermedia ap is for headless platforms and data integration
David Gómez García
 
What's in a community like Liferay's
What's in a community like Liferay'sWhat's in a community like Liferay's
What's in a community like Liferay's
David Gómez García
 
T3chFest2016 - Uso del API JavaScript de Photoshop para obtener fotos HDTR
T3chFest2016 - Uso del API JavaScript de Photoshop para obtener fotos HDTRT3chFest2016 - Uso del API JavaScript de Photoshop para obtener fotos HDTR
T3chFest2016 - Uso del API JavaScript de Photoshop para obtener fotos HDTR
David Gómez García
 
Managing user's data with Spring Session
Managing user's data with Spring SessionManaging user's data with Spring Session
Managing user's data with Spring Session
David Gómez García
 
Construccion de proyectos con gradle
Construccion de proyectos con gradleConstruccion de proyectos con gradle
Construccion de proyectos con gradle
David Gómez García
 
Midiendo la calidad de código en WTF/Min (Revisado EUI Abril 2014)
Midiendo la calidad de código en WTF/Min (Revisado EUI Abril 2014)Midiendo la calidad de código en WTF/Min (Revisado EUI Abril 2014)
Midiendo la calidad de código en WTF/Min (Revisado EUI Abril 2014)David Gómez García
 
Measuring Code Quality in WTF/min.
Measuring Code Quality in WTF/min. Measuring Code Quality in WTF/min.
Measuring Code Quality in WTF/min.
David Gómez García
 
Spring4 whats up doc?
Spring4 whats up doc?Spring4 whats up doc?
Spring4 whats up doc?
David Gómez García
 
El poder del creador de Software. Entre la ingeniería y la artesanía
El poder del creador de Software. Entre la ingeniería y la artesaníaEl poder del creador de Software. Entre la ingeniería y la artesanía
El poder del creador de Software. Entre la ingeniería y la artesanía
David Gómez García
 
Geo-SentimentZ
Geo-SentimentZGeo-SentimentZ
Geo-SentimentZ
David Gómez García
 
HDTR images with Photoshop Javascript Scripting
HDTR images with Photoshop Javascript ScriptingHDTR images with Photoshop Javascript Scripting
HDTR images with Photoshop Javascript Scripting
David Gómez García
 
A real systemwithjms-rest-protobuf-mongodb
A real systemwithjms-rest-protobuf-mongodbA real systemwithjms-rest-protobuf-mongodb
A real systemwithjms-rest-protobuf-mongodb
David Gómez García
 
Spring Data y Mongo DB en un proyecto Real
Spring Data y Mongo DB en un proyecto RealSpring Data y Mongo DB en un proyecto Real
Spring Data y Mongo DB en un proyecto Real
David Gómez García
 

More from David Gómez García (20)

Leverage CompletableFutures to handle async queries. DevNexus 2022
Leverage CompletableFutures to handle async queries. DevNexus 2022Leverage CompletableFutures to handle async queries. DevNexus 2022
Leverage CompletableFutures to handle async queries. DevNexus 2022
 
Building Modular monliths that could scale to microservices (only if they nee...
Building Modular monliths that could scale to microservices (only if they nee...Building Modular monliths that could scale to microservices (only if they nee...
Building Modular monliths that could scale to microservices (only if they nee...
 
Building modular monoliths that could scale to microservices (only if they ne...
Building modular monoliths that could scale to microservices (only if they ne...Building modular monoliths that could scale to microservices (only if they ne...
Building modular monoliths that could scale to microservices (only if they ne...
 
Leveraging Completable Futures to handle your query results Asynchrhonously
Leveraging Completable Futures to handle your query results AsynchrhonouslyLeveraging Completable Futures to handle your query results Asynchrhonously
Leveraging Completable Futures to handle your query results Asynchrhonously
 
Builiding Modular monoliths that can scale to microservices. JBCNConf 2021
Builiding Modular monoliths that can scale to microservices. JBCNConf 2021Builiding Modular monoliths that can scale to microservices. JBCNConf 2021
Builiding Modular monoliths that can scale to microservices. JBCNConf 2021
 
Cdm mil-18 - hypermedia ap is for headless platforms and data integration
Cdm mil-18 - hypermedia ap is for headless platforms and data integrationCdm mil-18 - hypermedia ap is for headless platforms and data integration
Cdm mil-18 - hypermedia ap is for headless platforms and data integration
 
What's in a community like Liferay's
What's in a community like Liferay'sWhat's in a community like Liferay's
What's in a community like Liferay's
 
T3chFest2016 - Uso del API JavaScript de Photoshop para obtener fotos HDTR
T3chFest2016 - Uso del API JavaScript de Photoshop para obtener fotos HDTRT3chFest2016 - Uso del API JavaScript de Photoshop para obtener fotos HDTR
T3chFest2016 - Uso del API JavaScript de Photoshop para obtener fotos HDTR
 
Managing user's data with Spring Session
Managing user's data with Spring SessionManaging user's data with Spring Session
Managing user's data with Spring Session
 
Construccion de proyectos con gradle
Construccion de proyectos con gradleConstruccion de proyectos con gradle
Construccion de proyectos con gradle
 
Midiendo la calidad de código en WTF/Min (Revisado EUI Abril 2014)
Midiendo la calidad de código en WTF/Min (Revisado EUI Abril 2014)Midiendo la calidad de código en WTF/Min (Revisado EUI Abril 2014)
Midiendo la calidad de código en WTF/Min (Revisado EUI Abril 2014)
 
Measuring Code Quality in WTF/min.
Measuring Code Quality in WTF/min. Measuring Code Quality in WTF/min.
Measuring Code Quality in WTF/min.
 
Spring4 whats up doc?
Spring4 whats up doc?Spring4 whats up doc?
Spring4 whats up doc?
 
Gradle como alternativa a maven
Gradle como alternativa a mavenGradle como alternativa a maven
Gradle como alternativa a maven
 
El poder del creador de Software. Entre la ingeniería y la artesanía
El poder del creador de Software. Entre la ingeniería y la artesaníaEl poder del creador de Software. Entre la ingeniería y la artesanía
El poder del creador de Software. Entre la ingeniería y la artesanía
 
Geo-SentimentZ
Geo-SentimentZGeo-SentimentZ
Geo-SentimentZ
 
HDTR images with Photoshop Javascript Scripting
HDTR images with Photoshop Javascript ScriptingHDTR images with Photoshop Javascript Scripting
HDTR images with Photoshop Javascript Scripting
 
Wtf per lineofcode
Wtf per lineofcodeWtf per lineofcode
Wtf per lineofcode
 
A real systemwithjms-rest-protobuf-mongodb
A real systemwithjms-rest-protobuf-mongodbA real systemwithjms-rest-protobuf-mongodb
A real systemwithjms-rest-protobuf-mongodb
 
Spring Data y Mongo DB en un proyecto Real
Spring Data y Mongo DB en un proyecto RealSpring Data y Mongo DB en un proyecto Real
Spring Data y Mongo DB en un proyecto Real
 

Recently uploaded

DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
KatiaHIMEUR1
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Inflectra
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
Dorra BARTAGUIZ
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Product School
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
Cheryl Hung
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
Thijs Feryn
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
Product School
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Tobias Schneck
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
Product School
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Albert Hoitingh
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Thierry Lestable
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
Alison B. Lowndes
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Sri Ambati
 

Recently uploaded (20)

DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 

Parallel streams in java 8

  • 1. ParallelStreams Concurrent data processing in Java 8 David Gómez G. @dgomezg dgomezg@autentia.com
  • 2. Do you remember? use stream() for (int i = 0; i < 100; i++) {
 long start = System.currentTimeMillis();
 List<Integer> even = numbers.parallelStream()
 .filter(n -> n % 2 == 0)
 .sorted()
 .collect(toList()); 
 System.out.printf( "%d elements computed in %5d msecs with %d threadsn”,
 even.size(), System.currentTimeMillis() - start, Thread.activeCount());
 } 4999299 elements computed in 225 msecs with 9 threads 4999299 elements computed in 230 msecs with 9 threads 4999299 elements computed in 250 msecs with 9 threads @dgomezg
  • 5. A Stream is… An convenience method to iterate over collections in a declarative way List<Integer>  numbers  =  new  ArrayList<Integer>();
 for  (int  i=  0;  i  <  100  ;  i++)  {
   numbers.add(i);
 }   List<Integer> evenNumbers = numbers.stream()
 .filter(n -> n % 2 == 0)
 .collect(toList()); @dgomezg
  • 6. Anatomy of a Stream Source Intermediate Operations filter map order function Final operation pipeline @dgomezg
  • 7. Iterating a Stream List<Integer> evenNumbers = numbers.stream()
 .filter(n -> n % 2 == 0)
 .collect(toList()); Internal Iteration - No manual Iterators handling - Concise - Fluent API: chain sequence processing Elements computed only when needed @dgomezg
  • 8. Iterating a Stream List<Integer> evenNumbers = numbers.parallelStream()
 .filter(n -> n % 2 == 0)
 .collect(toList()); Easily Parallelism - Concurrency is hard to be done right! - Uses ForkJoin - Process steps should be - stateless - independent @dgomezg
  • 9. Parallel Streams use stream() List<Integer> numbers = new ArrayList<>();
 for (int i= 0; i < 10_000_000 ; i++) {
 numbers.add((int)Math.round(Math.random()*100));
 } //This will use just a single thread Stream<Integer> evenNumbers = numbers.stream(); or parallelStream() //Automatically select the optimum number of threads Stream<Integer> evenNumbers = numbers.parallelStream(); @dgomezg
  • 10. Let’s test it use stream() for (int i = 0; i < 100; i++) {
 long start = System.currentTimeMillis();
 List<Integer> even = numbers.stream()
 .filter(n -> n % 2 == 0)
 .sorted()
 .collect(toList()); 
 System.out.printf( "%d elements computed in %5d msecs with %d threadsn”,
 even.size(), System.currentTimeMillis() - start, Thread.activeCount());
 } 5001983 elements computed in 828 msecs with 2 threads 5001983 elements computed in 843 msecs with 2 threads 5001983 elements computed in 675 msecs with 2 threads 5001983 elements computed in 795 msecs with 2 threads @dgomezg
  • 11. Going parallel use stream() for (int i = 0; i < 100; i++) {
 long start = System.currentTimeMillis();
 List<Integer> even = numbers.parallelStream()
 .filter(n -> n % 2 == 0)
 .sorted()
 .collect(toList()); 
 System.out.printf( "%d elements computed in %5d msecs with %d threadsn”,
 even.size(), System.currentTimeMillis() - start, Thread.activeCount());
 } 4999299 elements computed in 225 msecs with 9 threads 4999299 elements computed in 230 msecs with 9 threads 4999299 elements computed in 250 msecs with 9 threads @dgomezg
  • 14. Fork/Join Framework Proposed by Doug Lea "a style of parallel programming in which problems are solved by (recursively) splitting them into subtasks that are solved in parallel." Available in Java 7 Used by ParallelStreams
  • 15. The F/J algorithm Result solve(Problem problem) { if (problem is small) directly solve problem else { split problem into independent parts fork new subtasks to solve each part join all subtasks compose result from subresults } } as proposed by Doug Lea
  • 16. ForkJoinPool ExecutorService implementation that • has a defined number of Workers (threads) • executes ForkJoinTasks • submitted by execute(ForkJoinTask   task)   • or by invoke(ForkJoinTask  task)
  • 17. ForkJoinTask Abstract class that represents a task to be run concurrently Every ForkJoinTask could be splitted (if not small enough) and solved Recursively Two concrete implementations • RecursiveAction  if not returning value • RecursiveTask  if returning a value
  • 18. ForkJoinWorkerThread Any of the threads created by the ForkJoinPool Executes ForkJoinTasks Everyone has a Dequeue for tasks (allows task stealing)
  • 19. ForkJoinWorkerThread Result solve(Problem problem) { if (problem is small) directly solve problem else { split problem into independent parts fork new subtasks to solve each part join all subtasks compose result from subresults } } the F/J algorithm plus Task Stealing.
  • 20. Fork/Join. When to use? For computations that could be splitted into smaller tasks aka ‘divide and conquer’ algorithms Independent Reduction with no contention.
  • 22. ParallellStreams for (int i = 0; i < 100; i++) {
 long start = System.currentTimeMillis();
 List<Integer> even = numbers.parallelStream()
 .filter(n -> n % 2 == 0)
 .sorted()
 .collect(toList()); 
 System.out.printf( "%d elements computed in %5d msecs with %d threadsn”,
 even.size(), System.currentTimeMillis() - start, Thread.activeCount());
 } 4999299 elements computed in 225 msecs with 9 threads 4999299 elements computed in 230 msecs with 9 threads 4999299 elements computed in 250 msecs with 9 threads
  • 23. Thread.activeCount not accurate for (int i = 0; i < 100; i++) {
 long start = System.currentTimeMillis();
 List<Integer> even = numbers.parallelStream()
 .filter(n -> n % 2 == 0)
 .sorted()
 .collect(toList()); 
 System.out.printf( "%d elements computed in %5d msecs with %d threadsn”,
 even.size(), System.currentTimeMillis() - start, Thread.activeCount());
 } Thread.activeCount() does not show the effective number of threads processing the stream
  • 24. Better count threads involved Set<String> workerThreadNames = new ConcurrentSet<>();
 for (int i = 0; i < 100; i++) {
 long start = System.currentTimeMillis();
 List<Integer> even = numbers.stream()
 .filter(n -> n % 2 == 0)
 .peek(n -> workerThreadNames.add( Thread.currentThread().getName()))
 .sorted()
 .collect(toList());
 
 System.out.printf( "%d elements computed in %5d msecs with %d threadsn”,
 even.size(), System.currentTimeMillis() - start, workerThreadNames.size());
 }
  • 25. Threads usage ParallelStreams use the common ForkJoinPool Number of worker threads configured with -­‐Djava.util.concurrent.ForkJoinPool.common.parallelism=n Useful to keep CPU parallelism under control… …but …
  • 26. Limiting parallelism for (int i = 0; i < 100; i++) {
 long start = System.currentTimeMillis();
 List<Integer> even = numbers.stream()
 .filter(n -> n % 2 == 0)
 .peek(n -> workerThreadNames.add( Thread.currentThread().getName()))
 .sorted()
 .collect(toList());
 
 System.out.printf( "%d elements computed in %5d msecs with %d threadsn”,
 even.size(), System.currentTimeMillis() - start, workerThreadNames.size());
 } -­‐Djava.util.concurrent.ForkJoinPool.common.parallelism=4 5001069 elements computed in 269 msecs with 5 threads WTF
  • 27. Limiting parallelism for (int i = 0; i < 100; i++) {
 long start = System.currentTimeMillis();
 List<Integer> even = numbers.stream()
 .filter(n -> n % 2 == 0)
 .peek(n -> workerThreadNames.add( Thread.currentThread().getName()))
 .sorted()
 .collect(toList());
 
 System.out.printf( "%d elements computed in %5d msecs with %d threadsn”,
 even.size(), System.currentTimeMillis() - start, workerThreadNames.size());
 } System.out.println("credits to threads: “ + workerThreadNames); 5001069 elements computed in 269 msecs with 5 threads credits to threads: ForkJoinPool.commonPool-worker-0, ForkJoinPool.commonPool-worker-1, ForkJoinPool.commonPool-worker-2, ForkJoinPool.commonPool-worker-3, main WTF
  • 28. Threads Involved in ParallelStream ParallelStreams use the common ForkJoinPool Thread invoking ParallelStream also used as Worker Caveats: •ParallelStream processing is synchronous for invoking thread •Other Threads using common ForkJoinPool could be affected
  • 29. ParallelStream Hack ParallelStream can be forced to use a custom ForkJoinPool ForkJoinPool forkJoinPool = new ForkJoinPool(4);
 
 long start = System.currentTimeMillis();
 numbers.parallelStream()
 .filter(n -> n % 2 == 0)
 .sorted()
 .collect(toList());
 

  • 30. ParallelStream Hack ParallelStream can be forced to use a custom ForkJoinPool ForkJoinPool forkJoinPool = new ForkJoinPool(4);
 
 long start = System.currentTimeMillis();
 ForkJoinTask<List<Integer>> task =
 forkJoinPool.submit(() -> {
 return numbers.parallelStream()
 .filter(n -> n % 2 == 0)
 .sorted()
 .collect(toList());
 }
 ); List<Integer> even = task.get();
  • 31. ParallelStream Hack ParallelStream can be forced to use a custom ForkJoinPool ForkJoinPool forkJoinPool = new ForkJoinPool(4);
 
 ForkJoinTask<List<Integer>> task =
 forkJoinPool.submit(() -> {
 return numbers.parallelStream()
 .filter(n -> n % 2 == 0)
 .sorted()
 .collect(toList());
 }
 ); List<Integer> even = task.get(); Task submitted in 1 msecs 5000805 elements computed in 328 msecs with 4 threads
  • 32. ParallelStream Hack benefits A custom ExecutorService • Does not affect other ParallelStreams • Does not affect Common ForkJoinPool users • Reduces unpredictable latency due to other CommonForkJoin Pool load • Invoking thread not used as worker (async parallel process)
  • 34. Blocking for IO If firsts URLs stuck on a ConnectionTimeOut, overall performance could be affected Stream<String> urls = Files.lines(Paths.get("urlsToCheck.txt"));
 
 List<String> errors = urls.parallel().filter(url -> {
 //Connect to URL and wait for 200 response or timeout
 return true;
 }).collect(toList());

  • 35. Nested parallelStreams Outer parallelStream could exhaust ForkJoin Workers: long start = System.currentTimeMillis();
 IntStream.range(0, 10_000).parallel() .forEach(i -> {
 results[i][0] = (int) Math.round(Math.random() * 100);
 
 IntStream.range(1, 9_999) .parallel().forEach((int j) -> results[i][j] = (int) Math.round(Math.random() * 1000));
 
 });
 Process finalized in 22974 msecs Process finalized in 22575 msecs Process finalized in 22606 msecs
  • 36. Nested parallelStreams Outer parallelStream could exhaust ForkJoin Workers: long start = System.currentTimeMillis();
 IntStream.range(0, 10_000).parallel() .forEach(i -> {
 results[i][0] = (int) Math.round(Math.random() * 100);
 
 IntStream.range(1, 9_999) .sequential().forEach((int j) -> results[i][j] = (int) Math.round(Math.random() * 1000));
 
 });
 Process finalized in 12491 msecs Process finalized in 12589 msecs Process finalized in 12798 msecs
  • 38. Too much Auto(un)boxing outboxing and boxing of Integers in every filter call List<Integer> even = numbers.parallelStream()
 .filter(n -> n % 2 == 0)
 .sorted()
 .collect(toList());
 4999464 elements computed in 290 msecs with 8 threads 4999464 elements computed in 276 msecs with 8 threads 4999464 elements computed in 257 msecs with 8 threads 4999464 elements computed in 265 msecs with 8 threads
  • 39. Less Auto(un)boxing outboxing and boxing of Integers in every filter call List<Integer> even = numbers.parallelStream()
 .mapToInt(n -> n)
 .filter(n -> n % 2 == 0)
 .sorted()
 .boxed()
 .collect(toList()); 4999460 elements computed in 160 msecs with 8 threads 4999460 elements computed in 243 msecs with 8 threads 4999460 elements computed in 144 msecs with 8 threads 4999460 elements computed in 140 msecs with 8 threads
  • 41. Conclusions ParallelStreams eases concurrent processing but: • Understand how it works • Don’t abuse the default common ForkJoinPool • Don’t use when blocking by IO • Or use a custom ForkJoinPool • Avoid unnecessary autoboxing • Don’t add contention or synchronisation • Be careful with nested parallel streams • Use method references when sorting