SlideShare une entreprise Scribd logo
1  sur  102
Télécharger pour lire hors ligne
How to fail at benchmarking ?
Pierre Laporte
Performance engineer - Datastax
@pingtimeout
@pingtimeout
Agenda
• Intro
• Why this talk?
• How to fail a benchmark ?
– What to measure ?
– How to measure ?
– "Coordinated Omission" ...?
• Available tools ?
• Mindset ?
• JMH ?
2
Intro
@pingtimeout 4
@pingtimeout 5
Cassandra
• NoSQL Database
• Linear Scalability
• Always On
@pingtimeout 6
Datastax Enterprise (DSE)
• Full featured database platform
• Certified for production
• Enhanced search
• Analytics w/ Hadoop/Spark
• Security
• OpsCenter
@pingtimeout 7
Datastax Enterprise (DSE)
OpsCenter
Why this talk?
@pingtimeout 9
I have not failed.
I have just found 10,000 ways
that won’t work
— Thomas Edison
To learn
Make mistakes
Learn from them
Do *not* blame
@pingtimeout 11
How to fail?
@pingtimeout 13
Example
• User login benchmark (POST /login)
• 100.000 logins
• 1 user
• Measure each login
• Measure from first login
• Perform one (long) run
• On a dev laptop
• Average the results
• CPU utilization => Capacity Planning
@pingtimeout 14
Problem
@pingtimeout 15
Cache
• « 100.000 logins of 1 user »
• CPU caches L1, L2, L3 (and L4)
• TLB cache
• Database cache
• Hibernate cache
• …
@pingtimeout 16
Clock resolution
• « Measure every single login latency »
• login ~> 5ms
• System.currentTimeMillis() ~> 1ms
• ±1 unit <=> ±20%
• System.nanoTime() "provides
nanosecond precision, but not
necessarily nanosecond resolution"
@pingtimeout 17
Warmup
• « Start measuring at first login »
• Class loading
• JVM Warmup time
@pingtimeout 18
Precision
• « Perform one run »
• What if background noise?
• How do we build confidence?
@pingtimeout 19
Environment
• « On a dev laptop » vs. Production
@pingtimeout 20
Metrics
• « Average the results »
@pingtimeout
Capacity Planning
• CPU utilization ≈ 50%
• Remaining Capacity ≈ …?
21
What to measure?
@pingtimeout 23
Average
• Get rid of outliers
• What is the average of a and b ?
• Why do we keep hearing about it ?
• Is it enough ?
@pingtimeout 24
Average
@pingtimeout 25
Useful metrics
• Graphs
• Percentiles
• 90th percentile
• 95th percentile
• 99th percentile
• 99.9th percentile
• …
• Max
@pingtimeout 26
How many 9’s in percentiles ?
• Depend on number of users
• If 500 users, 99th percentile means… ?
@pingtimeout 27
How many 9’s in percentiles ?
• If 1.000.000 users, 99th percentile
means… ?
• 10.000 unlucky folks
@pingtimeout 28
Maximum
• « Meh, probably a timeout, let’s
ignore » — Random dev facing a 60s
response time
• Is that be acceptable…
• For a video game?
• For a real-time application?
• For a mobile application?
@pingtimeout
Benchmark genesis
• A specific question
• Precise requirements
• Ex:
• e-commerce website
• « With my 5 application servers, 20.000
articles in DB and 1.000 simultaneous
clients, will my purchase take 50ms on
average, 100ms once every 10
attempts, and 300ms at worst? »
29
@pingtimeout
Environment
• « With my 5 application servers, 20.000
articles in DB and 1.000 simultaneous clients,
will my purchase take 50ms on average,
100ms once every 10 attempts, and 300ms at
worst? »
• POC:
• TomEE
• Glassfish
• Weblogic
30
@pingtimeout
Load
• « With my 5 application servers, 20.000
articles in DB and 1.000 simultaneous clients,
will my purchase take 50ms on average,
100ms once every 10 attempts, and 300ms at
worst? »
31
@pingtimeout
Requirements
• « With my 5 application servers, 20.000
articles in DB and 1.000 simultaneous clients,
will my purchase take 50ms on average,
100ms once every 10 attempts, and 300ms at
worst? »
32
@pingtimeout
Epilogue
• Answer
• Satisfactory… or not
• Contextual results
• Environment
• Load
• Constraints
• Compromises
33
Statistical truths
@pingtimeout 35
99th percentile on average
• Typical (bad) application in 2012:
• 100 Web Objects/page
• ≈ 100 HTTP requests/page
• Probability of avoiding 99th percentile?
• 0.99n, considering n attempts
• 0.99100 ≈ 36.6%
@pingtimeout 36
99th percentile on average
@pingtimeout 37
Normal distribution
• Client gives those latency numbers
• Average = 100 ms
• Std dev = 20 ms
• Median = 120 ms
• Max = 1 s
• What is the 99th percentile ?
We don’t know.
@pingtimeout 39
Anscombe’s quartet
@pingtimeout 40
Normal distribution ?!
• Latency never follows a normal
distribution
• Dropwizard metrics :
@pingtimeout 41
• Use HdrHistogram
• Arbitrary range
• Precision
• Constant memory footprint
• http://hdrhistogram.github.io/
HdrHistogram/
Normal distribution ?!
@pingtimeout 42
HdrHistogram graph'd
Puzzlers
@pingtimeout 44
Puzzler
• Any issue?
boolean isCustomer(Integer id) {
for (Integer cid : customers)
if (cid == id)
return true;
return false;
}
@pingtimeout 45
Puzzler (complete)
import java.util.*;
public class Fixnum {
private List<Integer> customers;
public Fixnum() {
customers = new ArrayList<Integer>();
for(int i=0 ; i<50_000 ; i++)
customers.add((Integer) i);
}
boolean isCustomer(Integer id) {
for (Integer cid : customers)
if (cid == id)
return true;
return false;
}
public static void main(String... args) {
Fixnum f = new Fixnum();
for(int i=0 ; i<Integer.valueOf(args[0]) ; i++)
if(!f.isCustomer(i))
System.out.println("Failed for i=" + i);
}
}
@pingtimeout 46
Puzzler (oh shit…)
$ java Fixnum 10
$ java Fixnum 50
$ java Fixnum 100
$ java Fixnum 128
$ java Fixnum 129
Failed for i=128
$
@pingtimeout 47
Puzzler (run 2)
• Anyone knows -XX:+AggressiveOpts ?
• What is going to happen ?
• … What does it do ?
@pingtimeout 48
Puzzler (oh shit…)
$ java -XX:+AggressiveOpts Fixnum 129
$ java -XX:+AggressiveOpts Fixnum 300
$ java -XX:+AggressiveOpts Fixnum 500
$ java -XX:+AggressiveOpts Fixnum 1000
$
@pingtimeout 49
Aggressive Opts
• Increase fixnum pool from 128 to … ?
• How much left as an exercise
• Hint: set_aggressive_opts_flags() in
arguments.cpp
• That’s pretty much it.
@pingtimeout 50
Puzzler 2
• What does

