SlideShare une entreprise Scribd logo
1  sur  144
Télécharger pour lire hors ligne
Good and Wicked Fairies
The Tragedy of the Commons
Understanding the Performance
of Java 8 Streams
Kirk Pepperdine @kcpeppe
MauriceNaftalin @mauricenaftalin
#java8fairies
About Kirk
• Specialises in performance tuning
• speaks frequently about performance
• author of performance tuning workshop
• Co-founder jClarity
• performance diagnositic tooling
• Java Champion (since 2006)
About Kirk
• Specialises in performance tuning
• speaks frequently about performance
• author of performance tuning workshop
• Co-founder jClarity
• performance diagnositic tooling
• Java Champion (since 2006)
Kirk’s quiz: what is this?
About Maurice
Developer, designer, architect, teacher, learner, writer
About Maurice
Co-author
Developer, designer, architect, teacher, learner, writer
About Maurice
Co-author Author
Developer, designer, architect, teacher, learner, writer
About Maurice
Co-author Author
Developer, designer, architect, teacher, learner, writer
@mauricenaftalin
The Lambda FAQ
www.lambdafaq.org
Varian 620/i
6
First Computer I Used
Agenda
#java8fairies
Agenda
• Define the problem
#java8fairies
Agenda
• Define the problem
• Implement a solution
#java8fairies
Agenda
• Define the problem
• Implement a solution
• Analyse performance
#java8fairies
Agenda
• Define the problem
• Implement a solution
• Analyse performance
– find the bottleneck
#java8fairies
Agenda
• Define the problem
• Implement a solution
• Analyse performance
– find the bottleneck
#java8fairies
Agenda
• Define the problem
• Implement a solution
• Analyse performance
– find the bottleneck
• Fork/Join parallelism in the real world
#java8fairies
Agenda
• Define the problem
• Implement a solution
• Analyse performance
– find the bottleneck
• Fork/Join parallelism in the real world
#java8fairies
Agenda
• Define the problem
• Implement a solution
• Analyse performance
– find the bottleneck
• Fork/Join parallelism in the real world
#java8fairies
Case Study: grep -b
grep -b:
“The offset in bytes of a matched pattern
is displayed in front of the matched line.”
Case Study: grep -b
The Moving Finger writes; and, having writ,
Moves on: nor all thy Piety nor Wit
Shall bring it back to cancel half a Line
Nor all thy Tears wash out a Word of it.
rubai51.txt
grep -b:
“The offset in bytes of a matched pattern
is displayed in front of the matched line.”
Case Study: grep -b
The Moving Finger writes; and, having writ,
Moves on: nor all thy Piety nor Wit
Shall bring it back to cancel half a Line
Nor all thy Tears wash out a Word of it.
rubai51.txt
grep -b:
“The offset in bytes of a matched pattern
is displayed in front of the matched line.”
$ grep -b 'W.*t' rubai51.txt
44:Moves on: nor all thy Piety nor Wit
122:Nor all thy Tears wash out a Word of it.
Case Study: grep -b
Obvious iterative implementation
- process file line by line
- maintain byte displacement in an accumulator variable
Case Study: grep -b
Obvious iterative implementation
- process file line by line
- maintain byte displacement in an accumulator variable
Objective here is to implement it in stream code
- no accumulators allowed!
Case Study: grep -b
Streams – Why?
• Intention: replace loops for aggregate operations
10
Streams – Why?
• Intention: replace loops for aggregate operations
List<Person> people = …
Set<City> shortCities = new HashSet<>();

for (Person p : people) {
City c = p.getCity();
if (c.getName().length() < 4 ) {
shortCities.add(c);
}
}
instead of writing this:
10
Streams – Why?
• Intention: replace loops for aggregate operations
• more concise, more readable, composable operations, parallelizable
Set<City> shortCities = new HashSet<>();

for (Person p : people) {
City c = p.getCity();
if (c.getName().length() < 4 ) {
shortCities.add(c);
}
}
instead of writing this:
List<Person> people = …
Set<City> shortCities = people.stream()
.map(Person::getCity)

.filter(c -> c.getName().length() < 4)
.collect(toSet());
11
we’re going to write this:
Streams – Why?
• Intention: replace loops for aggregate operations
• more concise, more readable, composable operations, parallelizable
Set<City> shortCities = new HashSet<>();

for (Person p : people) {
City c = p.getCity();
if (c.getName().length() < 4 ) {
shortCities.add(c);
}
}
instead of writing this:
List<Person> people = …
Set<City> shortCities = people.stream()
.map(Person::getCity)

.filter(c -> c.getName().length() < 4)
.collect(toSet());
11
we’re going to write this:
Streams – Why?
• Intention: replace loops for aggregate operations
• more concise, more readable, composable operations, parallelizable
Set<City> shortCities = new HashSet<>();

for (Person p : people) {
City c = p.getCity();
if (c.getName().length() < 4 ) {
shortCities.add(c);
}
}
instead of writing this:
List<Person> people = …
Set<City> shortCities = people.parallelStream()
.map(Person::getCity)