this code do ?
public class Haddock {
public static void main(String [] args) {
new Haddock().first();
}
void first() {
for(int i=0; i<1_000; i++)
second();
}
void second() {
for(int i=0; i<1_000_000; i++)
third();
}
void third() {
for(int i=0; i<1_000; i++)
new Sabord();
}
static class Sabord {}
}
@pingtimeout 51
Puzzler 2
• What does

this code do ?
1. It swears
2. It does not do

what we think
3. It measures
Hotspot
4. It creates ~10k
objects
public class Haddock {
public static void main(String [] args) {
new Haddock().first();
}
void first() {
for(int i=0; i<1_000; i++)
second();
}
void second() {
for(int i=0; i<1_000_000; i++)
third();
}
void third() {
for(int i=0; i<1_000; i++)
new Sabord();
}
static class Sabord {}
}
@pingtimeout 52
Puzzler 2
• All of the above

(below)
1. It swears
2. It does not do

what we think
3. It measures
Hotspot
4. It creates ~10k
objects
public class Haddock {
public static void main(String [] args) {
new Haddock().first();
}
void first() {
for(int i=0; i<1_000; i++)
second();
}
void second() {
for(int i=0; i<1_000_000; i++)
third();
}
void third() {
for(int i=0; i<1_000; i++)
new Sabord();
}
static class Sabord {}
}
@pingtimeout 53
It swears
@pingtimeout 54
Puzzler 2 - Run
$ time java Haddock
real 0m0.169s
user 0m0.110s
sys 0m0.055s
Test @3.5 GHz
@pingtimeout 55
It does not do what we think
public class Haddock {
public static void main(String [] args) {
new Haddock().first();
}
void first() {
for(int i=0; i<1_000; i++)
second();
}
void second() {
for(int i=0; i<1_000_000; i++)
third();
}
void third() {
for(int i=0; i<1_000; i++)
new Sabord();
}
static class Sabord {}
}
@pingtimeout 56
It does not do what we think
public class Haddock {
public static void main(String [] args) {
new Haddock().first();
}
void first() {
for(int i=0; i<1_000; i++)
second();
}
void second() {
for(int i=0; i<1_000_000; i++)
third();
}
void third() {
for(int i=0; i<1_000; i++)
;
}
static class Sabord {}
}
@pingtimeout 57
It does not do what we think
public class Haddock {
public static void main(String [] args) {
new Haddock().first();
}
void first() {
for(int i=0; i<1_000; i++)
second();
}
void second() {
for(int i=0; i<1_000_000; i++)
third();
}
void third() {
}
static class Sabord {}
}
@pingtimeout 58
It does not do what we think
public class Haddock {
public static void main(String [] args) {
new Haddock().first();
}
void first() {
for(int i=0; i<1_000; i++)
second();
}
void second() {
for(int i=0; i<1_000_000; i++)
;
}
static class Sabord {}
}
@pingtimeout 59
It does not do what we think
public class Haddock {
public static void main(String [] args) {
new Haddock().first();
}
void first() {
for(int i=0; i<1_000; i++)
;
}
static class Sabord {}
}
@pingtimeout 60
It does not do what we think
public class Haddock {
public static void main(String [] args) {
new Haddock().first();
}
void first() {
}
static class Sabord {}
}
@pingtimeout 61
Puzzler 2
• After ~10k iterations, code is DCE'd
public class Haddock {
public static void main(String [] args) {}
void first() {}
void second() {}
void third() {}
static class Sabord {}
}
Coordinated Omission
@pingtimeout 63
Java 8 Enterprise REST API
public class Server {
public static void main(String[] args) {
new WebServer().configure(
routes -> routes.get("/", Server::sayHello)
).start();
}
private static String sayHello() {
try {
Thread.sleep(10);
} catch (InterruptedException e) {
throw new IllegalStateException(e);
}
return "Hello World";
}
}
@pingtimeout 64
CO client
public class Client {
public static void main(String[] args) throws Exception {
ArrayList<Long> latencies = new ArrayList<>(100);
HttpGet get = new HttpGet("http://localhost:8080/");
try (CloseableHttpClient client = HttpClients.createDefault()) {
// First execution to load the classes
execute(client, get);
for (int i = 0 ; i < 100 ; i++) {
long requestSendTime = System.currentTimeMillis();
execute(client, get);
long requestTime = System.currentTimeMillis() - requestSendTime;
latencies.add(requestTime);
SECONDS.sleep(1);
}
}
Collections.sort(latencies);
System.out.println("Number of points : " + latencies.size());
System.out.println("Average : " + average(latencies));
System.out.println("80% : " + percentile(latencies, 0.8));
System.out.println("90% : " + percentile(latencies, 0.9));
System.out.println("95% : " + percentile(latencies, 0.9));
System.out.println("99% : " + percentile(latencies, 0.99));
System.out.println("Max : " + percentile(latencies, 1));
}
}
@pingtimeout 65
STW Runner
• Simulate lonnnng GC pause
• or any other lonnnng blocking task
• ^Z
echo "# Freezing server during 11 seconds..."
kill -STOP $server_pid
sleep 11
echo "# Unfreezing server..."
kill -CONT $server_pid
sleep 40
@pingtimeout 66
Expectations - Timeline
SIGSTOP
SIGCONT
@pingtimeout
Pre-run check
• Throughput = 1 req/s
• Total duration = 100 s
• Longest pause = 11 s
• Typical response time ≈ 10 ms
67
@pingtimeout 68
Expectations - Throughput
@pingtimeout 69
Expectations - Latency
@pingtimeout
Expectations - Maths
• Expected percentiles
• Max ∈ ]10; 11]
• 99% ∈ ]9; 10]
• 98% ∈ ]8; 9]
• 95% ∈ ]5; 6]
• 90% ∈ ]0; 1]
70
@pingtimeout 71
Reality
Wait… What?
@pingtimeout 72
Reality
@pingtimeout 73
Why?
public class Client {
public static void main(String[] args) throws Exception {
ArrayList<Long> latencies = new ArrayList<>(100);
HttpGet get = new HttpGet("http://localhost:8080/");
try (CloseableHttpClient client = HttpClients.createDefault()) {
// First execution to load the classes
execute(client, get);
for (int i = 0 ; i < 100 ; i++) {
long requestSendTime = System.currentTimeMillis();
execute(client, get);
long requestTime = System.currentTimeMillis() - requestSendTime;
latencies.add(requestTime);
SECONDS.sleep(1);
}
}
Collections.sort(latencies);
System.out.println("Number of points : " + latencies.size());
System.out.println("Average : " + average(latencies));
System.out.println("80% : " + percentile(latencies, 0.8));
System.out.println("90% : " + percentile(latencies, 0.9));
System.out.println("95% : " + percentile(latencies, 0.9));
System.out.println("99% : " + percentile(latencies, 0.99));
System.out.println("Max : " + percentile(latencies, 1));
}
@pingtimeout 74
Reality - Throughput
100s
100th data point
@pingtimeout 75
Reality - Throughput
100s
100th data point
@pingtimeout 76
What is CO ?
• Interval between samples : x
• Usual measurements << x
• Outliers > x
• Subsequent measurements delayed
• After the bad period
@pingtimeout 77
What is measured ?
• Service Time's 99th percentile
• ≠ Response Time's 99th percentile
@pingtimeout 78
Is it common ?
I rarely see load testers that
don't suffer from it, including
common testers used in the
industry (JMeter, Grinder, HP
LoadRunner) and benchmarks
(YCSB, SPECeverything, etc.)
— Gil Tene
@pingtimeout
Test the tester
• Mandatory step
• Replace SUT by noop
• Response time = 0
• ^Z Test
• Check hypothesis
79
@pingtimeout 80
How to fix it ? 1/2
• Know your theoretical send time
• Use it as the start time
• Delayed requests will show the issue
long requestSendTime = expectedSendTimeOfSample(n);
execute(client, get);
long requestTime = System.currentTimeMillis() - requestSendTime;
@pingtimeout 81
How to fix it ? 2/2
• Interval between samples
• Use HdrHistogram
• http://giltene.github.io/HdrHistogram/
• class Histogram
• copyCorrectedForCoordinatedOmission(…)
• recordValueWithExpectedInterval(…)
Java Microbenchmark Harness
@pingtimeout 83
JMH
• Written by Oracle Perf Eng Team
• @shipilev leading
• Code generator
• Multi options runner (# threads, groups,
iterations, …)
• Pluggable profiles
• Multi language
• …
@pingtimeout 84
Power == Responsibility
@pingtimeout 85
JMH Samples
• Code = documentation
• Run the doc
• Learn
@pingtimeout 86
DCE
@BenchmarkMode(Mode.Throughput)
@OutputTimeUnit(TimeUnit.MICROSECONDS)
public class DCE {
@Benchmark
public void baseline() {
}
@Benchmark
public void measureWrong() {
Math.log(Math.PI);
}
@Benchmark
public double measureRight() {
return Math.log(Math.PI);
}
}
@pingtimeout 87
DCE
Benchmark Samples Score Error Units
f.p.b.DCE.baseline 5 3776,469 ± 14,079 ops/us
f.p.b.DCE.measureRight 5 503,629 ± 10,431 ops/us
f.p.b.DCE.measureWrong 5 3714,931 ± 172,927 ops/us
@pingtimeout 88
CPU arithmetic
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
public class CPU {
long a;
long b;
// [...]
@Benchmark
public long addition() { return a+b; }
@Benchmark
public long subtraction() { return a-b; }
@Benchmark
public long multiplication() { return a*b; }
@Benchmark
public long division() { return a/b; }
}
@pingtimeout 89
CPU arithmetic
Benchmark Samples Score Error Units
f.p.b.CPU.addition 5 2,058 ± 0,034 ns/op
f.p.b.CPU.subtraction 5 2,070 ± 0,031 ns/op
f.p.b.CPU.multiplication 5 2,087 ± 0,016 ns/op
f.p.b.CPU.division 5 9,931 ± 0,218 ns/op
@pingtimeout 90
Locks
public class Locks {
@State(Scope.Benchmark)
public static class BenchmarkParameters {
@Param({"1"})
public int burnCpuFactor;
}
@State(Scope.Group)
public static class BaselineState {
private int value = 0;
}
@State(Scope.Group)
public static class SynchronizedState {
private final Object lock = new Object();
private int value = 0;
}
@State(Scope.Group)
public static class ReentrantRWLState {
private final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
private int value = 0;
}
@pingtimeout 91
Locks
@Benchmark
@Group("baseline")
public void updateBaseline(BaselineState s, BenchmarkParameters p) {
Blackhole.consumeCPU(p.burnCpuFactor);
s.value++;
}
@Benchmark
@Group("baseline")
public int readBaseline(BaselineState s, BenchmarkParameters p) {
Blackhole.consumeCPU(p.burnCpuFactor);
return s.value;
}
@pingtimeout
@Benchmark
@Group("synchronized")
public void updateSynchronized(SynchronizedState s, BenchmarkParameters p) {
synchronized (s.lock) {
Blackhole.consumeCPU(p.burnCpuFactor);
s.value++;
}
}
@Benchmark
@Group("synchronized")
public int readSynchronized(SynchronizedState s, BenchmarkParameters p) {
synchronized (s.lock) {
Blackhole.consumeCPU(p.burnCpuFactor);
return s.value;
}
}
92
Locks
@pingtimeout
@Benchmark
@Group("rrwl")
public void updateRrwl(ReentrantRWLState s, BenchmarkParameters p) {
s.lock.writeLock().lock();
try {
Blackhole.consumeCPU(p.burnCpuFactor);
s.value++;
} finally {
s.lock.writeLock().unlock();
}
}
@Benchmark
@Group("rrwl")
public int readRrwl(ReentrantRWLState s, BenchmarkParameters p) {
s.lock.readLock().lock();
try {
Blackhole.consumeCPU(p.burnCpuFactor);
return s.value;
} finally {
s.lock.readLock().unlock();
}
}
93
Locks
@pingtimeout 94
Locks
# 1 reader, 1 writer, burnCpuFactor=1
Benchmark Samples Score Error Units
f.p.b.Locks.readBaseline 20 48632,823 ±1549,042 ops/ms
f.p.b.Locks.updateBaseline 20 232492,376 ±12527,203 ops/ms
f.p.b.Locks.readSynchronized 20 2384,911 ±162,020 ops/ms
f.p.b.Locks.updateSynchronized 20 9295,519 ±1017,941 ops/ms
f.p.b.Locks.readSynchronized 20 13133,933 ±164,549 ops/ms
f.p.b.Locks.updateSynchronized 20 13701,232 ±357,065 ops/ms
@pingtimeout 95
Locks
# 1 reader, 1 writer, burnCpuFactor=10
Benchmark Samples Score Error Units
f.p.b.Locks.readBaseline 20 22573,454 ±158,246 ops/ms
f.p.b.Locks.updateBaseline 20 82398,369 ±1429,225 ops/ms
f.p.b.Locks.readSynchronized 20 2176,295 ±232,285 ops/ms
f.p.b.Locks.updateSynchronized 20 9236,524 ±1575,705 ops/ms
f.p.b.Locks.readSynchronized 20 8716,035 ±551,503 ops/ms
f.p.b.Locks.updateSynchronized 20 13970,326 ±1500,214 ops/ms
@pingtimeout 96
Locks
# 1 reader, 1 writer, burnCpuFactor=50
Benchmark Samples Score Error Units
f.p.b.Locks.readBaseline 20 11312,319 ±209,768 ops/ms
f.p.b.Locks.updateBaseline 20 11566,514 ±194,376 ops/ms
f.p.b.Locks.readSynchronized 20 998,879 ±156,620 ops/ms
f.p.b.Locks.updateSynchronized 20 3369,257 ±168,350 ops/ms
f.p.b.Locks.readSynchronized 20 3007,162 ±122,303 ops/ms
f.p.b.Locks.updateSynchronized 20 3068,433 ±99,109 ops/ms
@pingtimeout 97
Locks
# 1 reader, 3 writers, burnCpuFactor=10
Benchmark Samples Score Error Units
f.p.b.Locks.readBaseline 20 15215,388 ±229,017 ops/ms
f.p.b.Locks.updateBaseline 20 146910,990 ±1762,371 ops/ms
f.p.b.Locks.readRrwl 20 76,190 ±3,637 ops/ms
f.p.b.Locks.updateRrwl 20 30327,966 ±674,847 ops/ms
f.p.b.Locks.readSynchronized 20 3989,755 ±219,982 ops/ms
f.p.b.Locks.updateSynchronized 20 15769,990 ±116,859 ops/ms
Summary
@pingtimeout 99
The successful man will profit
from his mistakes and try again
in a different way
— Dale Carnegie
@pingtimeout
Contextual results
100
@pingtimeout 101
Sources
• https://groups.google.com/d/msg/mechanical-sympathy/
• http://psy-lob-saw.blogspot.fr/
• http://latencytipoftheday.blogspot.fr/
• http://www.websiteoptimization.com/speed/tweak/
average-number-web-objects/
• Hotspot source code
• @kcpeppe, @giltene, @shipilev
• @pingtimeout ;-)
@pingtimeout
Thank you for your attention!
• Q&A ?
102

Contenu connexe

En vedette

En vedette (7)

School
SchoolSchool
School
 
Randoms
RandomsRandoms
Randoms
 
La BDD, l'enfant gâté des SI
La BDD, l'enfant gâté des SILa BDD, l'enfant gâté des SI
La BDD, l'enfant gâté des SI
 
PROJECT
PROJECTPROJECT
PROJECT
 
Building a lock profiler on the JVM
Building a lock profiler on the JVMBuilding a lock profiler on the JVM
Building a lock profiler on the JVM
 
Devoxx BE - How to fail at benchmarking
Devoxx BE - How to fail at benchmarkingDevoxx BE - How to fail at benchmarking
Devoxx BE - How to fail at benchmarking
 
Pimp my gc - Supersonic Scala
Pimp my gc - Supersonic ScalaPimp my gc - Supersonic Scala
Pimp my gc - Supersonic Scala
 

Similaire à Lyon jug-how-to-fail-at-benchmarking

Testing: ¿what, how, why?
Testing: ¿what, how, why?Testing: ¿what, how, why?
Testing: ¿what, how, why?David Rodenas
 
Where the wild things are - Benchmarking and Micro-Optimisations
Where the wild things are - Benchmarking and Micro-OptimisationsWhere the wild things are - Benchmarking and Micro-Optimisations
Where the wild things are - Benchmarking and Micro-OptimisationsMatt Warren
 
Quantum programming in a nutshell Radu Vunvulea ITCamp 2018
Quantum programming in a nutshell Radu Vunvulea  ITCamp 2018Quantum programming in a nutshell Radu Vunvulea  ITCamp 2018
Quantum programming in a nutshell Radu Vunvulea ITCamp 2018Radu Vunvulea
 
"Practical Machine Learning With Ruby" by Iqbal Farabi (ID Ruby Community)
"Practical Machine Learning With Ruby" by Iqbal Farabi (ID Ruby Community)"Practical Machine Learning With Ruby" by Iqbal Farabi (ID Ruby Community)
"Practical Machine Learning With Ruby" by Iqbal Farabi (ID Ruby Community)Tech in Asia ID
 
Data Platform at Twitter: Enabling Real-time & Batch Analytics at Scale
Data Platform at Twitter: Enabling Real-time & Batch Analytics at ScaleData Platform at Twitter: Enabling Real-time & Batch Analytics at Scale
Data Platform at Twitter: Enabling Real-time & Batch Analytics at ScaleSriram Krishnan
 
Les race conditions, nos très chères amies
Les race conditions, nos très chères amiesLes race conditions, nos très chères amies
Les race conditions, nos très chères amiesPierre Laporte
 
MySQL Performance Monitoring
MySQL Performance MonitoringMySQL Performance Monitoring
MySQL Performance Monitoringspil-engineering
 
Java Performance Mistakes
Java Performance MistakesJava Performance Mistakes
Java Performance MistakesAndreas Grabner
 
What’s eating python performance
What’s eating python performanceWhat’s eating python performance
What’s eating python performancePiotr Przymus
 
Programming exercises
Programming exercisesProgramming exercises
Programming exercisesTerry Yin
 
5 must have patterns for your microservice - techorama
5 must have patterns for your microservice - techorama5 must have patterns for your microservice - techorama
5 must have patterns for your microservice - techoramaAli Kheyrollahi
 
"Quantum" performance effects
"Quantum" performance effects"Quantum" performance effects
"Quantum" performance effectsSergey Kuksenko
 
13multithreaded Programming
13multithreaded Programming13multithreaded Programming
13multithreaded ProgrammingAdil Jafri
 
How do software engineers understand code changes?
How do software engineers understand code changes?How do software engineers understand code changes?
How do software engineers understand code changes?Yida Tao
 
Basic Multiplayer Online Game with Node.js & dgt-net
Basic Multiplayer Online Game with Node.js & dgt-netBasic Multiplayer Online Game with Node.js & dgt-net
Basic Multiplayer Online Game with Node.js & dgt-netPisit Tangkoblarp
 
C* Summit 2013: Real-time Analytics using Cassandra, Spark and Shark by Evan ...
C* Summit 2013: Real-time Analytics using Cassandra, Spark and Shark by Evan ...C* Summit 2013: Real-time Analytics using Cassandra, Spark and Shark by Evan ...
C* Summit 2013: Real-time Analytics using Cassandra, Spark and Shark by Evan ...DataStax Academy
 
Static analysis works for mission-critical systems, why not yours?
Static analysis works for mission-critical systems, why not yours? Static analysis works for mission-critical systems, why not yours?
Static analysis works for mission-critical systems, why not yours? Rogue Wave Software
 
Monitoring Complex Systems: Keeping Your Head on Straight in a Hard World
Monitoring Complex Systems: Keeping Your Head on Straight in a Hard WorldMonitoring Complex Systems: Keeping Your Head on Straight in a Hard World
Monitoring Complex Systems: Keeping Your Head on Straight in a Hard WorldBrian Troutwine
 
Testing, Learning and Professionalism — 20171214
Testing, Learning and Professionalism — 20171214Testing, Learning and Professionalism — 20171214
Testing, Learning and Professionalism — 20171214David Rodenas
 

Similaire à Lyon jug-how-to-fail-at-benchmarking (20)

Type Casting Operator
Type Casting OperatorType Casting Operator
Type Casting Operator
 
Testing: ¿what, how, why?
Testing: ¿what, how, why?Testing: ¿what, how, why?
Testing: ¿what, how, why?
 
Where the wild things are - Benchmarking and Micro-Optimisations
Where the wild things are - Benchmarking and Micro-OptimisationsWhere the wild things are - Benchmarking and Micro-Optimisations
Where the wild things are - Benchmarking and Micro-Optimisations
 
Quantum programming in a nutshell Radu Vunvulea ITCamp 2018
Quantum programming in a nutshell Radu Vunvulea  ITCamp 2018Quantum programming in a nutshell Radu Vunvulea  ITCamp 2018
Quantum programming in a nutshell Radu Vunvulea ITCamp 2018
 
"Practical Machine Learning With Ruby" by Iqbal Farabi (ID Ruby Community)
"Practical Machine Learning With Ruby" by Iqbal Farabi (ID Ruby Community)"Practical Machine Learning With Ruby" by Iqbal Farabi (ID Ruby Community)
"Practical Machine Learning With Ruby" by Iqbal Farabi (ID Ruby Community)
 
Data Platform at Twitter: Enabling Real-time & Batch Analytics at Scale
Data Platform at Twitter: Enabling Real-time & Batch Analytics at ScaleData Platform at Twitter: Enabling Real-time & Batch Analytics at Scale
Data Platform at Twitter: Enabling Real-time & Batch Analytics at Scale
 
Les race conditions, nos très chères amies
Les race conditions, nos très chères amiesLes race conditions, nos très chères amies
Les race conditions, nos très chères amies
 
MySQL Performance Monitoring
MySQL Performance MonitoringMySQL Performance Monitoring
MySQL Performance Monitoring
 
Java Performance Mistakes
Java Performance MistakesJava Performance Mistakes
Java Performance Mistakes
 
What’s eating python performance
What’s eating python performanceWhat’s eating python performance
What’s eating python performance
 
Programming exercises
Programming exercisesProgramming exercises
Programming exercises
 
5 must have patterns for your microservice - techorama
5 must have patterns for your microservice - techorama5 must have patterns for your microservice - techorama
5 must have patterns for your microservice - techorama
 
"Quantum" performance effects
"Quantum" performance effects"Quantum" performance effects
"Quantum" performance effects
 
13multithreaded Programming
13multithreaded Programming13multithreaded Programming
13multithreaded Programming
 
How do software engineers understand code changes?
How do software engineers understand code changes?How do software engineers understand code changes?
How do software engineers understand code changes?
 
Basic Multiplayer Online Game with Node.js & dgt-net
Basic Multiplayer Online Game with Node.js & dgt-netBasic Multiplayer Online Game with Node.js & dgt-net
Basic Multiplayer Online Game with Node.js & dgt-net
 
C* Summit 2013: Real-time Analytics using Cassandra, Spark and Shark by Evan ...
C* Summit 2013: Real-time Analytics using Cassandra, Spark and Shark by Evan ...C* Summit 2013: Real-time Analytics using Cassandra, Spark and Shark by Evan ...
C* Summit 2013: Real-time Analytics using Cassandra, Spark and Shark by Evan ...
 
Static analysis works for mission-critical systems, why not yours?
Static analysis works for mission-critical systems, why not yours? Static analysis works for mission-critical systems, why not yours?
Static analysis works for mission-critical systems, why not yours?
 
Monitoring Complex Systems: Keeping Your Head on Straight in a Hard World
Monitoring Complex Systems: Keeping Your Head on Straight in a Hard WorldMonitoring Complex Systems: Keeping Your Head on Straight in a Hard World
Monitoring Complex Systems: Keeping Your Head on Straight in a Hard World
 
Testing, Learning and Professionalism — 20171214
Testing, Learning and Professionalism — 20171214Testing, Learning and Professionalism — 20171214
Testing, Learning and Professionalism — 20171214
 

Dernier

The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 

Dernier (20)

The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 

Lyon jug-how-to-fail-at-benchmarking