.filter(c -> c.getName().length() < 4)
.collect(toSet());
12
we’re going to write this:
Visualising Sequential Streams
x2x0 x1 x3x0 x1 x2 x3
Source Map Filter Reduction
Intermediate
Operations
Terminal
Operation
“Values in Motion”
Visualising Sequential Streams
x2x0 x1 x3x1 x2 x3 ✔
Source Map Filter Reduction
Intermediate
Operations
Terminal
Operation
“Values in Motion”
Visualising Sequential Streams
x2x0 x1 x3 x1x2 x3 ❌✔
Source Map Filter Reduction
Intermediate
Operations
Terminal
Operation
“Values in Motion”
Visualising Sequential Streams
x2x0 x1 x3 x1x2x3 ❌✔
Source Map Filter Reduction
Intermediate
Operations
Terminal
Operation
“Values in Motion”
Journey’s End, JavaOne, October 2015
Simple Collector – toSet()
Collectors.toSet()
people.stream().collect(Collectors.toSet())
Journey’s End, JavaOne, October 2015
Simple Collector – toSet()
Stream<Person>
Collectors.toSet()
Set<Person>
people.stream().collect(Collectors.toSet())
Collector<Person,?,Set<Person>>
Journey’s End, JavaOne, October 2015
Simple Collector – toSet()
Stream<Person>
Collectors.toSet()
Set<Person>
people.stream().collect(Collectors.toSet())
bill
Collector<Person,?,Set<Person>>
Journey’s End, JavaOne, October 2015
Simple Collector – toSet()
Stream<Person>
Collectors.toSet()
Set<Person>
people.stream().collect(Collectors.toSet())
bill
Collector<Person,?,Set<Person>>
Journey’s End, JavaOne, October 2015
Simple Collector – toSet()
Stream<Person>
Collectors.toSet()
Set<Person>
people.stream().collect(Collectors.toSet())
bill
Collector<Person,?,Set<Person>>
Journey’s End, JavaOne, October 2015
Simple Collector – toSet()
Stream<Person>
Collectors.toSet()
Set<Person>
people.stream().collect(Collectors.toSet())
bill
jon
Collector<Person,?,Set<Person>>
Journey’s End, JavaOne, October 2015
Simple Collector – toSet()
Stream<Person>
Collectors.toSet()
Set<Person>
people.stream().collect(Collectors.toSet())
bill
jon
Collector<Person,?,Set<Person>>
Journey’s End, JavaOne, October 2015
Simple Collector – toSet()
Stream<Person>
Collectors.toSet()
Set<Person>
people.stream().collect(Collectors.toSet())
amy
bill
jon
Collector<Person,?,Set<Person>>
Journey’s End, JavaOne, October 2015
Simple Collector – toSet()
Stream<Person>
Collectors.toSet()
Set<Person>
people.stream().collect(Collectors.toSet())
amy
bill
jon
Collector<Person,?,Set<Person>>
Journey’s End, JavaOne, October 2015
Simple Collector – toSet()
Collectors.toSet()
Set<Person>
people.stream().collect(Collectors.toSet())
amy
bill
jon
Collector<Person,?,Set<Person>>
Journey’s End, JavaOne, October 2015
Simple Collector – toSet()
Collectors.toSet()
Set<Person>
{ , , }
people.stream().collect(Collectors.toSet())
amybilljon
Collector<Person,?,Set<Person>>
Classical Reduction
+
+
+
0 1 2 3
+
+
+
0
4 5 6 7
0
++
+
Classical Reduction
+
+
+
0 1 2 3
+
+
+
0
4 5 6 7
0
++
+
intStream.reduce(0,(a,b) -> a+b)
Mutable Reduction
a
a
a
e0 e1 e2 e3
a
a
a
e4 e5 e6 e7
aa
c
a: accumulator
c: combiner
Supplier
()->[] ()->[]
Mutable Reduction
a
a
a
e0 e1 e2 e3
a
a
a
e4 e5 e6 e7
aa
c
a: accumulator
c: combiner
Supplier
()->[] ()->[]
Agenda
• Define the problem
• Implement a solution
• Analyse performance
– find the bottleneck
• Fork/Join parallelism in the real world
#java8fairies
122Nor …Moves … 44
grep -b: Collector combiner
0The …[ , 80Shall … ], ,
41 122Nor …Moves … 36 44
grep -b: Collector combiner
0The … 44[ , 42 80Shall … ], ,
41 122Nor …Moves … 36 44
grep -b: Collector combiner
0The … 44[ , 42 80Shall … ]
41 42Nor …Moves … 36 440The … 44[ , 42 0Shall … ]
, ,
,] [
41 122Nor …Moves … 36 44
grep -b: Collector solution
0The … 44[ , 42 80Shall … ]
41 42Nor …Moves … 36 440The … 44[ , 42 0Shall … ]
, ,
,] [
41 122Nor …Moves … 36 44
grep -b: Collector solution
0The … 44[ , 42 80Shall … ]
41 42Nor …Moves … 36 440The … 44[ , 42 0Shall … ]
, ,
,] [
80
41 122Nor …Moves … 36 44
grep -b: Collector solution
0The … 44[ , 42 80Shall … ]
41 42Nor …Moves … 36 440The … 44[ , 42 0Shall … ]
, ,
,] [
80
41 122Nor …Moves … 36 44
grep -b: Collector solution
0The … 44[ , 42 80Shall … ]
41 42Nor …Moves … 36 440The … 44[ , 42 0Shall … ]
, ,
,] [
80
41 122Nor …Moves … 36 44
grep -b: Collector combiner
0The … 44[ , 42 80Shall … ]
41 42Nor …Moves … 36 440The … 44[ , 42 0Shall … ]
, ,
,] [
Moves … 36 0 41 0Nor …42 0Shall …0The … 44[ ]] [[ [] ]
grep -b: Collector accumulator
44 0The moving … writ,
“Moves on: … Wit”
44 0The moving … writ, 36 44Moves on: … Wit
][
][ ,
[ ]
Supplier “The moving … writ,”
accumulator
accumulator
Agenda
• Define the problem
• Implement a solution
• Analyse performance
– find the bottleneck
• Fork/Join parallelism in the real world
#java8fairies
Because we don’t have a problem?
Why Shouldn’t We Optimize Code?
Why Shouldn’t We Optimize Code?
Because we don’t have a problem
- No performance target!
Why Shouldn’t We Optimize Code?
Because we don’t have a problem
- No performance target!
Else there is a problem, but not in our process
Why Shouldn’t We Optimize Code?
Because we don’t have a problem
- No performance target!
Else there is a problem, but not in our process
Why Shouldn’t We Optimize Code?
Demo…
Because we don’t have a problem
- No performance target!
Else there is a problem, but not in our process
- The OS is struggling!
Why Shouldn’t We Optimize Code?
Because we don’t have a problem
- No performance target!
Else there is a problem, but not in our process
- The OS is struggling!
Else there’s a problem in our process, but not in the code
Why Shouldn’t We Optimize Code?
Because we don’t have a problem
- No performance target!
Else there is a problem, but not in our process
- The OS is struggling!
Else there’s a problem in our process, but not in the code
Why Shouldn’t We Optimize Code?
Demo…
Because we don’t have a problem
- No performance target!
Else there is a problem, but not in our process
- The OS is struggling!
Else there’s a problem in our process, but not in the code
- GC is using all the cycles!
Why Shouldn’t We Optimize Code?
Because we don’t have a problem
- No performance target!
Else there is a problem, but not in our process
- The OS is struggling!
Else there’s a problem in our process, but not in the code
- GC is using all the cycles!
Now we can consider the code
Else there’s a problem in the code… somewhere
- now we can go and profile it
Because we don’t have a problem
- No performance target!
Else there is a problem, but not in our process
- The OS is struggling!
Else there’s a problem in our process, but not in the code
- GC is using all the cycles!
Now we can consider the code
Else there’s a problem in the code… somewhere
- now we can go and profile it
Demo…
So, streaming IO is slow
So, streaming IO is slow
If only there was a way of getting all that data into memory…
So, streaming IO is slow
If only there was a way of getting all that data into memory…
Demo…
Agenda
• Define the problem
• Implement a solution
• Analyse performance
– find the bottleneck
• Fork/Join parallelism in the real world
#java8fairies
Agenda
• Define the problem
• Implement a solution
• Analyse performance
– find the bottleneck OR – have a bright idea!
• Fork/Join parallelism in the real world
#java8fairies
Intel Xeon E5 2600 10-core
Parallelism – Why?
The Free Lunch Is Over
http://www.gotw.ca/publications/concurrency-ddj.htm
The Transistor, Blessed at Birth
What’s Happened?
What’s Happened?
Physical limitations of the technology:
What’s Happened?
Physical limitations of the technology:
• signal leakage
What’s Happened?
Physical limitations of the technology:
• signal leakage
• heat dissipation
What’s Happened?
Physical limitations of the technology:
• signal leakage
• heat dissipation
• speed of light!
What’s Happened?
Physical limitations of the technology:
• signal leakage
• heat dissipation
• speed of light!
– 30cm = 1 light-nanosecond
What’s Happened?
Physical limitations of the technology:
• signal leakage
• heat dissipation
• speed of light!
– 30cm = 1 light-nanosecond
We’re not going to get faster cores,
What’s Happened?
Physical limitations of the technology:
• signal leakage
• heat dissipation
• speed of light!
– 30cm = 1 light-nanosecond
We’re not going to get faster cores,
we’re going to get more cores!
x2
Visualizing Parallel Streams
x0
x1
x3
x0
x1
x2
x3
x2
Visualizing Parallel Streams
x0
x1
x3
x0
x1
x2
x3
x2
Visualizing Parallel Streams
x1
x3
x0
x1
x3
✔
❌
x2
Visualizing Parallel Streams
x1
y3
x0
x1
x3
✔
❌
A Parallel Solution for grep -b
• Parallel streams need splittable sources
• Streaming I/O makes you subject to Amdahl’s Law:
A Parallel Solution for grep -b
• Parallel streams need splittable sources
• Streaming I/O makes you subject to Amdahl’s Law:
Blessing – and Curse – on the Transistor
Stream Sources for Parallel Processing
Implemented by a Spliterator
Stream Sources for Parallel Processing
Implemented by a Spliterator
Stream Sources for Parallel Processing
Implemented by a Spliterator
Stream Sources for Parallel Processing
Implemented by a Spliterator
Stream Sources for Parallel Processing
Implemented by a Spliterator
Stream Sources for Parallel Processing
Implemented by a Spliterator
Stream Sources for Parallel Processing
Implemented by a Spliterator
Stream Sources for Parallel Processing
Implemented by a Spliterator
Stream Sources for Parallel Processing
Implemented by a Spliterator
Moves …Wit
LineSpliterator
The moving Finger … writ n Shall … Line Nor all thy … itn n n
spliterator coverage
Moves …Wit
LineSpliterator
The moving Finger … writ n Shall … Line Nor all thy … itn n n
spliterator coverage
MappedByteBuffer
Moves …Wit
LineSpliterator
The moving Finger … writ n Shall … Line Nor all thy … itn n n
spliterator coverage
MappedByteBuffer mid
Moves …Wit
LineSpliterator
The moving Finger … writ n Shall … Line Nor all thy … itn n n
spliterator coverage
MappedByteBuffer mid
Moves …Wit
LineSpliterator
The moving Finger … writ n Shall … Line Nor all thy … itn n n
spliterator coveragenew spliterator coverage
MappedByteBuffer mid
Moves …Wit
LineSpliterator
The moving Finger … writ n Shall … Line Nor all thy … itn n n
spliterator coveragenew spliterator coverage
MappedByteBuffer mid
Demo…
Parallelizing grep -b
• Splitting action of LineSpliterator is O(log n)
• Collector no longer needs to compute index
• Result (relatively independent of data size):
- sequential stream ~2x as fast as iterative solution
- parallel stream >2.5x as fast as sequential stream
- on 4 hardware threads
Parallelizing Streams
Parallel-unfriendly intermediate operations:
stateful ones
– need to store some or all of the stream data in memory
– sorted()
those requiring ordering
– limit()
Collectors Cost Extra!
Depends on the performance of accumulator and combiner
functions
• toList(), toSet(), toCollection() – performance
normally dominated by accumulator
• but allow for the overhead of managing multithread access to non-
threadsafe containers for the combine operation
• toMap(), toConcurrentMap() – map merging is slow.
Resizing maps, especially concurrent maps, is very expensive.
Whenever possible, presize all data structures, maps in particular.
Agenda
• Define the problem
• Implement a solution
• Analyse performance
– find the bottleneck
• Fork/Join parallelism in the real world
#java8fairies
Simulated Server Environment
threadPool.execute(() -> {
try {
double value = logEntries.parallelStream()
.map(applicationStoppedTimePattern::matcher)
.filter(Matcher::find)
.map( matcher -> matcher.group(2))
.mapToDouble(Double::parseDouble)
.summaryStatistics().getSum();
} catch (Exception ex) {}
});
How Does It Perform?
• Total run time: 261.7 seconds
• Max: 39.2 secs, Min: 9.2 secs, Median: 22.0
secs
Tragedy of the Commons
Garrett Hardin, ecologist (1968):
Imagine the grazing of animals on a common ground.
Each flock owner gains if they add to their own flock.
But every animal added to the total degrades the
commons a small amount.
Tragedy of the Commons
Tragedy of the Commons
You have a finite amount of hardware
– it might be in your best interest to grab it all
– but if everyone behaves the same way…
Tragedy of the Commons
You have a finite amount of hardware
– it might be in your best interest to grab it all
– but if everyone behaves the same way…
Be a good neighbor
Tragedy of the Commons
You have a finite amount of hardware
– it might be in your best interest to grab it all
– but if everyone behaves the same way…
With many parallelStream() operations running concurrently,
performance is limited by the size of the common thread
pool and the number of cores you have
Be a good neighbor
Configuring Common Pool
Size of common ForkJoinPool is
• Runtime.getRuntime().availableProcessors() - 1
-Djava.util.concurrent.ForkJoinPool.common.parallelism=N
-Djava.util.concurrent.ForkJoinPool.common.threadFactory
-Djava.util.concurrent.ForkJoinPool.common.exceptionHandler
Fork-Join
Support for Fork-Join added in Java 7
• difficult coding idiom to master
Used internally by parallel streams
• uses a spliterator to segment the stream
• each stream is processed by a ForkJoinWorkerThread
How fork-join works and performs is important to latency
ForkJoinPool invoke
ForkJoinPool.invoke(ForkJoinTask) uses the submitting thread
as a worker
• If 100 threads all call invoke(), we would have
100+ForkJoinThreads exhausting the limiting resource, e.g. CPUs,
IO, etc.
ForkJoinPool submit/get
ForkJoinPool.submit(Callable).get() suspends the submitting
thread
• If 100 threads all call submit(), the work queue can become very
long, thus adding latency
Fork-Join Performance
Fork Join comes with significant overhead
• each chunk of work must be large enough to amortize the
overhead
C/P/N/Q Performance Model
C - number of submitters
P - number of CPUs
N - number of elements
Q - cost of the operation
When to go Parallel
The workload of the intermediate operations must be great
enough to outweigh the overheads (~100µs):
– initializing the fork/join framework
– splitting
– concurrent collection
Often quoted as N x Q
size of data set
(typically > 10,000)
processing cost per element
Kernel Times
CPU will not be the limiting factor when
• CPU is not saturated
• kernel times exceed 10% of user time
More threads will decrease performance
• predicted by Little’s Law
Common Thread Pool
Fork-Join by default uses a common thread pool
• default number of worker threads == number of logical cores - 1
• Always contains at least one thread
Performance is tied to whichever you run out of first
• availability of the constraining resource
• number of ForkJoinWorkerThreads/hardware threads
Everyone is working together to get it done!
All Hands on Deck!!!
Little’s Law
Fork-Join is a work queue
• work queue behavior is typically modeled using Little’s Law
Number of tasks in a system equals the arrival rate times the
amount of time it takes to clear an item
Task is submitted every 500ms, or 2 per second
Number of tasks = 2/sec * 2.8 seconds
= 5.6 tasks
Components of Latency
Latency is time from stimulus to result
• internally, latency consists of active and dead time
Reducing dead time assumes you
• can find it and are able to fill in with useful work
From Previous Example
if there is available hardware capacity then
make the pool bigger
else
add capacity
or tune to reduce strength of the dependency
ForkJoinPool Observability
• In an application where you have many parallel stream
operations all running concurrently performance will be affected
by the size of the common thread pool
• too small can starve threads from needed resources
• too big can cause threads to thrash on contended resources
ForkJoinPool comes with no visibility
• no metrics to help us tune
• instrument ForkJoinTask.invoke()
• gather measures that can be feed into Little’s Law
• Collect
• service times
• time submitted to time returned
• inter-arrival times
Instrumenting ForkJoinPool
public final V invoke() {
ForkJoinPool.common.getMonitor().submitTask(this);
int s;
if ((s = doInvoke() & DONE_MASK) != NORMAL) reportException(s);
ForkJoinPool.common.getMonitor().retireTask(this);
return getRawResult();
}
Performance
Submit log parsing to our own ForkJoinPool
new ForkJoinPool(16).submit(() -> ……… ).get()

new ForkJoinPool(8).submit(() -> ……… ).get()

new ForkJoinPool(4).submit(() -> ……… ).get()
16 worker
threads
8 worker
threads
4 worker
threads
0
75000
150000
225000
300000
Stream Parallel Flood Stream Flood Parallel
Performance mostly doesn’t matter
But if you must…
• sequential streams normally beat iterative solutions
• parallel streams can utilize all cores, providing
- the data is efficiently splittable
- the intermediate operations are sufficiently expensive and are
CPU-bound
- there isn’t contention for the processors
Conclusions
#java8fairies
Resources
#java8fairies
Resources
http://gee.cs.oswego.edu/dl/html/StreamParallelGuidance.html
#java8fairies
Resources
http://gee.cs.oswego.edu/dl/html/StreamParallelGuidance.html
http://shipilev.net/talks/devoxx-Nov2013-benchmarking.pdf
#java8fairies
Resources
http://gee.cs.oswego.edu/dl/html/StreamParallelGuidance.html
http://shipilev.net/talks/devoxx-Nov2013-benchmarking.pdf
http://openjdk.java.net/projects/code-tools/jmh/
#java8fairies
Resources
http://gee.cs.oswego.edu/dl/html/StreamParallelGuidance.html
http://shipilev.net/talks/devoxx-Nov2013-benchmarking.pdf
http://openjdk.java.net/projects/code-tools/jmh/
#java8fairies

Contenu connexe

Tendances

Kotlin @ Coupang Backed - JetBrains Day seoul 2018
Kotlin @ Coupang Backed - JetBrains Day seoul 2018Kotlin @ Coupang Backed - JetBrains Day seoul 2018
Kotlin @ Coupang Backed - JetBrains Day seoul 2018Sunghyouk Bae
 
Weaving Dataflows with Silk - ScalaMatsuri 2014, Tokyo
Weaving Dataflows with Silk - ScalaMatsuri 2014, TokyoWeaving Dataflows with Silk - ScalaMatsuri 2014, Tokyo
Weaving Dataflows with Silk - ScalaMatsuri 2014, TokyoTaro L. Saito
 
Effective testing for spark programs Strata NY 2015
Effective testing for spark programs   Strata NY 2015Effective testing for spark programs   Strata NY 2015
Effective testing for spark programs Strata NY 2015Holden Karau
 
HBase RowKey design for Akka Persistence
HBase RowKey design for Akka PersistenceHBase RowKey design for Akka Persistence
HBase RowKey design for Akka PersistenceKonrad Malawski
 
Kotlin @ Coupang Backend 2017
Kotlin @ Coupang Backend 2017Kotlin @ Coupang Backend 2017
Kotlin @ Coupang Backend 2017Sunghyouk Bae
 
Apache Spark Structured Streaming for Machine Learning - StrataConf 2016
Apache Spark Structured Streaming for Machine Learning - StrataConf 2016Apache Spark Structured Streaming for Machine Learning - StrataConf 2016
Apache Spark Structured Streaming for Machine Learning - StrataConf 2016Holden Karau
 
Introduction of failsafe
Introduction of failsafeIntroduction of failsafe
Introduction of failsafeSunghyouk Bae
 
2014 akka-streams-tokyo-japanese
2014 akka-streams-tokyo-japanese2014 akka-streams-tokyo-japanese
2014 akka-streams-tokyo-japaneseKonrad Malawski
 
Beyond parallelize and collect - Spark Summit East 2016
Beyond parallelize and collect - Spark Summit East 2016Beyond parallelize and collect - Spark Summit East 2016
Beyond parallelize and collect - Spark Summit East 2016Holden Karau
 
Algebird : Abstract Algebra for big data analytics. Devoxx 2014
Algebird : Abstract Algebra for big data analytics. Devoxx 2014Algebird : Abstract Algebra for big data analytics. Devoxx 2014
Algebird : Abstract Algebra for big data analytics. Devoxx 2014Samir Bessalah
 
Kotlin Receiver Types 介紹
Kotlin Receiver Types 介紹Kotlin Receiver Types 介紹
Kotlin Receiver Types 介紹Kros Huang
 
Reactive Streams / Akka Streams - GeeCON Prague 2014
Reactive Streams / Akka Streams - GeeCON Prague 2014Reactive Streams / Akka Streams - GeeCON Prague 2014
Reactive Streams / Akka Streams - GeeCON Prague 2014Konrad Malawski
 
Ge aviation spark application experience porting analytics into py spark ml p...
Ge aviation spark application experience porting analytics into py spark ml p...Ge aviation spark application experience porting analytics into py spark ml p...
Ge aviation spark application experience porting analytics into py spark ml p...Databricks
 
ITSubbotik - как скрестить ежа с ужом или подводные камни внедрения функциона...
ITSubbotik - как скрестить ежа с ужом или подводные камни внедрения функциона...ITSubbotik - как скрестить ежа с ужом или подводные камни внедрения функциона...
ITSubbotik - как скрестить ежа с ужом или подводные камни внедрения функциона...Vyacheslav Lapin
 
Storm - As deep into real-time data processing as you can get in 30 minutes.
Storm - As deep into real-time data processing as you can get in 30 minutes.Storm - As deep into real-time data processing as you can get in 30 minutes.
Storm - As deep into real-time data processing as you can get in 30 minutes.Dan Lynn
 
Fresh from the Oven (04.2015): Experimental Akka Typed and Akka Streams
Fresh from the Oven (04.2015): Experimental Akka Typed and Akka StreamsFresh from the Oven (04.2015): Experimental Akka Typed and Akka Streams
Fresh from the Oven (04.2015): Experimental Akka Typed and Akka StreamsKonrad Malawski
 
Improving PySpark Performance - Spark Beyond the JVM @ PyData DC 2016
Improving PySpark Performance - Spark Beyond the JVM @ PyData DC 2016Improving PySpark Performance - Spark Beyond the JVM @ PyData DC 2016
Improving PySpark Performance - Spark Beyond the JVM @ PyData DC 2016Holden Karau
 

Tendances (20)

Hot Streaming Java
Hot Streaming JavaHot Streaming Java
Hot Streaming Java
 
Kotlin @ Coupang Backed - JetBrains Day seoul 2018
Kotlin @ Coupang Backed - JetBrains Day seoul 2018Kotlin @ Coupang Backed - JetBrains Day seoul 2018
Kotlin @ Coupang Backed - JetBrains Day seoul 2018
 
Weaving Dataflows with Silk - ScalaMatsuri 2014, Tokyo
Weaving Dataflows with Silk - ScalaMatsuri 2014, TokyoWeaving Dataflows with Silk - ScalaMatsuri 2014, Tokyo
Weaving Dataflows with Silk - ScalaMatsuri 2014, Tokyo
 
Effective testing for spark programs Strata NY 2015
Effective testing for spark programs   Strata NY 2015Effective testing for spark programs   Strata NY 2015
Effective testing for spark programs Strata NY 2015
 
HBase RowKey design for Akka Persistence
HBase RowKey design for Akka PersistenceHBase RowKey design for Akka Persistence
HBase RowKey design for Akka Persistence
 
Graphite
GraphiteGraphite
Graphite
 
Kotlin @ Coupang Backend 2017
Kotlin @ Coupang Backend 2017Kotlin @ Coupang Backend 2017
Kotlin @ Coupang Backend 2017
 
Apache Spark Structured Streaming for Machine Learning - StrataConf 2016
Apache Spark Structured Streaming for Machine Learning - StrataConf 2016Apache Spark Structured Streaming for Machine Learning - StrataConf 2016
Apache Spark Structured Streaming for Machine Learning - StrataConf 2016
 
Introduction of failsafe
Introduction of failsafeIntroduction of failsafe
Introduction of failsafe
 
2014 akka-streams-tokyo-japanese
2014 akka-streams-tokyo-japanese2014 akka-streams-tokyo-japanese
2014 akka-streams-tokyo-japanese
 
Beyond parallelize and collect - Spark Summit East 2016
Beyond parallelize and collect - Spark Summit East 2016Beyond parallelize and collect - Spark Summit East 2016
Beyond parallelize and collect - Spark Summit East 2016
 
Algebird : Abstract Algebra for big data analytics. Devoxx 2014
Algebird : Abstract Algebra for big data analytics. Devoxx 2014Algebird : Abstract Algebra for big data analytics. Devoxx 2014
Algebird : Abstract Algebra for big data analytics. Devoxx 2014
 
Kotlin Receiver Types 介紹
Kotlin Receiver Types 介紹Kotlin Receiver Types 介紹
Kotlin Receiver Types 介紹
 
Reactive Streams / Akka Streams - GeeCON Prague 2014
Reactive Streams / Akka Streams - GeeCON Prague 2014Reactive Streams / Akka Streams - GeeCON Prague 2014
Reactive Streams / Akka Streams - GeeCON Prague 2014
 
Scalding
ScaldingScalding
Scalding
 
Ge aviation spark application experience porting analytics into py spark ml p...
Ge aviation spark application experience porting analytics into py spark ml p...Ge aviation spark application experience porting analytics into py spark ml p...
Ge aviation spark application experience porting analytics into py spark ml p...
 
ITSubbotik - как скрестить ежа с ужом или подводные камни внедрения функциона...
ITSubbotik - как скрестить ежа с ужом или подводные камни внедрения функциона...ITSubbotik - как скрестить ежа с ужом или подводные камни внедрения функциона...
ITSubbotik - как скрестить ежа с ужом или подводные камни внедрения функциона...
 
Storm - As deep into real-time data processing as you can get in 30 minutes.
Storm - As deep into real-time data processing as you can get in 30 minutes.Storm - As deep into real-time data processing as you can get in 30 minutes.
Storm - As deep into real-time data processing as you can get in 30 minutes.
 
Fresh from the Oven (04.2015): Experimental Akka Typed and Akka Streams
Fresh from the Oven (04.2015): Experimental Akka Typed and Akka StreamsFresh from the Oven (04.2015): Experimental Akka Typed and Akka Streams
Fresh from the Oven (04.2015): Experimental Akka Typed and Akka Streams
 
Improving PySpark Performance - Spark Beyond the JVM @ PyData DC 2016
Improving PySpark Performance - Spark Beyond the JVM @ PyData DC 2016Improving PySpark Performance - Spark Beyond the JVM @ PyData DC 2016
Improving PySpark Performance - Spark Beyond the JVM @ PyData DC 2016
 

En vedette

Model multiplication of decimals
Model multiplication of decimalsModel multiplication of decimals
Model multiplication of decimalsbujols
 
Présentation Kivy (et projets associés) à Pycon-fr 2013
Présentation Kivy (et projets associés) à Pycon-fr 2013Présentation Kivy (et projets associés) à Pycon-fr 2013
Présentation Kivy (et projets associés) à Pycon-fr 2013Gabriel Pettier
 
Metasepi team meeting #6: "Snatch-driven development"
Metasepi team meeting #6: "Snatch-driven development"Metasepi team meeting #6: "Snatch-driven development"
Metasepi team meeting #6: "Snatch-driven development"Kiwamu Okabe
 
Managing gang of chaotic developers is complex at Agile Tour Riga 2012
Managing gang of chaotic developers is complex at Agile Tour Riga 2012Managing gang of chaotic developers is complex at Agile Tour Riga 2012
Managing gang of chaotic developers is complex at Agile Tour Riga 2012Piotr Burdylo
 
Agile Management 2013 - Nie tylko it
Agile Management 2013 - Nie tylko itAgile Management 2013 - Nie tylko it
Agile Management 2013 - Nie tylko itPiotr Burdylo
 
A Scalable I/O Manager for GHC
A Scalable I/O Manager for GHCA Scalable I/O Manager for GHC
A Scalable I/O Manager for GHCJohan Tibell
 
Monadologie
MonadologieMonadologie
Monadologieleague
 
A Hitchhiker's Guide to the Inter-Cloud
A Hitchhiker's Guide to the Inter-CloudA Hitchhiker's Guide to the Inter-Cloud
A Hitchhiker's Guide to the Inter-CloudGovCloud Network
 
Federated CDNs: What every service provider should know
Federated CDNs: What every service provider should knowFederated CDNs: What every service provider should know
Federated CDNs: What every service provider should knowPatrick Hurley
 
Be careful when entering a casino (Agile by Example 2012)
Be careful when entering a casino (Agile by Example 2012)Be careful when entering a casino (Agile by Example 2012)
Be careful when entering a casino (Agile by Example 2012)Piotr Burdylo
 
Sneaking Scala through the Back Door
Sneaking Scala through the Back DoorSneaking Scala through the Back Door
Sneaking Scala through the Back DoorDianne Marsh
 
Vert.x - JDD 2013 (English)
Vert.x - JDD 2013 (English)Vert.x - JDD 2013 (English)
Vert.x - JDD 2013 (English)Bartek Zdanowski
 
Efficient Immutable Data Structures (Okasaki for Dummies)
Efficient Immutable Data Structures (Okasaki for Dummies)Efficient Immutable Data Structures (Okasaki for Dummies)
Efficient Immutable Data Structures (Okasaki for Dummies)Tom Faulhaber
 
Protecting Java EE Web Apps with Secure HTTP Headers
Protecting Java EE Web Apps with Secure HTTP HeadersProtecting Java EE Web Apps with Secure HTTP Headers
Protecting Java EE Web Apps with Secure HTTP HeadersFrank Kim
 
Software Dendrology by Brandon Bloom
Software Dendrology by Brandon BloomSoftware Dendrology by Brandon Bloom
Software Dendrology by Brandon BloomHakka Labs
 
Haskell is Not For Production and Other Tales
Haskell is Not For Production and Other TalesHaskell is Not For Production and Other Tales
Haskell is Not For Production and Other TalesKatie Ots
 
erlang at hover.in , Devcamp Blr 09
erlang at hover.in , Devcamp Blr 09erlang at hover.in , Devcamp Blr 09
erlang at hover.in , Devcamp Blr 09Bhasker Kode
 
O'Reilly ETech Conference: Laszlo RIA
O'Reilly ETech Conference: Laszlo RIAO'Reilly ETech Conference: Laszlo RIA
O'Reilly ETech Conference: Laszlo RIAOliver Steele
 
Wakanda: a new end-to-end JavaScript platform - JSConf Berlin 2009
Wakanda: a new end-to-end JavaScript platform - JSConf Berlin 2009Wakanda: a new end-to-end JavaScript platform - JSConf Berlin 2009
Wakanda: a new end-to-end JavaScript platform - JSConf Berlin 2009Alexandre Morgaut
 

En vedette (20)

Model multiplication of decimals
Model multiplication of decimalsModel multiplication of decimals
Model multiplication of decimals
 
Présentation Kivy (et projets associés) à Pycon-fr 2013
Présentation Kivy (et projets associés) à Pycon-fr 2013Présentation Kivy (et projets associés) à Pycon-fr 2013
Présentation Kivy (et projets associés) à Pycon-fr 2013
 
Metasepi team meeting #6: "Snatch-driven development"
Metasepi team meeting #6: "Snatch-driven development"Metasepi team meeting #6: "Snatch-driven development"
Metasepi team meeting #6: "Snatch-driven development"
 
Managing gang of chaotic developers is complex at Agile Tour Riga 2012
Managing gang of chaotic developers is complex at Agile Tour Riga 2012Managing gang of chaotic developers is complex at Agile Tour Riga 2012
Managing gang of chaotic developers is complex at Agile Tour Riga 2012
 
Agile Management 2013 - Nie tylko it
Agile Management 2013 - Nie tylko itAgile Management 2013 - Nie tylko it
Agile Management 2013 - Nie tylko it
 
A Scalable I/O Manager for GHC
A Scalable I/O Manager for GHCA Scalable I/O Manager for GHC
A Scalable I/O Manager for GHC
 
Monadologie
MonadologieMonadologie
Monadologie
 
A Hitchhiker's Guide to the Inter-Cloud
A Hitchhiker's Guide to the Inter-CloudA Hitchhiker's Guide to the Inter-Cloud
A Hitchhiker's Guide to the Inter-Cloud
 
Federated CDNs: What every service provider should know
Federated CDNs: What every service provider should knowFederated CDNs: What every service provider should know
Federated CDNs: What every service provider should know
 
Be careful when entering a casino (Agile by Example 2012)
Be careful when entering a casino (Agile by Example 2012)Be careful when entering a casino (Agile by Example 2012)
Be careful when entering a casino (Agile by Example 2012)
 
Sneaking Scala through the Back Door
Sneaking Scala through the Back DoorSneaking Scala through the Back Door
Sneaking Scala through the Back Door
 
Vert.x - JDD 2013 (English)
Vert.x - JDD 2013 (English)Vert.x - JDD 2013 (English)
Vert.x - JDD 2013 (English)
 
Efficient Immutable Data Structures (Okasaki for Dummies)
Efficient Immutable Data Structures (Okasaki for Dummies)Efficient Immutable Data Structures (Okasaki for Dummies)
Efficient Immutable Data Structures (Okasaki for Dummies)
 
Protecting Java EE Web Apps with Secure HTTP Headers
Protecting Java EE Web Apps with Secure HTTP HeadersProtecting Java EE Web Apps with Secure HTTP Headers
Protecting Java EE Web Apps with Secure HTTP Headers
 
Software Dendrology by Brandon Bloom
Software Dendrology by Brandon BloomSoftware Dendrology by Brandon Bloom
Software Dendrology by Brandon Bloom
 
Haskell is Not For Production and Other Tales
Haskell is Not For Production and Other TalesHaskell is Not For Production and Other Tales
Haskell is Not For Production and Other Tales
 
erlang at hover.in , Devcamp Blr 09
erlang at hover.in , Devcamp Blr 09erlang at hover.in , Devcamp Blr 09
erlang at hover.in , Devcamp Blr 09
 
O'Reilly ETech Conference: Laszlo RIA
O'Reilly ETech Conference: Laszlo RIAO'Reilly ETech Conference: Laszlo RIA
O'Reilly ETech Conference: Laszlo RIA
 
Wakanda: a new end-to-end JavaScript platform - JSConf Berlin 2009
Wakanda: a new end-to-end JavaScript platform - JSConf Berlin 2009Wakanda: a new end-to-end JavaScript platform - JSConf Berlin 2009
Wakanda: a new end-to-end JavaScript platform - JSConf Berlin 2009
 
Laszlo PyCon 2005
Laszlo PyCon 2005Laszlo PyCon 2005
Laszlo PyCon 2005
 

Similaire à Good and Wicked Fairies, and the Tragedy of the Commons: Understanding the Performance of Java 8 Streams

Reactive Web-Applications @ LambdaDays
Reactive Web-Applications @ LambdaDaysReactive Web-Applications @ LambdaDays
Reactive Web-Applications @ LambdaDaysManuel Bernhardt
 
Voxxed Days Vienna - The Why and How of Reactive Web-Applications on the JVM
Voxxed Days Vienna - The Why and How of Reactive Web-Applications on the JVMVoxxed Days Vienna - The Why and How of Reactive Web-Applications on the JVM
Voxxed Days Vienna - The Why and How of Reactive Web-Applications on the JVMManuel Bernhardt
 
Hands on Training – Graph Database with Neo4j
Hands on Training – Graph Database with Neo4jHands on Training – Graph Database with Neo4j
Hands on Training – Graph Database with Neo4jSerendio Inc.
 
Apache Spark for Library Developers with William Benton and Erik Erlandson
 Apache Spark for Library Developers with William Benton and Erik Erlandson Apache Spark for Library Developers with William Benton and Erik Erlandson
Apache Spark for Library Developers with William Benton and Erik ErlandsonDatabricks
 
A Few of My Favorite (Python) Things
A Few of My Favorite (Python) ThingsA Few of My Favorite (Python) Things
A Few of My Favorite (Python) ThingsMichael Pirnat
 
The openCypher Project - An Open Graph Query Language
The openCypher Project - An Open Graph Query LanguageThe openCypher Project - An Open Graph Query Language
The openCypher Project - An Open Graph Query LanguageNeo4j
 
Java 8 - Return of the Java
Java 8 - Return of the JavaJava 8 - Return of the Java
Java 8 - Return of the JavaFredrik Vraalsen
 
Scala Collections : Java 8 on Steroids
Scala Collections : Java 8 on SteroidsScala Collections : Java 8 on Steroids
Scala Collections : Java 8 on SteroidsFrançois Garillot
 
Community-driven Language Design at TC39 on the JavaScript Pipeline Operator ...
Community-driven Language Design at TC39 on the JavaScript Pipeline Operator ...Community-driven Language Design at TC39 on the JavaScript Pipeline Operator ...
Community-driven Language Design at TC39 on the JavaScript Pipeline Operator ...Igalia
 
Free The Enterprise With Ruby & Master Your Own Domain
Free The Enterprise With Ruby & Master Your Own DomainFree The Enterprise With Ruby & Master Your Own Domain
Free The Enterprise With Ruby & Master Your Own DomainKen Collins
 
Reactive Stream Processing with Akka Streams
Reactive Stream Processing with Akka StreamsReactive Stream Processing with Akka Streams
Reactive Stream Processing with Akka StreamsKonrad Malawski
 
Kotlin Introduction with Android applications
Kotlin Introduction with Android applicationsKotlin Introduction with Android applications
Kotlin Introduction with Android applicationsThao Huynh Quang
 
CM NCCU Class2
CM NCCU Class2CM NCCU Class2
CM NCCU Class2志明 陳
 
Graal in GraalVM - A New JIT Compiler
Graal in GraalVM - A New JIT CompilerGraal in GraalVM - A New JIT Compiler
Graal in GraalVM - A New JIT CompilerKoichi Sakata
 
Tomasz Nurkiewicz - Programowanie reaktywne: czego się nauczyłem
Tomasz Nurkiewicz - Programowanie reaktywne: czego się nauczyłemTomasz Nurkiewicz - Programowanie reaktywne: czego się nauczyłem
Tomasz Nurkiewicz - Programowanie reaktywne: czego się nauczyłemSegFaultConf
 

Similaire à Good and Wicked Fairies, and the Tragedy of the Commons: Understanding the Performance of Java 8 Streams (20)

Reactive Web-Applications @ LambdaDays
Reactive Web-Applications @ LambdaDaysReactive Web-Applications @ LambdaDays
Reactive Web-Applications @ LambdaDays
 
Voxxed Days Vienna - The Why and How of Reactive Web-Applications on the JVM
Voxxed Days Vienna - The Why and How of Reactive Web-Applications on the JVMVoxxed Days Vienna - The Why and How of Reactive Web-Applications on the JVM
Voxxed Days Vienna - The Why and How of Reactive Web-Applications on the JVM
 
Hands on Training – Graph Database with Neo4j
Hands on Training – Graph Database with Neo4jHands on Training – Graph Database with Neo4j
Hands on Training – Graph Database with Neo4j
 
RxSwift to Combine
RxSwift to CombineRxSwift to Combine
RxSwift to Combine
 
RxSwift to Combine
RxSwift to CombineRxSwift to Combine
RxSwift to Combine
 
Apache Spark for Library Developers with William Benton and Erik Erlandson
 Apache Spark for Library Developers with William Benton and Erik Erlandson Apache Spark for Library Developers with William Benton and Erik Erlandson
Apache Spark for Library Developers with William Benton and Erik Erlandson
 
Intro to Akka Streams
Intro to Akka StreamsIntro to Akka Streams
Intro to Akka Streams
 
A Few of My Favorite (Python) Things
A Few of My Favorite (Python) ThingsA Few of My Favorite (Python) Things
A Few of My Favorite (Python) Things
 
The openCypher Project - An Open Graph Query Language
The openCypher Project - An Open Graph Query LanguageThe openCypher Project - An Open Graph Query Language
The openCypher Project - An Open Graph Query Language
 
Java 8 - Return of the Java
Java 8 - Return of the JavaJava 8 - Return of the Java
Java 8 - Return of the Java
 
zStore
zStorezStore
zStore
 
Scala Collections : Java 8 on Steroids
Scala Collections : Java 8 on SteroidsScala Collections : Java 8 on Steroids
Scala Collections : Java 8 on Steroids
 
Community-driven Language Design at TC39 on the JavaScript Pipeline Operator ...
Community-driven Language Design at TC39 on the JavaScript Pipeline Operator ...Community-driven Language Design at TC39 on the JavaScript Pipeline Operator ...
Community-driven Language Design at TC39 on the JavaScript Pipeline Operator ...
 
Free The Enterprise With Ruby & Master Your Own Domain
Free The Enterprise With Ruby & Master Your Own DomainFree The Enterprise With Ruby & Master Your Own Domain
Free The Enterprise With Ruby & Master Your Own Domain
 
Reactive Stream Processing with Akka Streams
Reactive Stream Processing with Akka StreamsReactive Stream Processing with Akka Streams
Reactive Stream Processing with Akka Streams
 
Kotlin Introduction with Android applications
Kotlin Introduction with Android applicationsKotlin Introduction with Android applications
Kotlin Introduction with Android applications
 
CM NCCU Class2
CM NCCU Class2CM NCCU Class2
CM NCCU Class2
 
Graal in GraalVM - A New JIT Compiler
Graal in GraalVM - A New JIT CompilerGraal in GraalVM - A New JIT Compiler
Graal in GraalVM - A New JIT Compiler
 
Tomasz Nurkiewicz - Programowanie reaktywne: czego się nauczyłem
Tomasz Nurkiewicz - Programowanie reaktywne: czego się nauczyłemTomasz Nurkiewicz - Programowanie reaktywne: czego się nauczyłem
Tomasz Nurkiewicz - Programowanie reaktywne: czego się nauczyłem
 
Spl Not A Bridge Too Far phpNW09
Spl Not A Bridge Too Far phpNW09Spl Not A Bridge Too Far phpNW09
Spl Not A Bridge Too Far phpNW09
 

Dernier

Osi security architecture in network.pptx
Osi security architecture in network.pptxOsi security architecture in network.pptx
Osi security architecture in network.pptxVinzoCenzo
 
Patterns for automating API delivery. API conference
Patterns for automating API delivery. API conferencePatterns for automating API delivery. API conference
Patterns for automating API delivery. API conferencessuser9e7c64
 
2024 DevNexus Patterns for Resiliency: Shuffle shards
2024 DevNexus Patterns for Resiliency: Shuffle shards2024 DevNexus Patterns for Resiliency: Shuffle shards
2024 DevNexus Patterns for Resiliency: Shuffle shardsChristopher Curtin
 
Strategies for using alternative queries to mitigate zero results
Strategies for using alternative queries to mitigate zero resultsStrategies for using alternative queries to mitigate zero results
Strategies for using alternative queries to mitigate zero resultsJean Silva
 
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...OnePlan Solutions
 
Post Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on IdentityPost Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on Identityteam-WIBU
 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfDrew Moseley
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationBradBedford3
 
SoftTeco - Software Development Company Profile
SoftTeco - Software Development Company ProfileSoftTeco - Software Development Company Profile
SoftTeco - Software Development Company Profileakrivarotava
 
Powering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsPowering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsSafe Software
 
Salesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZSalesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZABSYZ Inc
 
Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalLionel Briand
 
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full RecordingOpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full RecordingShane Coughlan
 
SAM Training Session - How to use EXCEL ?
SAM Training Session - How to use EXCEL ?SAM Training Session - How to use EXCEL ?
SAM Training Session - How to use EXCEL ?Alexandre Beguel
 
Effectively Troubleshoot 9 Types of OutOfMemoryError
Effectively Troubleshoot 9 Types of OutOfMemoryErrorEffectively Troubleshoot 9 Types of OutOfMemoryError
Effectively Troubleshoot 9 Types of OutOfMemoryErrorTier1 app
 
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsSensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsChristian Birchler
 
Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...Rob Geurden
 
A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfMarharyta Nedzelska
 
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...Bert Jan Schrijver
 
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...OnePlan Solutions
 

Dernier (20)

Osi security architecture in network.pptx
Osi security architecture in network.pptxOsi security architecture in network.pptx
Osi security architecture in network.pptx
 
Patterns for automating API delivery. API conference
Patterns for automating API delivery. API conferencePatterns for automating API delivery. API conference
Patterns for automating API delivery. API conference
 
2024 DevNexus Patterns for Resiliency: Shuffle shards
2024 DevNexus Patterns for Resiliency: Shuffle shards2024 DevNexus Patterns for Resiliency: Shuffle shards
2024 DevNexus Patterns for Resiliency: Shuffle shards
 
Strategies for using alternative queries to mitigate zero results
Strategies for using alternative queries to mitigate zero resultsStrategies for using alternative queries to mitigate zero results
Strategies for using alternative queries to mitigate zero results
 
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
 
Post Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on IdentityPost Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on Identity
 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdf
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion Application
 
SoftTeco - Software Development Company Profile
SoftTeco - Software Development Company ProfileSoftTeco - Software Development Company Profile
SoftTeco - Software Development Company Profile
 
Powering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsPowering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data Streams
 
Salesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZSalesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZ
 
Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive Goal
 
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full RecordingOpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
 
SAM Training Session - How to use EXCEL ?
SAM Training Session - How to use EXCEL ?SAM Training Session - How to use EXCEL ?
SAM Training Session - How to use EXCEL ?
 
Effectively Troubleshoot 9 Types of OutOfMemoryError
Effectively Troubleshoot 9 Types of OutOfMemoryErrorEffectively Troubleshoot 9 Types of OutOfMemoryError
Effectively Troubleshoot 9 Types of OutOfMemoryError
 
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsSensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
 
Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...
 
A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdf
 
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...
 
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
 

Good and Wicked Fairies, and the Tragedy of the Commons: Understanding the Performance of Java 8 Streams

  • 1. Good and Wicked Fairies The Tragedy of the Commons Understanding the Performance of Java 8 Streams Kirk Pepperdine @kcpeppe MauriceNaftalin @mauricenaftalin #java8fairies
  • 2. About Kirk • Specialises in performance tuning • speaks frequently about performance • author of performance tuning workshop • Co-founder jClarity • performance diagnositic tooling • Java Champion (since 2006)
  • 3. About Kirk • Specialises in performance tuning • speaks frequently about performance • author of performance tuning workshop • Co-founder jClarity • performance diagnositic tooling • Java Champion (since 2006)
  • 5. About Maurice Developer, designer, architect, teacher, learner, writer
  • 6. About Maurice Co-author Developer, designer, architect, teacher, learner, writer
  • 7. About Maurice Co-author Author Developer, designer, architect, teacher, learner, writer
  • 8. About Maurice Co-author Author Developer, designer, architect, teacher, learner, writer
  • 12. Agenda • Define the problem #java8fairies
  • 13. Agenda • Define the problem • Implement a solution #java8fairies
  • 14. Agenda • Define the problem • Implement a solution • Analyse performance #java8fairies
  • 15. Agenda • Define the problem • Implement a solution • Analyse performance – find the bottleneck #java8fairies
  • 16. Agenda • Define the problem • Implement a solution • Analyse performance – find the bottleneck #java8fairies
  • 17. Agenda • Define the problem • Implement a solution • Analyse performance – find the bottleneck • Fork/Join parallelism in the real world #java8fairies
  • 18. Agenda • Define the problem • Implement a solution • Analyse performance – find the bottleneck • Fork/Join parallelism in the real world #java8fairies
  • 19. Agenda • Define the problem • Implement a solution • Analyse performance – find the bottleneck • Fork/Join parallelism in the real world #java8fairies
  • 20. Case Study: grep -b grep -b: “The offset in bytes of a matched pattern is displayed in front of the matched line.”
  • 21. Case Study: grep -b The Moving Finger writes; and, having writ, Moves on: nor all thy Piety nor Wit Shall bring it back to cancel half a Line Nor all thy Tears wash out a Word of it. rubai51.txt grep -b: “The offset in bytes of a matched pattern is displayed in front of the matched line.”
  • 22. Case Study: grep -b The Moving Finger writes; and, having writ, Moves on: nor all thy Piety nor Wit Shall bring it back to cancel half a Line Nor all thy Tears wash out a Word of it. rubai51.txt grep -b: “The offset in bytes of a matched pattern is displayed in front of the matched line.” $ grep -b 'W.*t' rubai51.txt 44:Moves on: nor all thy Piety nor Wit 122:Nor all thy Tears wash out a Word of it.
  • 24. Obvious iterative implementation - process file line by line - maintain byte displacement in an accumulator variable Case Study: grep -b
  • 25. Obvious iterative implementation - process file line by line - maintain byte displacement in an accumulator variable Objective here is to implement it in stream code - no accumulators allowed! Case Study: grep -b
  • 26. Streams – Why? • Intention: replace loops for aggregate operations 10
  • 27. Streams – Why? • Intention: replace loops for aggregate operations List<Person> people = … Set<City> shortCities = new HashSet<>();
 for (Person p : people) { City c = p.getCity(); if (c.getName().length() < 4 ) { shortCities.add(c); } } instead of writing this: 10
  • 28. Streams – Why? • Intention: replace loops for aggregate operations • more concise, more readable, composable operations, parallelizable Set<City> shortCities = new HashSet<>();
 for (Person p : people) { City c = p.getCity(); if (c.getName().length() < 4 ) { shortCities.add(c); } } instead of writing this: List<Person> people = … Set<City> shortCities = people.stream() .map(Person::getCity)
 .filter(c -> c.getName().length() < 4) .collect(toSet()); 11 we’re going to write this:
  • 29. Streams – Why? • Intention: replace loops for aggregate operations • more concise, more readable, composable operations, parallelizable Set<City> shortCities = new HashSet<>();
 for (Person p : people) { City c = p.getCity(); if (c.getName().length() < 4 ) { shortCities.add(c); } } instead of writing this: List<Person> people = … Set<City> shortCities = people.stream() .map(Person::getCity)
 .filter(c -> c.getName().length() < 4) .collect(toSet()); 11 we’re going to write this:
  • 30. Streams – Why? • Intention: replace loops for aggregate operations • more concise, more readable, composable operations, parallelizable Set<City> shortCities = new HashSet<>();
 for (Person p : people) { City c = p.getCity(); if (c.getName().length() < 4 ) { shortCities.add(c); } } instead of writing this: List<Person> people = … Set<City> shortCities = people.parallelStream() .map(Person::getCity)
 .filter(c -> c.getName().length() < 4) .collect(toSet()); 12 we’re going to write this:
  • 31. Visualising Sequential Streams x2x0 x1 x3x0 x1 x2 x3 Source Map Filter Reduction Intermediate Operations Terminal Operation “Values in Motion”
  • 32. Visualising Sequential Streams x2x0 x1 x3x1 x2 x3 ✔ Source Map Filter Reduction Intermediate Operations Terminal Operation “Values in Motion”
  • 33. Visualising Sequential Streams x2x0 x1 x3 x1x2 x3 ❌✔ Source Map Filter Reduction Intermediate Operations Terminal Operation “Values in Motion”
  • 34. Visualising Sequential Streams x2x0 x1 x3 x1x2x3 ❌✔ Source Map Filter Reduction Intermediate Operations Terminal Operation “Values in Motion”
  • 35. Journey’s End, JavaOne, October 2015 Simple Collector – toSet() Collectors.toSet() people.stream().collect(Collectors.toSet())
  • 36. Journey’s End, JavaOne, October 2015 Simple Collector – toSet() Stream<Person> Collectors.toSet() Set<Person> people.stream().collect(Collectors.toSet()) Collector<Person,?,Set<Person>>
  • 37. Journey’s End, JavaOne, October 2015 Simple Collector – toSet() Stream<Person> Collectors.toSet() Set<Person> people.stream().collect(Collectors.toSet()) bill Collector<Person,?,Set<Person>>
  • 38. Journey’s End, JavaOne, October 2015 Simple Collector – toSet() Stream<Person> Collectors.toSet() Set<Person> people.stream().collect(Collectors.toSet()) bill Collector<Person,?,Set<Person>>
  • 39. Journey’s End, JavaOne, October 2015 Simple Collector – toSet() Stream<Person> Collectors.toSet() Set<Person> people.stream().collect(Collectors.toSet()) bill Collector<Person,?,Set<Person>>
  • 40. Journey’s End, JavaOne, October 2015 Simple Collector – toSet() Stream<Person> Collectors.toSet() Set<Person> people.stream().collect(Collectors.toSet()) bill jon Collector<Person,?,Set<Person>>
  • 41. Journey’s End, JavaOne, October 2015 Simple Collector – toSet() Stream<Person> Collectors.toSet() Set<Person> people.stream().collect(Collectors.toSet()) bill jon Collector<Person,?,Set<Person>>
  • 42. Journey’s End, JavaOne, October 2015 Simple Collector – toSet() Stream<Person> Collectors.toSet() Set<Person> people.stream().collect(Collectors.toSet()) amy bill jon Collector<Person,?,Set<Person>>
  • 43. Journey’s End, JavaOne, October 2015 Simple Collector – toSet() Stream<Person> Collectors.toSet() Set<Person> people.stream().collect(Collectors.toSet()) amy bill jon Collector<Person,?,Set<Person>>
  • 44. Journey’s End, JavaOne, October 2015 Simple Collector – toSet() Collectors.toSet() Set<Person> people.stream().collect(Collectors.toSet()) amy bill jon Collector<Person,?,Set<Person>>
  • 45. Journey’s End, JavaOne, October 2015 Simple Collector – toSet() Collectors.toSet() Set<Person> { , , } people.stream().collect(Collectors.toSet()) amybilljon Collector<Person,?,Set<Person>>
  • 46. Classical Reduction + + + 0 1 2 3 + + + 0 4 5 6 7 0 ++ +
  • 47. Classical Reduction + + + 0 1 2 3 + + + 0 4 5 6 7 0 ++ + intStream.reduce(0,(a,b) -> a+b)
  • 48. Mutable Reduction a a a e0 e1 e2 e3 a a a e4 e5 e6 e7 aa c a: accumulator c: combiner Supplier ()->[] ()->[]
  • 49. Mutable Reduction a a a e0 e1 e2 e3 a a a e4 e5 e6 e7 aa c a: accumulator c: combiner Supplier ()->[] ()->[]
  • 50. Agenda • Define the problem • Implement a solution • Analyse performance – find the bottleneck • Fork/Join parallelism in the real world #java8fairies
  • 51. 122Nor …Moves … 44 grep -b: Collector combiner 0The …[ , 80Shall … ], ,
  • 52. 41 122Nor …Moves … 36 44 grep -b: Collector combiner 0The … 44[ , 42 80Shall … ], ,
  • 53. 41 122Nor …Moves … 36 44 grep -b: Collector combiner 0The … 44[ , 42 80Shall … ] 41 42Nor …Moves … 36 440The … 44[ , 42 0Shall … ] , , ,] [
  • 54. 41 122Nor …Moves … 36 44 grep -b: Collector solution 0The … 44[ , 42 80Shall … ] 41 42Nor …Moves … 36 440The … 44[ , 42 0Shall … ] , , ,] [
  • 55. 41 122Nor …Moves … 36 44 grep -b: Collector solution 0The … 44[ , 42 80Shall … ] 41 42Nor …Moves … 36 440The … 44[ , 42 0Shall … ] , , ,] [ 80
  • 56. 41 122Nor …Moves … 36 44 grep -b: Collector solution 0The … 44[ , 42 80Shall … ] 41 42Nor …Moves … 36 440The … 44[ , 42 0Shall … ] , , ,] [ 80
  • 57. 41 122Nor …Moves … 36 44 grep -b: Collector solution 0The … 44[ , 42 80Shall … ] 41 42Nor …Moves … 36 440The … 44[ , 42 0Shall … ] , , ,] [ 80
  • 58. 41 122Nor …Moves … 36 44 grep -b: Collector combiner 0The … 44[ , 42 80Shall … ] 41 42Nor …Moves … 36 440The … 44[ , 42 0Shall … ] , , ,] [ Moves … 36 0 41 0Nor …42 0Shall …0The … 44[ ]] [[ [] ]
  • 59. grep -b: Collector accumulator 44 0The moving … writ, “Moves on: … Wit” 44 0The moving … writ, 36 44Moves on: … Wit ][ ][ , [ ] Supplier “The moving … writ,” accumulator accumulator
  • 60. Agenda • Define the problem • Implement a solution • Analyse performance – find the bottleneck • Fork/Join parallelism in the real world #java8fairies
  • 61. Because we don’t have a problem? Why Shouldn’t We Optimize Code?
  • 62. Why Shouldn’t We Optimize Code? Because we don’t have a problem - No performance target!
  • 63. Why Shouldn’t We Optimize Code?
  • 64. Because we don’t have a problem - No performance target! Else there is a problem, but not in our process Why Shouldn’t We Optimize Code?
  • 65. Because we don’t have a problem - No performance target! Else there is a problem, but not in our process Why Shouldn’t We Optimize Code? Demo…
  • 66. Because we don’t have a problem - No performance target! Else there is a problem, but not in our process - The OS is struggling! Why Shouldn’t We Optimize Code?
  • 67. Because we don’t have a problem - No performance target! Else there is a problem, but not in our process - The OS is struggling! Else there’s a problem in our process, but not in the code Why Shouldn’t We Optimize Code?
  • 68. Because we don’t have a problem - No performance target! Else there is a problem, but not in our process - The OS is struggling! Else there’s a problem in our process, but not in the code Why Shouldn’t We Optimize Code? Demo…
  • 69. Because we don’t have a problem - No performance target! Else there is a problem, but not in our process - The OS is struggling! Else there’s a problem in our process, but not in the code - GC is using all the cycles! Why Shouldn’t We Optimize Code?
  • 70. Because we don’t have a problem - No performance target! Else there is a problem, but not in our process - The OS is struggling! Else there’s a problem in our process, but not in the code - GC is using all the cycles! Now we can consider the code Else there’s a problem in the code… somewhere - now we can go and profile it
  • 71. Because we don’t have a problem - No performance target! Else there is a problem, but not in our process - The OS is struggling! Else there’s a problem in our process, but not in the code - GC is using all the cycles! Now we can consider the code Else there’s a problem in the code… somewhere - now we can go and profile it Demo…
  • 72. So, streaming IO is slow
  • 73. So, streaming IO is slow If only there was a way of getting all that data into memory…
  • 74. So, streaming IO is slow If only there was a way of getting all that data into memory… Demo…
  • 75. Agenda • Define the problem • Implement a solution • Analyse performance – find the bottleneck • Fork/Join parallelism in the real world #java8fairies
  • 76. Agenda • Define the problem • Implement a solution • Analyse performance – find the bottleneck OR – have a bright idea! • Fork/Join parallelism in the real world #java8fairies
  • 77. Intel Xeon E5 2600 10-core
  • 78. Parallelism – Why? The Free Lunch Is Over http://www.gotw.ca/publications/concurrency-ddj.htm
  • 82. What’s Happened? Physical limitations of the technology: • signal leakage
  • 83. What’s Happened? Physical limitations of the technology: • signal leakage • heat dissipation
  • 84. What’s Happened? Physical limitations of the technology: • signal leakage • heat dissipation • speed of light!
  • 85. What’s Happened? Physical limitations of the technology: • signal leakage • heat dissipation • speed of light! – 30cm = 1 light-nanosecond
  • 86. What’s Happened? Physical limitations of the technology: • signal leakage • heat dissipation • speed of light! – 30cm = 1 light-nanosecond We’re not going to get faster cores,
  • 87. What’s Happened? Physical limitations of the technology: • signal leakage • heat dissipation • speed of light! – 30cm = 1 light-nanosecond We’re not going to get faster cores, we’re going to get more cores!
  • 92. A Parallel Solution for grep -b • Parallel streams need splittable sources • Streaming I/O makes you subject to Amdahl’s Law:
  • 93. A Parallel Solution for grep -b • Parallel streams need splittable sources • Streaming I/O makes you subject to Amdahl’s Law:
  • 94. Blessing – and Curse – on the Transistor
  • 95. Stream Sources for Parallel Processing Implemented by a Spliterator
  • 96. Stream Sources for Parallel Processing Implemented by a Spliterator
  • 97. Stream Sources for Parallel Processing Implemented by a Spliterator
  • 98. Stream Sources for Parallel Processing Implemented by a Spliterator
  • 99. Stream Sources for Parallel Processing Implemented by a Spliterator
  • 100. Stream Sources for Parallel Processing Implemented by a Spliterator
  • 101. Stream Sources for Parallel Processing Implemented by a Spliterator
  • 102. Stream Sources for Parallel Processing Implemented by a Spliterator
  • 103. Stream Sources for Parallel Processing Implemented by a Spliterator
  • 104. Moves …Wit LineSpliterator The moving Finger … writ n Shall … Line Nor all thy … itn n n spliterator coverage
  • 105. Moves …Wit LineSpliterator The moving Finger … writ n Shall … Line Nor all thy … itn n n spliterator coverage MappedByteBuffer
  • 106. Moves …Wit LineSpliterator The moving Finger … writ n Shall … Line Nor all thy … itn n n spliterator coverage MappedByteBuffer mid
  • 107. Moves …Wit LineSpliterator The moving Finger … writ n Shall … Line Nor all thy … itn n n spliterator coverage MappedByteBuffer mid
  • 108. Moves …Wit LineSpliterator The moving Finger … writ n Shall … Line Nor all thy … itn n n spliterator coveragenew spliterator coverage MappedByteBuffer mid
  • 109. Moves …Wit LineSpliterator The moving Finger … writ n Shall … Line Nor all thy … itn n n spliterator coveragenew spliterator coverage MappedByteBuffer mid Demo…
  • 110. Parallelizing grep -b • Splitting action of LineSpliterator is O(log n) • Collector no longer needs to compute index • Result (relatively independent of data size): - sequential stream ~2x as fast as iterative solution - parallel stream >2.5x as fast as sequential stream - on 4 hardware threads
  • 111. Parallelizing Streams Parallel-unfriendly intermediate operations: stateful ones – need to store some or all of the stream data in memory – sorted() those requiring ordering – limit()
  • 112. Collectors Cost Extra! Depends on the performance of accumulator and combiner functions • toList(), toSet(), toCollection() – performance normally dominated by accumulator • but allow for the overhead of managing multithread access to non- threadsafe containers for the combine operation • toMap(), toConcurrentMap() – map merging is slow. Resizing maps, especially concurrent maps, is very expensive. Whenever possible, presize all data structures, maps in particular.
  • 113. Agenda • Define the problem • Implement a solution • Analyse performance – find the bottleneck • Fork/Join parallelism in the real world #java8fairies
  • 114. Simulated Server Environment threadPool.execute(() -> { try { double value = logEntries.parallelStream() .map(applicationStoppedTimePattern::matcher) .filter(Matcher::find) .map( matcher -> matcher.group(2)) .mapToDouble(Double::parseDouble) .summaryStatistics().getSum(); } catch (Exception ex) {} });
  • 115. How Does It Perform? • Total run time: 261.7 seconds • Max: 39.2 secs, Min: 9.2 secs, Median: 22.0 secs
  • 116. Tragedy of the Commons Garrett Hardin, ecologist (1968): Imagine the grazing of animals on a common ground. Each flock owner gains if they add to their own flock. But every animal added to the total degrades the commons a small amount.
  • 117. Tragedy of the Commons
  • 118. Tragedy of the Commons You have a finite amount of hardware – it might be in your best interest to grab it all – but if everyone behaves the same way…
  • 119. Tragedy of the Commons You have a finite amount of hardware – it might be in your best interest to grab it all – but if everyone behaves the same way… Be a good neighbor
  • 120. Tragedy of the Commons You have a finite amount of hardware – it might be in your best interest to grab it all – but if everyone behaves the same way… With many parallelStream() operations running concurrently, performance is limited by the size of the common thread pool and the number of cores you have Be a good neighbor
  • 121. Configuring Common Pool Size of common ForkJoinPool is • Runtime.getRuntime().availableProcessors() - 1 -Djava.util.concurrent.ForkJoinPool.common.parallelism=N -Djava.util.concurrent.ForkJoinPool.common.threadFactory -Djava.util.concurrent.ForkJoinPool.common.exceptionHandler
  • 122. Fork-Join Support for Fork-Join added in Java 7 • difficult coding idiom to master Used internally by parallel streams • uses a spliterator to segment the stream • each stream is processed by a ForkJoinWorkerThread How fork-join works and performs is important to latency
  • 123. ForkJoinPool invoke ForkJoinPool.invoke(ForkJoinTask) uses the submitting thread as a worker • If 100 threads all call invoke(), we would have 100+ForkJoinThreads exhausting the limiting resource, e.g. CPUs, IO, etc.
  • 124. ForkJoinPool submit/get ForkJoinPool.submit(Callable).get() suspends the submitting thread • If 100 threads all call submit(), the work queue can become very long, thus adding latency
  • 125. Fork-Join Performance Fork Join comes with significant overhead • each chunk of work must be large enough to amortize the overhead
  • 126. C/P/N/Q Performance Model C - number of submitters P - number of CPUs N - number of elements Q - cost of the operation
  • 127. When to go Parallel The workload of the intermediate operations must be great enough to outweigh the overheads (~100µs): – initializing the fork/join framework – splitting – concurrent collection Often quoted as N x Q size of data set (typically > 10,000) processing cost per element
  • 128. Kernel Times CPU will not be the limiting factor when • CPU is not saturated • kernel times exceed 10% of user time More threads will decrease performance • predicted by Little’s Law
  • 129. Common Thread Pool Fork-Join by default uses a common thread pool • default number of worker threads == number of logical cores - 1 • Always contains at least one thread Performance is tied to whichever you run out of first • availability of the constraining resource • number of ForkJoinWorkerThreads/hardware threads
  • 130. Everyone is working together to get it done! All Hands on Deck!!!
  • 131. Little’s Law Fork-Join is a work queue • work queue behavior is typically modeled using Little’s Law Number of tasks in a system equals the arrival rate times the amount of time it takes to clear an item Task is submitted every 500ms, or 2 per second Number of tasks = 2/sec * 2.8 seconds = 5.6 tasks
  • 132. Components of Latency Latency is time from stimulus to result • internally, latency consists of active and dead time Reducing dead time assumes you • can find it and are able to fill in with useful work
  • 133. From Previous Example if there is available hardware capacity then make the pool bigger else add capacity or tune to reduce strength of the dependency
  • 134. ForkJoinPool Observability • In an application where you have many parallel stream operations all running concurrently performance will be affected by the size of the common thread pool • too small can starve threads from needed resources • too big can cause threads to thrash on contended resources ForkJoinPool comes with no visibility • no metrics to help us tune • instrument ForkJoinTask.invoke() • gather measures that can be feed into Little’s Law
  • 135. • Collect • service times • time submitted to time returned • inter-arrival times Instrumenting ForkJoinPool public final V invoke() { ForkJoinPool.common.getMonitor().submitTask(this); int s; if ((s = doInvoke() & DONE_MASK) != NORMAL) reportException(s); ForkJoinPool.common.getMonitor().retireTask(this); return getRawResult(); }
  • 136. Performance Submit log parsing to our own ForkJoinPool new ForkJoinPool(16).submit(() -> ……… ).get() new ForkJoinPool(8).submit(() -> ……… ).get() new ForkJoinPool(4).submit(() -> ……… ).get()
  • 139. Performance mostly doesn’t matter But if you must… • sequential streams normally beat iterative solutions • parallel streams can utilize all cores, providing - the data is efficiently splittable - the intermediate operations are sufficiently expensive and are CPU-bound - there isn’t contention for the processors Conclusions #java8fairies