  • 1. How to fail at benchmarking ? Pierre Laporte Performance engineer - Datastax @pingtimeout
  • 2. @pingtimeout Agenda • Intro • Why this talk? • How to fail a benchmark ? – What to measure ? – How to measure ? – "Coordinated Omission" ...? • Available tools ? • Mindset ? • JMH ? 2
  • 5. @pingtimeout 5 Cassandra • NoSQL Database • Linear Scalability • Always On
  • 6. @pingtimeout 6 Datastax Enterprise (DSE) • Full featured database platform • Certified for production • Enhanced search • Analytics w/ Hadoop/Spark • Security • OpsCenter
  • 9. @pingtimeout 9 I have not failed. I have just found 10,000 ways that won’t work — Thomas Edison
  • 10. To learn Make mistakes Learn from them Do *not* blame
  • 13. @pingtimeout 13 Example • User login benchmark (POST /login) • 100.000 logins • 1 user • Measure each login • Measure from first login • Perform one (long) run • On a dev laptop • Average the results • CPU utilization => Capacity Planning
  • 15. @pingtimeout 15 Cache • « 100.000 logins of 1 user » • CPU caches L1, L2, L3 (and L4) • TLB cache • Database cache • Hibernate cache • …
  • 16. @pingtimeout 16 Clock resolution • « Measure every single login latency » • login ~> 5ms • System.currentTimeMillis() ~> 1ms • ±1 unit <=> ±20% • System.nanoTime() "provides nanosecond precision, but not necessarily nanosecond resolution"
  • 17. @pingtimeout 17 Warmup • « Start measuring at first login » • Class loading • JVM Warmup time
  • 18. @pingtimeout 18 Precision • « Perform one run » • What if background noise? • How do we build confidence?
  • 19. @pingtimeout 19 Environment • « On a dev laptop » vs. Production
  • 20. @pingtimeout 20 Metrics • « Average the results »
  • 21. @pingtimeout Capacity Planning • CPU utilization ≈ 50% • Remaining Capacity ≈ …? 21
  • 23. @pingtimeout 23 Average • Get rid of outliers • What is the average of a and b ? • Why do we keep hearing about it ? • Is it enough ?
  • 25. @pingtimeout 25 Useful metrics • Graphs • Percentiles • 90th percentile • 95th percentile • 99th percentile • 99.9th percentile • … • Max
  • 26. @pingtimeout 26 How many 9’s in percentiles ? • Depend on number of users • If 500 users, 99th percentile means… ?
  • 27. @pingtimeout 27 How many 9’s in percentiles ? • If 1.000.000 users, 99th percentile means… ? • 10.000 unlucky folks
  • 28. @pingtimeout 28 Maximum • « Meh, probably a timeout, let’s ignore » — Random dev facing a 60s response time • Is that be acceptable… • For a video game? • For a real-time application? • For a mobile application?
  • 29. @pingtimeout Benchmark genesis • A specific question • Precise requirements • Ex: • e-commerce website • « With my 5 application servers, 20.000 articles in DB and 1.000 simultaneous clients, will my purchase take 50ms on average, 100ms once every 10 attempts, and 300ms at worst? » 29
  • 30. @pingtimeout Environment • « With my 5 application servers, 20.000 articles in DB and 1.000 simultaneous clients, will my purchase take 50ms on average, 100ms once every 10 attempts, and 300ms at worst? » • POC: • TomEE • Glassfish • Weblogic 30
  • 31. @pingtimeout Load • « With my 5 application servers, 20.000 articles in DB and 1.000 simultaneous clients, will my purchase take 50ms on average, 100ms once every 10 attempts, and 300ms at worst? » 31
  • 32. @pingtimeout Requirements • « With my 5 application servers, 20.000 articles in DB and 1.000 simultaneous clients, will my purchase take 50ms on average, 100ms once every 10 attempts, and 300ms at worst? » 32
  • 33. @pingtimeout Epilogue • Answer • Satisfactory… or not • Contextual results • Environment • Load • Constraints • Compromises 33
  • 35. @pingtimeout 35 99th percentile on average • Typical (bad) application in 2012: • 100 Web Objects/page • ≈ 100 HTTP requests/page • Probability of avoiding 99th percentile? • 0.99n, considering n attempts • 0.99100 ≈ 36.6%
  • 37. @pingtimeout 37 Normal distribution • Client gives those latency numbers • Average = 100 ms • Std dev = 20 ms • Median = 120 ms • Max = 1 s • What is the 99th percentile ?
  • 40. @pingtimeout 40 Normal distribution ?! • Latency never follows a normal distribution • Dropwizard metrics :
  • 41. @pingtimeout 41 • Use HdrHistogram • Arbitrary range • Precision • Constant memory footprint • http://hdrhistogram.github.io/ HdrHistogram/ Normal distribution ?!
  • 44. @pingtimeout 44 Puzzler • Any issue? boolean isCustomer(Integer id) { for (Integer cid : customers) if (cid == id) return true; return false; }
  • 45. @pingtimeout 45 Puzzler (complete) import java.util.*; public class Fixnum { private List<Integer> customers; public Fixnum() { customers = new ArrayList<Integer>(); for(int i=0 ; i<50_000 ; i++) customers.add((Integer) i); } boolean isCustomer(Integer id) { for (Integer cid : customers) if (cid == id) return true; return false; } public static void main(String... args) { Fixnum f = new Fixnum(); for(int i=0 ; i<Integer.valueOf(args[0]) ; i++) if(!f.isCustomer(i)) System.out.println("Failed for i=" + i); } }
  • 46. @pingtimeout 46 Puzzler (oh shit…) $ java Fixnum 10 $ java Fixnum 50 $ java Fixnum 100 $ java Fixnum 128 $ java Fixnum 129 Failed for i=128 $
  • 47. @pingtimeout 47 Puzzler (run 2) • Anyone knows -XX:+AggressiveOpts ? • What is going to happen ? • … What does it do ?
  • 48. @pingtimeout 48 Puzzler (oh shit…) $ java -XX:+AggressiveOpts Fixnum 129 $ java -XX:+AggressiveOpts Fixnum 300 $ java -XX:+AggressiveOpts Fixnum 500 $ java -XX:+AggressiveOpts Fixnum 1000 $
  • 49. @pingtimeout 49 Aggressive Opts • Increase fixnum pool from 128 to … ? • How much left as an exercise • Hint: set_aggressive_opts_flags() in arguments.cpp • That’s pretty much it.
  • 50. @pingtimeout 50 Puzzler 2 • What does
 this code do ? public class Haddock { public static void main(String [] args) { new Haddock().first(); } void first() { for(int i=0; i<1_000; i++) second(); } void second() { for(int i=0; i<1_000_000; i++) third(); } void third() { for(int i=0; i<1_000; i++) new Sabord(); } static class Sabord {} }
  • 51. @pingtimeout 51 Puzzler 2 • What does
 this code do ? 1. It swears 2. It does not do
 what we think 3. It measures Hotspot 4. It creates ~10k objects public class Haddock { public static void main(String [] args) { new Haddock().first(); } void first() { for(int i=0; i<1_000; i++) second(); } void second() { for(int i=0; i<1_000_000; i++) third(); } void third() { for(int i=0; i<1_000; i++) new Sabord(); } static class Sabord {} }
  • 52. @pingtimeout 52 Puzzler 2 • All of the above
 (below) 1. It swears 2. It does not do
 what we think 3. It measures Hotspot 4. It creates ~10k objects public class Haddock { public static void main(String [] args) { new Haddock().first(); } void first() { for(int i=0; i<1_000; i++) second(); } void second() { for(int i=0; i<1_000_000; i++) third(); } void third() { for(int i=0; i<1_000; i++) new Sabord(); } static class Sabord {} }
  • 54. @pingtimeout 54 Puzzler 2 - Run $ time java Haddock real 0m0.169s user 0m0.110s sys 0m0.055s Test @3.5 GHz
  • 55. @pingtimeout 55 It does not do what we think public class Haddock { public static void main(String [] args) { new Haddock().first(); } void first() { for(int i=0; i<1_000; i++) second(); } void second() { for(int i=0; i<1_000_000; i++) third(); } void third() { for(int i=0; i<1_000; i++) new Sabord(); } static class Sabord {} }
  • 56. @pingtimeout 56 It does not do what we think public class Haddock { public static void main(String [] args) { new Haddock().first(); } void first() { for(int i=0; i<1_000; i++) second(); } void second() { for(int i=0; i<1_000_000; i++) third(); } void third() { for(int i=0; i<1_000; i++) ; } static class Sabord {} }
  • 57. @pingtimeout 57 It does not do what we think public class Haddock { public static void main(String [] args) { new Haddock().first(); } void first() { for(int i=0; i<1_000; i++) second(); } void second() { for(int i=0; i<1_000_000; i++) third(); } void third() { } static class Sabord {} }
  • 58. @pingtimeout 58 It does not do what we think public class Haddock { public static void main(String [] args) { new Haddock().first(); } void first() { for(int i=0; i<1_000; i++) second(); } void second() { for(int i=0; i<1_000_000; i++) ; } static class Sabord {} }
  • 59. @pingtimeout 59 It does not do what we think public class Haddock { public static void main(String [] args) { new Haddock().first(); } void first() { for(int i=0; i<1_000; i++) ; } static class Sabord {} }
  • 60. @pingtimeout 60 It does not do what we think public class Haddock { public static void main(String [] args) { new Haddock().first(); } void first() { } static class Sabord {} }
  • 61. @pingtimeout 61 Puzzler 2 • After ~10k iterations, code is DCE'd public class Haddock { public static void main(String [] args) {} void first() {} void second() {} void third() {} static class Sabord {} }
  • 63. @pingtimeout 63 Java 8 Enterprise REST API public class Server { public static void main(String[] args) { new WebServer().configure( routes -> routes.get("/", Server::sayHello) ).start(); } private static String sayHello() { try { Thread.sleep(10); } catch (InterruptedException e) { throw new IllegalStateException(e); } return "Hello World"; } }
  • 64. @pingtimeout 64 CO client public class Client { public static void main(String[] args) throws Exception { ArrayList<Long> latencies = new ArrayList<>(100); HttpGet get = new HttpGet("http://localhost:8080/"); try (CloseableHttpClient client = HttpClients.createDefault()) { // First execution to load the classes execute(client, get); for (int i = 0 ; i < 100 ; i++) { long requestSendTime = System.currentTimeMillis(); execute(client, get); long requestTime = System.currentTimeMillis() - requestSendTime; latencies.add(requestTime); SECONDS.sleep(1); } } Collections.sort(latencies); System.out.println("Number of points : " + latencies.size()); System.out.println("Average : " + average(latencies)); System.out.println("80% : " + percentile(latencies, 0.8)); System.out.println("90% : " + percentile(latencies, 0.9)); System.out.println("95% : " + percentile(latencies, 0.9)); System.out.println("99% : " + percentile(latencies, 0.99)); System.out.println("Max : " + percentile(latencies, 1)); } }
  • 65. @pingtimeout 65 STW Runner • Simulate lonnnng GC pause • or any other lonnnng blocking task • ^Z echo "# Freezing server during 11 seconds..." kill -STOP $server_pid sleep 11 echo "# Unfreezing server..." kill -CONT $server_pid sleep 40
  • 66. @pingtimeout 66 Expectations - Timeline SIGSTOP SIGCONT
  • 67. @pingtimeout Pre-run check • Throughput = 1 req/s • Total duration = 100 s • Longest pause = 11 s • Typical response time ≈ 10 ms 67
  • 70. @pingtimeout Expectations - Maths • Expected percentiles • Max ∈ ]10; 11] • 99% ∈ ]9; 10] • 98% ∈ ]8; 9] • 95% ∈ ]5; 6] • 90% ∈ ]0; 1] 70
  • 73. @pingtimeout 73 Why? public class Client { public static void main(String[] args) throws Exception { ArrayList<Long> latencies = new ArrayList<>(100); HttpGet get = new HttpGet("http://localhost:8080/"); try (CloseableHttpClient client = HttpClients.createDefault()) { // First execution to load the classes execute(client, get); for (int i = 0 ; i < 100 ; i++) { long requestSendTime = System.currentTimeMillis(); execute(client, get); long requestTime = System.currentTimeMillis() - requestSendTime; latencies.add(requestTime); SECONDS.sleep(1); } } Collections.sort(latencies); System.out.println("Number of points : " + latencies.size()); System.out.println("Average : " + average(latencies)); System.out.println("80% : " + percentile(latencies, 0.8)); System.out.println("90% : " + percentile(latencies, 0.9)); System.out.println("95% : " + percentile(latencies, 0.9)); System.out.println("99% : " + percentile(latencies, 0.99)); System.out.println("Max : " + percentile(latencies, 1)); }
  • 74. @pingtimeout 74 Reality - Throughput 100s 100th data point
  • 75. @pingtimeout 75 Reality - Throughput 100s 100th data point
  • 76. @pingtimeout 76 What is CO ? • Interval between samples : x • Usual measurements << x • Outliers > x • Subsequent measurements delayed • After the bad period
  • 77. @pingtimeout 77 What is measured ? • Service Time's 99th percentile • ≠ Response Time's 99th percentile
  • 78. @pingtimeout 78 Is it common ? I rarely see load testers that don't suffer from it, including common testers used in the industry (JMeter, Grinder, HP LoadRunner) and benchmarks (YCSB, SPECeverything, etc.) — Gil Tene
  • 79. @pingtimeout Test the tester • Mandatory step • Replace SUT by noop • Response time = 0 • ^Z Test • Check hypothesis 79
  • 80. @pingtimeout 80 How to fix it ? 1/2 • Know your theoretical send time • Use it as the start time • Delayed requests will show the issue long requestSendTime = expectedSendTimeOfSample(n); execute(client, get); long requestTime = System.currentTimeMillis() - requestSendTime;
  • 81. @pingtimeout 81 How to fix it ? 2/2 • Interval between samples • Use HdrHistogram • http://giltene.github.io/HdrHistogram/ • class Histogram • copyCorrectedForCoordinatedOmission(…) • recordValueWithExpectedInterval(…)
  • 83. @pingtimeout 83 JMH • Written by Oracle Perf Eng Team • @shipilev leading • Code generator • Multi options runner (# threads, groups, iterations, …) • Pluggable profiles • Multi language • …
  • 84. @pingtimeout 84 Power == Responsibility
  • 85. @pingtimeout 85 JMH Samples • Code = documentation • Run the doc • Learn
  • 86. @pingtimeout 86 DCE @BenchmarkMode(Mode.Throughput) @OutputTimeUnit(TimeUnit.MICROSECONDS) public class DCE { @Benchmark public void baseline() { } @Benchmark public void measureWrong() { Math.log(Math.PI); } @Benchmark public double measureRight() { return Math.log(Math.PI); } }
  • 87. @pingtimeout 87 DCE Benchmark Samples Score Error Units f.p.b.DCE.baseline 5 3776,469 ± 14,079 ops/us f.p.b.DCE.measureRight 5 503,629 ± 10,431 ops/us f.p.b.DCE.measureWrong 5 3714,931 ± 172,927 ops/us
  • 88. @pingtimeout 88 CPU arithmetic @BenchmarkMode(Mode.AverageTime) @OutputTimeUnit(TimeUnit.NANOSECONDS) public class CPU { long a; long b; // [...] @Benchmark public long addition() { return a+b; } @Benchmark public long subtraction() { return a-b; } @Benchmark public long multiplication() { return a*b; } @Benchmark public long division() { return a/b; } }
  • 89. @pingtimeout 89 CPU arithmetic Benchmark Samples Score Error Units f.p.b.CPU.addition 5 2,058 ± 0,034 ns/op f.p.b.CPU.subtraction 5 2,070 ± 0,031 ns/op f.p.b.CPU.multiplication 5 2,087 ± 0,016 ns/op f.p.b.CPU.division 5 9,931 ± 0,218 ns/op
  • 90. @pingtimeout 90 Locks public class Locks { @State(Scope.Benchmark) public static class BenchmarkParameters { @Param({"1"}) public int burnCpuFactor; } @State(Scope.Group) public static class BaselineState { private int value = 0; } @State(Scope.Group) public static class SynchronizedState { private final Object lock = new Object(); private int value = 0; } @State(Scope.Group) public static class ReentrantRWLState { private final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); private int value = 0; }
  • 91. @pingtimeout 91 Locks @Benchmark @Group("baseline") public void updateBaseline(BaselineState s, BenchmarkParameters p) { Blackhole.consumeCPU(p.burnCpuFactor); s.value++; } @Benchmark @Group("baseline") public int readBaseline(BaselineState s, BenchmarkParameters p) { Blackhole.consumeCPU(p.burnCpuFactor); return s.value; }
  • 92. @pingtimeout @Benchmark @Group("synchronized") public void updateSynchronized(SynchronizedState s, BenchmarkParameters p) { synchronized (s.lock) { Blackhole.consumeCPU(p.burnCpuFactor); s.value++; } } @Benchmark @Group("synchronized") public int readSynchronized(SynchronizedState s, BenchmarkParameters p) { synchronized (s.lock) { Blackhole.consumeCPU(p.burnCpuFactor); return s.value; } } 92 Locks
  • 93. @pingtimeout @Benchmark @Group("rrwl") public void updateRrwl(ReentrantRWLState s, BenchmarkParameters p) { s.lock.writeLock().lock(); try { Blackhole.consumeCPU(p.burnCpuFactor); s.value++; } finally { s.lock.writeLock().unlock(); } } @Benchmark @Group("rrwl") public int readRrwl(ReentrantRWLState s, BenchmarkParameters p) { s.lock.readLock().lock(); try { Blackhole.consumeCPU(p.burnCpuFactor); return s.value; } finally { s.lock.readLock().unlock(); } } 93 Locks
  • 94. @pingtimeout 94 Locks # 1 reader, 1 writer, burnCpuFactor=1 Benchmark Samples Score Error Units f.p.b.Locks.readBaseline 20 48632,823 ±1549,042 ops/ms f.p.b.Locks.updateBaseline 20 232492,376 ±12527,203 ops/ms f.p.b.Locks.readSynchronized 20 2384,911 ±162,020 ops/ms f.p.b.Locks.updateSynchronized 20 9295,519 ±1017,941 ops/ms f.p.b.Locks.readSynchronized 20 13133,933 ±164,549 ops/ms f.p.b.Locks.updateSynchronized 20 13701,232 ±357,065 ops/ms
  • 95. @pingtimeout 95 Locks # 1 reader, 1 writer, burnCpuFactor=10 Benchmark Samples Score Error Units f.p.b.Locks.readBaseline 20 22573,454 ±158,246 ops/ms f.p.b.Locks.updateBaseline 20 82398,369 ±1429,225 ops/ms f.p.b.Locks.readSynchronized 20 2176,295 ±232,285 ops/ms f.p.b.Locks.updateSynchronized 20 9236,524 ±1575,705 ops/ms f.p.b.Locks.readSynchronized 20 8716,035 ±551,503 ops/ms f.p.b.Locks.updateSynchronized 20 13970,326 ±1500,214 ops/ms
  • 96. @pingtimeout 96 Locks # 1 reader, 1 writer, burnCpuFactor=50 Benchmark Samples Score Error Units f.p.b.Locks.readBaseline 20 11312,319 ±209,768 ops/ms f.p.b.Locks.updateBaseline 20 11566,514 ±194,376 ops/ms f.p.b.Locks.readSynchronized 20 998,879 ±156,620 ops/ms f.p.b.Locks.updateSynchronized 20 3369,257 ±168,350 ops/ms f.p.b.Locks.readSynchronized 20 3007,162 ±122,303 ops/ms f.p.b.Locks.updateSynchronized 20 3068,433 ±99,109 ops/ms
  • 97. @pingtimeout 97 Locks # 1 reader, 3 writers, burnCpuFactor=10 Benchmark Samples Score Error Units f.p.b.Locks.readBaseline 20 15215,388 ±229,017 ops/ms f.p.b.Locks.updateBaseline 20 146910,990 ±1762,371 ops/ms f.p.b.Locks.readRrwl 20 76,190 ±3,637 ops/ms f.p.b.Locks.updateRrwl 20 30327,966 ±674,847 ops/ms f.p.b.Locks.readSynchronized 20 3989,755 ±219,982 ops/ms f.p.b.Locks.updateSynchronized 20 15769,990 ±116,859 ops/ms
  • 99. @pingtimeout 99 The successful man will profit from his mistakes and try again in a different way — Dale Carnegie
  • 101. @pingtimeout 101 Sources • https://groups.google.com/d/msg/mechanical-sympathy/ • http://psy-lob-saw.blogspot.fr/ • http://latencytipoftheday.blogspot.fr/ • http://www.websiteoptimization.com/speed/tweak/ average-number-web-objects/ • Hotspot source code • @kcpeppe, @giltene, @shipilev • @pingtimeout ;-)
  • 102. @pingtimeout Thank you for your attention! • Q&A ? 102