designing for performance - jfokusuniversal scalability law 0 2 4 6 8 10 12 14 16 18 20 1 2 4 8 16...
TRANSCRIPT
![Page 1: Designing for Performance - JfokusUniversal Scalability Law 0 2 4 6 8 10 12 14 16 18 20 1 2 4 8 16 32 64 128 256 512 1024 Speedup Processors Amdahl USL](https://reader035.vdocuments.us/reader035/viewer/2022081607/5f01f1577e708231d401cc74/html5/thumbnails/1.jpg)
Designing for Performance
Martin Thompson - @mjpt777
![Page 2: Designing for Performance - JfokusUniversal Scalability Law 0 2 4 6 8 10 12 14 16 18 20 1 2 4 8 16 32 64 128 256 512 1024 Speedup Processors Amdahl USL](https://reader035.vdocuments.us/reader035/viewer/2022081607/5f01f1577e708231d401cc74/html5/thumbnails/2.jpg)
Is it difficult writing software
which has good performance?
![Page 3: Designing for Performance - JfokusUniversal Scalability Law 0 2 4 6 8 10 12 14 16 18 20 1 2 4 8 16 32 64 128 256 512 1024 Speedup Processors Amdahl USL](https://reader035.vdocuments.us/reader035/viewer/2022081607/5f01f1577e708231d401cc74/html5/thumbnails/3.jpg)
It is if you practice
RDD(Resume Driven Development)
![Page 4: Designing for Performance - JfokusUniversal Scalability Law 0 2 4 6 8 10 12 14 16 18 20 1 2 4 8 16 32 64 128 256 512 1024 Speedup Processors Amdahl USL](https://reader035.vdocuments.us/reader035/viewer/2022081607/5f01f1577e708231d401cc74/html5/thumbnails/4.jpg)
How do we
Design for Performance?
![Page 5: Designing for Performance - JfokusUniversal Scalability Law 0 2 4 6 8 10 12 14 16 18 20 1 2 4 8 16 32 64 128 256 512 1024 Speedup Processors Amdahl USL](https://reader035.vdocuments.us/reader035/viewer/2022081607/5f01f1577e708231d401cc74/html5/thumbnails/5.jpg)
1. What is Performance?
2. What is Clean & Representative?
3. Implementing efficient Models
4. Why Performance Test?
![Page 6: Designing for Performance - JfokusUniversal Scalability Law 0 2 4 6 8 10 12 14 16 18 20 1 2 4 8 16 32 64 128 256 512 1024 Speedup Processors Amdahl USL](https://reader035.vdocuments.us/reader035/viewer/2022081607/5f01f1577e708231d401cc74/html5/thumbnails/6.jpg)
Performance
![Page 7: Designing for Performance - JfokusUniversal Scalability Law 0 2 4 6 8 10 12 14 16 18 20 1 2 4 8 16 32 64 128 256 512 1024 Speedup Processors Amdahl USL](https://reader035.vdocuments.us/reader035/viewer/2022081607/5f01f1577e708231d401cc74/html5/thumbnails/7.jpg)
Throughput (aka Bandwidth)
![Page 8: Designing for Performance - JfokusUniversal Scalability Law 0 2 4 6 8 10 12 14 16 18 20 1 2 4 8 16 32 64 128 256 512 1024 Speedup Processors Amdahl USL](https://reader035.vdocuments.us/reader035/viewer/2022081607/5f01f1577e708231d401cc74/html5/thumbnails/8.jpg)
Response Time (aka Latency)
![Page 9: Designing for Performance - JfokusUniversal Scalability Law 0 2 4 6 8 10 12 14 16 18 20 1 2 4 8 16 32 64 128 256 512 1024 Speedup Processors Amdahl USL](https://reader035.vdocuments.us/reader035/viewer/2022081607/5f01f1577e708231d401cc74/html5/thumbnails/9.jpg)
Scalability
![Page 10: Designing for Performance - JfokusUniversal Scalability Law 0 2 4 6 8 10 12 14 16 18 20 1 2 4 8 16 32 64 128 256 512 1024 Speedup Processors Amdahl USL](https://reader035.vdocuments.us/reader035/viewer/2022081607/5f01f1577e708231d401cc74/html5/thumbnails/10.jpg)
![Page 11: Designing for Performance - JfokusUniversal Scalability Law 0 2 4 6 8 10 12 14 16 18 20 1 2 4 8 16 32 64 128 256 512 1024 Speedup Processors Amdahl USL](https://reader035.vdocuments.us/reader035/viewer/2022081607/5f01f1577e708231d401cc74/html5/thumbnails/11.jpg)
Queuing Theory
0.0
2.0
4.0
6.0
8.0
10.0
12.0
0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0
Re
spo
nse
Tim
e
Utilisation
![Page 12: Designing for Performance - JfokusUniversal Scalability Law 0 2 4 6 8 10 12 14 16 18 20 1 2 4 8 16 32 64 128 256 512 1024 Speedup Processors Amdahl USL](https://reader035.vdocuments.us/reader035/viewer/2022081607/5f01f1577e708231d401cc74/html5/thumbnails/12.jpg)
Pro Tip:Ensure you have sufficient capacity
![Page 13: Designing for Performance - JfokusUniversal Scalability Law 0 2 4 6 8 10 12 14 16 18 20 1 2 4 8 16 32 64 128 256 512 1024 Speedup Processors Amdahl USL](https://reader035.vdocuments.us/reader035/viewer/2022081607/5f01f1577e708231d401cc74/html5/thumbnails/13.jpg)
Can we go parallel to speedup?
![Page 14: Designing for Performance - JfokusUniversal Scalability Law 0 2 4 6 8 10 12 14 16 18 20 1 2 4 8 16 32 64 128 256 512 1024 Speedup Processors Amdahl USL](https://reader035.vdocuments.us/reader035/viewer/2022081607/5f01f1577e708231d401cc74/html5/thumbnails/14.jpg)
ASequential Process
time
B
Amdahl’s Law
![Page 15: Designing for Performance - JfokusUniversal Scalability Law 0 2 4 6 8 10 12 14 16 18 20 1 2 4 8 16 32 64 128 256 512 1024 Speedup Processors Amdahl USL](https://reader035.vdocuments.us/reader035/viewer/2022081607/5f01f1577e708231d401cc74/html5/thumbnails/15.jpg)
ASequential Process
A BParallel Process A
A
A
A
time
B
Amdahl’s Law
![Page 16: Designing for Performance - JfokusUniversal Scalability Law 0 2 4 6 8 10 12 14 16 18 20 1 2 4 8 16 32 64 128 256 512 1024 Speedup Processors Amdahl USL](https://reader035.vdocuments.us/reader035/viewer/2022081607/5f01f1577e708231d401cc74/html5/thumbnails/16.jpg)
ASequential Process
Parallel Process B
A BParallel Process A
A
A
A
time
B
A B
B
B
B
Amdahl’s Law
![Page 17: Designing for Performance - JfokusUniversal Scalability Law 0 2 4 6 8 10 12 14 16 18 20 1 2 4 8 16 32 64 128 256 512 1024 Speedup Processors Amdahl USL](https://reader035.vdocuments.us/reader035/viewer/2022081607/5f01f1577e708231d401cc74/html5/thumbnails/17.jpg)
Amdahl’s Law
![Page 18: Designing for Performance - JfokusUniversal Scalability Law 0 2 4 6 8 10 12 14 16 18 20 1 2 4 8 16 32 64 128 256 512 1024 Speedup Processors Amdahl USL](https://reader035.vdocuments.us/reader035/viewer/2022081607/5f01f1577e708231d401cc74/html5/thumbnails/18.jpg)
Universal Scalability Law
C(N) = N / (1 + α(N – 1) + ((β* N) * (N – 1)))
C = capacity or throughput
N = number of processors
α = contention penalty
β = coherence penalty
![Page 19: Designing for Performance - JfokusUniversal Scalability Law 0 2 4 6 8 10 12 14 16 18 20 1 2 4 8 16 32 64 128 256 512 1024 Speedup Processors Amdahl USL](https://reader035.vdocuments.us/reader035/viewer/2022081607/5f01f1577e708231d401cc74/html5/thumbnails/19.jpg)
Universal Scalability Law
0
2
4
6
8
10
12
14
16
18
20
1 2 4 8 16 32 64 128 256 512 1024
Sp
ee
du
p
Processors
Amdahl USL
![Page 20: Designing for Performance - JfokusUniversal Scalability Law 0 2 4 6 8 10 12 14 16 18 20 1 2 4 8 16 32 64 128 256 512 1024 Speedup Processors Amdahl USL](https://reader035.vdocuments.us/reader035/viewer/2022081607/5f01f1577e708231d401cc74/html5/thumbnails/20.jpg)
0
20,000
40,000
60,000
80,000
100,000
120,000
140,000
160,000
1 2 3 4 5 6 7 8
Tim
e (
nan
oseco
nd
s)
![Page 21: Designing for Performance - JfokusUniversal Scalability Law 0 2 4 6 8 10 12 14 16 18 20 1 2 4 8 16 32 64 128 256 512 1024 Speedup Processors Amdahl USL](https://reader035.vdocuments.us/reader035/viewer/2022081607/5f01f1577e708231d401cc74/html5/thumbnails/21.jpg)
0
20,000
40,000
60,000
80,000
100,000
120,000
140,000
160,000
1 2 3 4 5 6 7 8
Tim
e (
nan
oseco
nd
s)
Mean Logging Duration
![Page 22: Designing for Performance - JfokusUniversal Scalability Law 0 2 4 6 8 10 12 14 16 18 20 1 2 4 8 16 32 64 128 256 512 1024 Speedup Processors Amdahl USL](https://reader035.vdocuments.us/reader035/viewer/2022081607/5f01f1577e708231d401cc74/html5/thumbnails/22.jpg)
Clean & Representative
![Page 23: Designing for Performance - JfokusUniversal Scalability Law 0 2 4 6 8 10 12 14 16 18 20 1 2 4 8 16 32 64 128 256 512 1024 Speedup Processors Amdahl USL](https://reader035.vdocuments.us/reader035/viewer/2022081607/5f01f1577e708231d401cc74/html5/thumbnails/23.jpg)
- Clean
“Morally uncontaminated;
pure; innocent”
- Oxford English Dictionary
![Page 24: Designing for Performance - JfokusUniversal Scalability Law 0 2 4 6 8 10 12 14 16 18 20 1 2 4 8 16 32 64 128 256 512 1024 Speedup Processors Amdahl USL](https://reader035.vdocuments.us/reader035/viewer/2022081607/5f01f1577e708231d401cc74/html5/thumbnails/24.jpg)
- Representative
“Serving as a portrayal or
symbol of something”
- Oxford English Dictionary
![Page 25: Designing for Performance - JfokusUniversal Scalability Law 0 2 4 6 8 10 12 14 16 18 20 1 2 4 8 16 32 64 128 256 512 1024 Speedup Processors Amdahl USL](https://reader035.vdocuments.us/reader035/viewer/2022081607/5f01f1577e708231d401cc74/html5/thumbnails/25.jpg)
- Representative
Code is the best place to
capture our current
understanding of a model
![Page 26: Designing for Performance - JfokusUniversal Scalability Law 0 2 4 6 8 10 12 14 16 18 20 1 2 4 8 16 32 64 128 256 512 1024 Speedup Processors Amdahl USL](https://reader035.vdocuments.us/reader035/viewer/2022081607/5f01f1577e708231d401cc74/html5/thumbnails/26.jpg)
Abstractions
![Page 27: Designing for Performance - JfokusUniversal Scalability Law 0 2 4 6 8 10 12 14 16 18 20 1 2 4 8 16 32 64 128 256 512 1024 Speedup Processors Amdahl USL](https://reader035.vdocuments.us/reader035/viewer/2022081607/5f01f1577e708231d401cc74/html5/thumbnails/27.jpg)
Rules of Abstraction
1. Don’t use abstraction
![Page 28: Designing for Performance - JfokusUniversal Scalability Law 0 2 4 6 8 10 12 14 16 18 20 1 2 4 8 16 32 64 128 256 512 1024 Speedup Processors Amdahl USL](https://reader035.vdocuments.us/reader035/viewer/2022081607/5f01f1577e708231d401cc74/html5/thumbnails/28.jpg)
Rules of Abstraction
1. Don’t use abstraction
2. Don’t use abstraction
![Page 29: Designing for Performance - JfokusUniversal Scalability Law 0 2 4 6 8 10 12 14 16 18 20 1 2 4 8 16 32 64 128 256 512 1024 Speedup Processors Amdahl USL](https://reader035.vdocuments.us/reader035/viewer/2022081607/5f01f1577e708231d401cc74/html5/thumbnails/29.jpg)
Rules of Abstraction
1. Don’t use abstraction
2. Don’t use abstraction
3. Only consider abstracting when you
see at least 3 things that ARE the same
![Page 30: Designing for Performance - JfokusUniversal Scalability Law 0 2 4 6 8 10 12 14 16 18 20 1 2 4 8 16 32 64 128 256 512 1024 Speedup Processors Amdahl USL](https://reader035.vdocuments.us/reader035/viewer/2022081607/5f01f1577e708231d401cc74/html5/thumbnails/30.jpg)
Rules of Abstraction
1. Don’t use abstraction
2. Don’t use abstraction
3. Only consider abstracting when you
see at least 3 things that ARE the same
4. Abstractions must pay for themselves
![Page 31: Designing for Performance - JfokusUniversal Scalability Law 0 2 4 6 8 10 12 14 16 18 20 1 2 4 8 16 32 64 128 256 512 1024 Speedup Processors Amdahl USL](https://reader035.vdocuments.us/reader035/viewer/2022081607/5f01f1577e708231d401cc74/html5/thumbnails/31.jpg)
Rules of Abstraction
1. Don’t use abstraction
2. Don’t use abstraction
3. Only consider abstracting when you
see at least 3 things that ARE the same
4. Abstractions must pay for themselves
5. Beware DRY, the evil siren that tricks you into abstraction -> Coupling
![Page 32: Designing for Performance - JfokusUniversal Scalability Law 0 2 4 6 8 10 12 14 16 18 20 1 2 4 8 16 32 64 128 256 512 1024 Speedup Processors Amdahl USL](https://reader035.vdocuments.us/reader035/viewer/2022081607/5f01f1577e708231d401cc74/html5/thumbnails/32.jpg)
Abstraction
Megamorphism => Branch Hell
![Page 33: Designing for Performance - JfokusUniversal Scalability Law 0 2 4 6 8 10 12 14 16 18 20 1 2 4 8 16 32 64 128 256 512 1024 Speedup Processors Amdahl USL](https://reader035.vdocuments.us/reader035/viewer/2022081607/5f01f1577e708231d401cc74/html5/thumbnails/33.jpg)
Abstraction
Not Representative => Big Smell
![Page 34: Designing for Performance - JfokusUniversal Scalability Law 0 2 4 6 8 10 12 14 16 18 20 1 2 4 8 16 32 64 128 256 512 1024 Speedup Processors Amdahl USL](https://reader035.vdocuments.us/reader035/viewer/2022081607/5f01f1577e708231d401cc74/html5/thumbnails/34.jpg)
Abstraction
Say no to big frameworks!
![Page 35: Designing for Performance - JfokusUniversal Scalability Law 0 2 4 6 8 10 12 14 16 18 20 1 2 4 8 16 32 64 128 256 512 1024 Speedup Processors Amdahl USL](https://reader035.vdocuments.us/reader035/viewer/2022081607/5f01f1577e708231d401cc74/html5/thumbnails/35.jpg)
![Page 36: Designing for Performance - JfokusUniversal Scalability Law 0 2 4 6 8 10 12 14 16 18 20 1 2 4 8 16 32 64 128 256 512 1024 Speedup Processors Amdahl USL](https://reader035.vdocuments.us/reader035/viewer/2022081607/5f01f1577e708231d401cc74/html5/thumbnails/36.jpg)
Pro Tip: Abstract when you are sure of the benefits
![Page 37: Designing for Performance - JfokusUniversal Scalability Law 0 2 4 6 8 10 12 14 16 18 20 1 2 4 8 16 32 64 128 256 512 1024 Speedup Processors Amdahl USL](https://reader035.vdocuments.us/reader035/viewer/2022081607/5f01f1577e708231d401cc74/html5/thumbnails/37.jpg)
Law of Leaky Abstractions
“All non-trivial abstractions,
to some extent, are leaky.”
- Joel Spolsky
![Page 38: Designing for Performance - JfokusUniversal Scalability Law 0 2 4 6 8 10 12 14 16 18 20 1 2 4 8 16 32 64 128 256 512 1024 Speedup Processors Amdahl USL](https://reader035.vdocuments.us/reader035/viewer/2022081607/5f01f1577e708231d401cc74/html5/thumbnails/38.jpg)
Law of Leaky Abstractions
“The detail of underlying
complexity cannot be ignored.”
![Page 39: Designing for Performance - JfokusUniversal Scalability Law 0 2 4 6 8 10 12 14 16 18 20 1 2 4 8 16 32 64 128 256 512 1024 Speedup Processors Amdahl USL](https://reader035.vdocuments.us/reader035/viewer/2022081607/5f01f1577e708231d401cc74/html5/thumbnails/39.jpg)
“the purpose of abstracting
is not to be vague, but to create
a new semantic level in which
one can be absolutely precise”
- Dijkstra
![Page 40: Designing for Performance - JfokusUniversal Scalability Law 0 2 4 6 8 10 12 14 16 18 20 1 2 4 8 16 32 64 128 256 512 1024 Speedup Processors Amdahl USL](https://reader035.vdocuments.us/reader035/viewer/2022081607/5f01f1577e708231d401cc74/html5/thumbnails/40.jpg)
How can we abstractmemory systems?
![Page 41: Designing for Performance - JfokusUniversal Scalability Law 0 2 4 6 8 10 12 14 16 18 20 1 2 4 8 16 32 64 128 256 512 1024 Speedup Processors Amdahl USL](https://reader035.vdocuments.us/reader035/viewer/2022081607/5f01f1577e708231d401cc74/html5/thumbnails/41.jpg)
- It’s about 3 bets!
1. The Temporal Bet
![Page 42: Designing for Performance - JfokusUniversal Scalability Law 0 2 4 6 8 10 12 14 16 18 20 1 2 4 8 16 32 64 128 256 512 1024 Speedup Processors Amdahl USL](https://reader035.vdocuments.us/reader035/viewer/2022081607/5f01f1577e708231d401cc74/html5/thumbnails/42.jpg)
- It’s about 3 bets!
1. The Temporal Bet
2. The Spatial Bet
![Page 43: Designing for Performance - JfokusUniversal Scalability Law 0 2 4 6 8 10 12 14 16 18 20 1 2 4 8 16 32 64 128 256 512 1024 Speedup Processors Amdahl USL](https://reader035.vdocuments.us/reader035/viewer/2022081607/5f01f1577e708231d401cc74/html5/thumbnails/43.jpg)
- It’s about 3 bets!
1. The Temporal Bet
2. The Spatial Bet
3. The Pattern Bet
![Page 44: Designing for Performance - JfokusUniversal Scalability Law 0 2 4 6 8 10 12 14 16 18 20 1 2 4 8 16 32 64 128 256 512 1024 Speedup Processors Amdahl USL](https://reader035.vdocuments.us/reader035/viewer/2022081607/5f01f1577e708231d401cc74/html5/thumbnails/44.jpg)
Model Implementation
![Page 45: Designing for Performance - JfokusUniversal Scalability Law 0 2 4 6 8 10 12 14 16 18 20 1 2 4 8 16 32 64 128 256 512 1024 Speedup Processors Amdahl USL](https://reader035.vdocuments.us/reader035/viewer/2022081607/5f01f1577e708231d401cc74/html5/thumbnails/45.jpg)
Coupling vs Cohesion
![Page 46: Designing for Performance - JfokusUniversal Scalability Law 0 2 4 6 8 10 12 14 16 18 20 1 2 4 8 16 32 64 128 256 512 1024 Speedup Processors Amdahl USL](https://reader035.vdocuments.us/reader035/viewer/2022081607/5f01f1577e708231d401cc74/html5/thumbnails/46.jpg)
Coupling vs Cohesion
public class Queue
{
private final Object[] buffer;
private final int capacity;
// Rest of the code
}
![Page 47: Designing for Performance - JfokusUniversal Scalability Law 0 2 4 6 8 10 12 14 16 18 20 1 2 4 8 16 32 64 128 256 512 1024 Speedup Processors Amdahl USL](https://reader035.vdocuments.us/reader035/viewer/2022081607/5f01f1577e708231d401cc74/html5/thumbnails/47.jpg)
Coupling vs Cohesion
public class Queue
{
private final Object[] buffer;
private final int capacity;
// Rest of the code
}
![Page 48: Designing for Performance - JfokusUniversal Scalability Law 0 2 4 6 8 10 12 14 16 18 20 1 2 4 8 16 32 64 128 256 512 1024 Speedup Processors Amdahl USL](https://reader035.vdocuments.us/reader035/viewer/2022081607/5f01f1577e708231d401cc74/html5/thumbnails/48.jpg)
Coupling vs Cohesion
Properties Bag
![Page 49: Designing for Performance - JfokusUniversal Scalability Law 0 2 4 6 8 10 12 14 16 18 20 1 2 4 8 16 32 64 128 256 512 1024 Speedup Processors Amdahl USL](https://reader035.vdocuments.us/reader035/viewer/2022081607/5f01f1577e708231d401cc74/html5/thumbnails/49.jpg)
Pro Tip: RespectLocality of Reference
![Page 50: Designing for Performance - JfokusUniversal Scalability Law 0 2 4 6 8 10 12 14 16 18 20 1 2 4 8 16 32 64 128 256 512 1024 Speedup Processors Amdahl USL](https://reader035.vdocuments.us/reader035/viewer/2022081607/5f01f1577e708231d401cc74/html5/thumbnails/50.jpg)
Relationships
![Page 51: Designing for Performance - JfokusUniversal Scalability Law 0 2 4 6 8 10 12 14 16 18 20 1 2 4 8 16 32 64 128 256 512 1024 Speedup Processors Amdahl USL](https://reader035.vdocuments.us/reader035/viewer/2022081607/5f01f1577e708231d401cc74/html5/thumbnails/51.jpg)
Order
BookOrder
Relationships
![Page 52: Designing for Performance - JfokusUniversal Scalability Law 0 2 4 6 8 10 12 14 16 18 20 1 2 4 8 16 32 64 128 256 512 1024 Speedup Processors Amdahl USL](https://reader035.vdocuments.us/reader035/viewer/2022081607/5f01f1577e708231d401cc74/html5/thumbnails/52.jpg)
Order
BookOrder
1 Offers *
1 Bids *
Relationships
![Page 53: Designing for Performance - JfokusUniversal Scalability Law 0 2 4 6 8 10 12 14 16 18 20 1 2 4 8 16 32 64 128 256 512 1024 Speedup Processors Amdahl USL](https://reader035.vdocuments.us/reader035/viewer/2022081607/5f01f1577e708231d401cc74/html5/thumbnails/53.jpg)
Order
BookOrder
Price
Price
1 Bids *
1 Offers *
Relationships
![Page 54: Designing for Performance - JfokusUniversal Scalability Law 0 2 4 6 8 10 12 14 16 18 20 1 2 4 8 16 32 64 128 256 512 1024 Speedup Processors Amdahl USL](https://reader035.vdocuments.us/reader035/viewer/2022081607/5f01f1577e708231d401cc74/html5/thumbnails/54.jpg)
Order
BookOrder
Price
Price
1 Bids *
1 Offers *
{ordered, FIFO}
{ordered, FIFO}
Relationships
![Page 55: Designing for Performance - JfokusUniversal Scalability Law 0 2 4 6 8 10 12 14 16 18 20 1 2 4 8 16 32 64 128 256 512 1024 Speedup Processors Amdahl USL](https://reader035.vdocuments.us/reader035/viewer/2022081607/5f01f1577e708231d401cc74/html5/thumbnails/55.jpg)
Pro Tip: Make friends with your Data Structures
![Page 56: Designing for Performance - JfokusUniversal Scalability Law 0 2 4 6 8 10 12 14 16 18 20 1 2 4 8 16 32 64 128 256 512 1024 Speedup Processors Amdahl USL](https://reader035.vdocuments.us/reader035/viewer/2022081607/5f01f1577e708231d401cc74/html5/thumbnails/56.jpg)
Pro Tip:Document, discuss,
design tests, before going to code
![Page 57: Designing for Performance - JfokusUniversal Scalability Law 0 2 4 6 8 10 12 14 16 18 20 1 2 4 8 16 32 64 128 256 512 1024 Speedup Processors Amdahl USL](https://reader035.vdocuments.us/reader035/viewer/2022081607/5f01f1577e708231d401cc74/html5/thumbnails/57.jpg)
Algorithms
![Page 58: Designing for Performance - JfokusUniversal Scalability Law 0 2 4 6 8 10 12 14 16 18 20 1 2 4 8 16 32 64 128 256 512 1024 Speedup Processors Amdahl USL](https://reader035.vdocuments.us/reader035/viewer/2022081607/5f01f1577e708231d401cc74/html5/thumbnails/58.jpg)
Order of Algorithms
![Page 59: Designing for Performance - JfokusUniversal Scalability Law 0 2 4 6 8 10 12 14 16 18 20 1 2 4 8 16 32 64 128 256 512 1024 Speedup Processors Amdahl USL](https://reader035.vdocuments.us/reader035/viewer/2022081607/5f01f1577e708231d401cc74/html5/thumbnails/59.jpg)
Order of Algorithms
Magnitude of n?
![Page 60: Designing for Performance - JfokusUniversal Scalability Law 0 2 4 6 8 10 12 14 16 18 20 1 2 4 8 16 32 64 128 256 512 1024 Speedup Processors Amdahl USL](https://reader035.vdocuments.us/reader035/viewer/2022081607/5f01f1577e708231d401cc74/html5/thumbnails/60.jpg)
Pro Tip:Know the cardinality
of allsignificant relationships
![Page 61: Designing for Performance - JfokusUniversal Scalability Law 0 2 4 6 8 10 12 14 16 18 20 1 2 4 8 16 32 64 128 256 512 1024 Speedup Processors Amdahl USL](https://reader035.vdocuments.us/reader035/viewer/2022081607/5f01f1577e708231d401cc74/html5/thumbnails/61.jpg)
Pro Tip: Algorithms are your key to service time
![Page 62: Designing for Performance - JfokusUniversal Scalability Law 0 2 4 6 8 10 12 14 16 18 20 1 2 4 8 16 32 64 128 256 512 1024 Speedup Processors Amdahl USL](https://reader035.vdocuments.us/reader035/viewer/2022081607/5f01f1577e708231d401cc74/html5/thumbnails/62.jpg)
Batching
![Page 63: Designing for Performance - JfokusUniversal Scalability Law 0 2 4 6 8 10 12 14 16 18 20 1 2 4 8 16 32 64 128 256 512 1024 Speedup Processors Amdahl USL](https://reader035.vdocuments.us/reader035/viewer/2022081607/5f01f1577e708231d401cc74/html5/thumbnails/63.jpg)
Amortise the expensive costs
![Page 64: Designing for Performance - JfokusUniversal Scalability Law 0 2 4 6 8 10 12 14 16 18 20 1 2 4 8 16 32 64 128 256 512 1024 Speedup Processors Amdahl USL](https://reader035.vdocuments.us/reader035/viewer/2022081607/5f01f1577e708231d401cc74/html5/thumbnails/64.jpg)
Natural Batching
Producers
![Page 65: Designing for Performance - JfokusUniversal Scalability Law 0 2 4 6 8 10 12 14 16 18 20 1 2 4 8 16 32 64 128 256 512 1024 Speedup Processors Amdahl USL](https://reader035.vdocuments.us/reader035/viewer/2022081607/5f01f1577e708231d401cc74/html5/thumbnails/65.jpg)
Natural Batching
Batcher
Producers
<< Amortise Expensive Costs >>
![Page 66: Designing for Performance - JfokusUniversal Scalability Law 0 2 4 6 8 10 12 14 16 18 20 1 2 4 8 16 32 64 128 256 512 1024 Speedup Processors Amdahl USL](https://reader035.vdocuments.us/reader035/viewer/2022081607/5f01f1577e708231d401cc74/html5/thumbnails/66.jpg)
Natural BatchingR
esp
on
se T
ime
Load
Typical
Possible
![Page 67: Designing for Performance - JfokusUniversal Scalability Law 0 2 4 6 8 10 12 14 16 18 20 1 2 4 8 16 32 64 128 256 512 1024 Speedup Processors Amdahl USL](https://reader035.vdocuments.us/reader035/viewer/2022081607/5f01f1577e708231d401cc74/html5/thumbnails/67.jpg)
Pro Tip: Batch processing is not just for offline
![Page 68: Designing for Performance - JfokusUniversal Scalability Law 0 2 4 6 8 10 12 14 16 18 20 1 2 4 8 16 32 64 128 256 512 1024 Speedup Processors Amdahl USL](https://reader035.vdocuments.us/reader035/viewer/2022081607/5f01f1577e708231d401cc74/html5/thumbnails/68.jpg)
Branches, branches,
branches...
![Page 69: Designing for Performance - JfokusUniversal Scalability Law 0 2 4 6 8 10 12 14 16 18 20 1 2 4 8 16 32 64 128 256 512 1024 Speedup Processors Amdahl USL](https://reader035.vdocuments.us/reader035/viewer/2022081607/5f01f1577e708231d401cc74/html5/thumbnails/69.jpg)
Branches
public void doStuff(List<String> things)
{
if (null == things || things.isEmpty())
{
return;
}
for (String thing : things)
{
// Do useful work
}
}
![Page 70: Designing for Performance - JfokusUniversal Scalability Law 0 2 4 6 8 10 12 14 16 18 20 1 2 4 8 16 32 64 128 256 512 1024 Speedup Processors Amdahl USL](https://reader035.vdocuments.us/reader035/viewer/2022081607/5f01f1577e708231d401cc74/html5/thumbnails/70.jpg)
Branches
public void doStuff(List<String> things)
{
if (null == things || things.isEmpty())
{
return;
}
for (String thing : things)
{
// Do useful work
}
}
![Page 71: Designing for Performance - JfokusUniversal Scalability Law 0 2 4 6 8 10 12 14 16 18 20 1 2 4 8 16 32 64 128 256 512 1024 Speedup Processors Amdahl USL](https://reader035.vdocuments.us/reader035/viewer/2022081607/5f01f1577e708231d401cc74/html5/thumbnails/71.jpg)
Branches
public void doStuff(List<String> things)
{
for (String thing : things)
{
// Do useful work
}
}
![Page 72: Designing for Performance - JfokusUniversal Scalability Law 0 2 4 6 8 10 12 14 16 18 20 1 2 4 8 16 32 64 128 256 512 1024 Speedup Processors Amdahl USL](https://reader035.vdocuments.us/reader035/viewer/2022081607/5f01f1577e708231d401cc74/html5/thumbnails/72.jpg)
Pro Tip: Respect the Principle of least surprise
![Page 73: Designing for Performance - JfokusUniversal Scalability Law 0 2 4 6 8 10 12 14 16 18 20 1 2 4 8 16 32 64 128 256 512 1024 Speedup Processors Amdahl USL](https://reader035.vdocuments.us/reader035/viewer/2022081607/5f01f1577e708231d401cc74/html5/thumbnails/73.jpg)
Loops
![Page 74: Designing for Performance - JfokusUniversal Scalability Law 0 2 4 6 8 10 12 14 16 18 20 1 2 4 8 16 32 64 128 256 512 1024 Speedup Processors Amdahl USL](https://reader035.vdocuments.us/reader035/viewer/2022081607/5f01f1577e708231d401cc74/html5/thumbnails/74.jpg)
Loops
“If I had more time, I would
have written a shorter letter.”
- Blaise Pascal
![Page 75: Designing for Performance - JfokusUniversal Scalability Law 0 2 4 6 8 10 12 14 16 18 20 1 2 4 8 16 32 64 128 256 512 1024 Speedup Processors Amdahl USL](https://reader035.vdocuments.us/reader035/viewer/2022081607/5f01f1577e708231d401cc74/html5/thumbnails/75.jpg)
L0 1536 µops
Loops
![Page 76: Designing for Performance - JfokusUniversal Scalability Law 0 2 4 6 8 10 12 14 16 18 20 1 2 4 8 16 32 64 128 256 512 1024 Speedup Processors Amdahl USL](https://reader035.vdocuments.us/reader035/viewer/2022081607/5f01f1577e708231d401cc74/html5/thumbnails/76.jpg)
L0 1536 µops
IDQ 28/56 µops
Loops
![Page 77: Designing for Performance - JfokusUniversal Scalability Law 0 2 4 6 8 10 12 14 16 18 20 1 2 4 8 16 32 64 128 256 512 1024 Speedup Processors Amdahl USL](https://reader035.vdocuments.us/reader035/viewer/2022081607/5f01f1577e708231d401cc74/html5/thumbnails/77.jpg)
Pro Tip: Craft major loops like good prose
![Page 78: Designing for Performance - JfokusUniversal Scalability Law 0 2 4 6 8 10 12 14 16 18 20 1 2 4 8 16 32 64 128 256 512 1024 Speedup Processors Amdahl USL](https://reader035.vdocuments.us/reader035/viewer/2022081607/5f01f1577e708231d401cc74/html5/thumbnails/78.jpg)
Composition
![Page 79: Designing for Performance - JfokusUniversal Scalability Law 0 2 4 6 8 10 12 14 16 18 20 1 2 4 8 16 32 64 128 256 512 1024 Speedup Processors Amdahl USL](https://reader035.vdocuments.us/reader035/viewer/2022081607/5f01f1577e708231d401cc74/html5/thumbnails/79.jpg)
Composition
Size matters
![Page 80: Designing for Performance - JfokusUniversal Scalability Law 0 2 4 6 8 10 12 14 16 18 20 1 2 4 8 16 32 64 128 256 512 1024 Speedup Processors Amdahl USL](https://reader035.vdocuments.us/reader035/viewer/2022081607/5f01f1577e708231d401cc74/html5/thumbnails/80.jpg)
Composition
“Inlining is THE optimisation.”
- Cliff Click
![Page 81: Designing for Performance - JfokusUniversal Scalability Law 0 2 4 6 8 10 12 14 16 18 20 1 2 4 8 16 32 64 128 256 512 1024 Speedup Processors Amdahl USL](https://reader035.vdocuments.us/reader035/viewer/2022081607/5f01f1577e708231d401cc74/html5/thumbnails/81.jpg)
Composition
Single Responsibility
![Page 82: Designing for Performance - JfokusUniversal Scalability Law 0 2 4 6 8 10 12 14 16 18 20 1 2 4 8 16 32 64 128 256 512 1024 Speedup Processors Amdahl USL](https://reader035.vdocuments.us/reader035/viewer/2022081607/5f01f1577e708231d401cc74/html5/thumbnails/82.jpg)
Pro Tip:Small atoms can
compose to build anything
![Page 83: Designing for Performance - JfokusUniversal Scalability Law 0 2 4 6 8 10 12 14 16 18 20 1 2 4 8 16 32 64 128 256 512 1024 Speedup Processors Amdahl USL](https://reader035.vdocuments.us/reader035/viewer/2022081607/5f01f1577e708231d401cc74/html5/thumbnails/83.jpg)
APIs
![Page 84: Designing for Performance - JfokusUniversal Scalability Law 0 2 4 6 8 10 12 14 16 18 20 1 2 4 8 16 32 64 128 256 512 1024 Speedup Processors Amdahl USL](https://reader035.vdocuments.us/reader035/viewer/2022081607/5f01f1577e708231d401cc74/html5/thumbnails/84.jpg)
selector.selectNow();
Set<SelectionKey> selectedKeys =
selector.selectedKeys();
Iterator<SelectionKey> iter =
selectedKeys.iterator();
while (iter.hasNext())
{
SelectionKey key = iter.next();
if (key.isReadable())
{
key.attachment(); // do work
}
iter.remove();
}
![Page 85: Designing for Performance - JfokusUniversal Scalability Law 0 2 4 6 8 10 12 14 16 18 20 1 2 4 8 16 32 64 128 256 512 1024 Speedup Processors Amdahl USL](https://reader035.vdocuments.us/reader035/viewer/2022081607/5f01f1577e708231d401cc74/html5/thumbnails/85.jpg)
selector.selectNow();
Set<SelectionKey> selectedKeys =
selector.selectedKeys();
Iterator<SelectionKey> iter =
selectedKeys.iterator();
while (iter.hasNext())
{
SelectionKey key = iter.next();
if (key.isReadable())
{
key.attachment(); // do work
}
iter.remove();
}
![Page 86: Designing for Performance - JfokusUniversal Scalability Law 0 2 4 6 8 10 12 14 16 18 20 1 2 4 8 16 32 64 128 256 512 1024 Speedup Processors Amdahl USL](https://reader035.vdocuments.us/reader035/viewer/2022081607/5f01f1577e708231d401cc74/html5/thumbnails/86.jpg)
// Keep and reuse
List<SelectionKey> keys = new ArrayList<>();
selector.selectNow(keys, READABLE);
keys.forEach(keyHandler);
![Page 87: Designing for Performance - JfokusUniversal Scalability Law 0 2 4 6 8 10 12 14 16 18 20 1 2 4 8 16 32 64 128 256 512 1024 Speedup Processors Amdahl USL](https://reader035.vdocuments.us/reader035/viewer/2022081607/5f01f1577e708231d401cc74/html5/thumbnails/87.jpg)
Data
![Page 88: Designing for Performance - JfokusUniversal Scalability Law 0 2 4 6 8 10 12 14 16 18 20 1 2 4 8 16 32 64 128 256 512 1024 Speedup Processors Amdahl USL](https://reader035.vdocuments.us/reader035/viewer/2022081607/5f01f1577e708231d401cc74/html5/thumbnails/88.jpg)
Data
![Page 89: Designing for Performance - JfokusUniversal Scalability Law 0 2 4 6 8 10 12 14 16 18 20 1 2 4 8 16 32 64 128 256 512 1024 Speedup Processors Amdahl USL](https://reader035.vdocuments.us/reader035/viewer/2022081607/5f01f1577e708231d401cc74/html5/thumbnails/89.jpg)
Data
![Page 90: Designing for Performance - JfokusUniversal Scalability Law 0 2 4 6 8 10 12 14 16 18 20 1 2 4 8 16 32 64 128 256 512 1024 Speedup Processors Amdahl USL](https://reader035.vdocuments.us/reader035/viewer/2022081607/5f01f1577e708231d401cc74/html5/thumbnails/90.jpg)
Data
![Page 91: Designing for Performance - JfokusUniversal Scalability Law 0 2 4 6 8 10 12 14 16 18 20 1 2 4 8 16 32 64 128 256 512 1024 Speedup Processors Amdahl USL](https://reader035.vdocuments.us/reader035/viewer/2022081607/5f01f1577e708231d401cc74/html5/thumbnails/91.jpg)
Data
![Page 92: Designing for Performance - JfokusUniversal Scalability Law 0 2 4 6 8 10 12 14 16 18 20 1 2 4 8 16 32 64 128 256 512 1024 Speedup Processors Amdahl USL](https://reader035.vdocuments.us/reader035/viewer/2022081607/5f01f1577e708231d401cc74/html5/thumbnails/92.jpg)
Data
![Page 93: Designing for Performance - JfokusUniversal Scalability Law 0 2 4 6 8 10 12 14 16 18 20 1 2 4 8 16 32 64 128 256 512 1024 Speedup Processors Amdahl USL](https://reader035.vdocuments.us/reader035/viewer/2022081607/5f01f1577e708231d401cc74/html5/thumbnails/93.jpg)
Pro Tip: Embrace Set Theory and FP techniques
![Page 94: Designing for Performance - JfokusUniversal Scalability Law 0 2 4 6 8 10 12 14 16 18 20 1 2 4 8 16 32 64 128 256 512 1024 Speedup Processors Amdahl USL](https://reader035.vdocuments.us/reader035/viewer/2022081607/5f01f1577e708231d401cc74/html5/thumbnails/94.jpg)
Performance Testing
![Page 95: Designing for Performance - JfokusUniversal Scalability Law 0 2 4 6 8 10 12 14 16 18 20 1 2 4 8 16 32 64 128 256 512 1024 Speedup Processors Amdahl USL](https://reader035.vdocuments.us/reader035/viewer/2022081607/5f01f1577e708231d401cc74/html5/thumbnails/95.jpg)
Define Performance Goals
![Page 96: Designing for Performance - JfokusUniversal Scalability Law 0 2 4 6 8 10 12 14 16 18 20 1 2 4 8 16 32 64 128 256 512 1024 Speedup Processors Amdahl USL](https://reader035.vdocuments.us/reader035/viewer/2022081607/5f01f1577e708231d401cc74/html5/thumbnails/96.jpg)
How to measure response time?
![Page 97: Designing for Performance - JfokusUniversal Scalability Law 0 2 4 6 8 10 12 14 16 18 20 1 2 4 8 16 32 64 128 256 512 1024 Speedup Processors Amdahl USL](https://reader035.vdocuments.us/reader035/viewer/2022081607/5f01f1577e708231d401cc74/html5/thumbnails/97.jpg)
Response Time Histograms
![Page 98: Designing for Performance - JfokusUniversal Scalability Law 0 2 4 6 8 10 12 14 16 18 20 1 2 4 8 16 32 64 128 256 512 1024 Speedup Processors Amdahl USL](https://reader035.vdocuments.us/reader035/viewer/2022081607/5f01f1577e708231d401cc74/html5/thumbnails/98.jpg)
Mode
Response Time Histograms
![Page 99: Designing for Performance - JfokusUniversal Scalability Law 0 2 4 6 8 10 12 14 16 18 20 1 2 4 8 16 32 64 128 256 512 1024 Speedup Processors Amdahl USL](https://reader035.vdocuments.us/reader035/viewer/2022081607/5f01f1577e708231d401cc74/html5/thumbnails/99.jpg)
ModeMedian
Response Time Histograms
![Page 100: Designing for Performance - JfokusUniversal Scalability Law 0 2 4 6 8 10 12 14 16 18 20 1 2 4 8 16 32 64 128 256 512 1024 Speedup Processors Amdahl USL](https://reader035.vdocuments.us/reader035/viewer/2022081607/5f01f1577e708231d401cc74/html5/thumbnails/100.jpg)
ModeMedian
Mean
Response Time Histograms
![Page 101: Designing for Performance - JfokusUniversal Scalability Law 0 2 4 6 8 10 12 14 16 18 20 1 2 4 8 16 32 64 128 256 512 1024 Speedup Processors Amdahl USL](https://reader035.vdocuments.us/reader035/viewer/2022081607/5f01f1577e708231d401cc74/html5/thumbnails/101.jpg)
ModeMedian
Mean
Response Time Histograms
![Page 102: Designing for Performance - JfokusUniversal Scalability Law 0 2 4 6 8 10 12 14 16 18 20 1 2 4 8 16 32 64 128 256 512 1024 Speedup Processors Amdahl USL](https://reader035.vdocuments.us/reader035/viewer/2022081607/5f01f1577e708231d401cc74/html5/thumbnails/102.jpg)
ModeMedian
Mean
Response Time Histograms
![Page 103: Designing for Performance - JfokusUniversal Scalability Law 0 2 4 6 8 10 12 14 16 18 20 1 2 4 8 16 32 64 128 256 512 1024 Speedup Processors Amdahl USL](https://reader035.vdocuments.us/reader035/viewer/2022081607/5f01f1577e708231d401cc74/html5/thumbnails/103.jpg)
Source: Gil Tene (Azul Systems)
Coordinated Omission
![Page 104: Designing for Performance - JfokusUniversal Scalability Law 0 2 4 6 8 10 12 14 16 18 20 1 2 4 8 16 32 64 128 256 512 1024 Speedup Processors Amdahl USL](https://reader035.vdocuments.us/reader035/viewer/2022081607/5f01f1577e708231d401cc74/html5/thumbnails/104.jpg)
HdrHistogram
![Page 105: Designing for Performance - JfokusUniversal Scalability Law 0 2 4 6 8 10 12 14 16 18 20 1 2 4 8 16 32 64 128 256 512 1024 Speedup Processors Amdahl USL](https://reader035.vdocuments.us/reader035/viewer/2022081607/5f01f1577e708231d401cc74/html5/thumbnails/105.jpg)
JMH
(Java Microbenchmark Harness)
![Page 106: Designing for Performance - JfokusUniversal Scalability Law 0 2 4 6 8 10 12 14 16 18 20 1 2 4 8 16 32 64 128 256 512 1024 Speedup Processors Amdahl USL](https://reader035.vdocuments.us/reader035/viewer/2022081607/5f01f1577e708231d401cc74/html5/thumbnails/106.jpg)
CPU Performance Counters
![Page 107: Designing for Performance - JfokusUniversal Scalability Law 0 2 4 6 8 10 12 14 16 18 20 1 2 4 8 16 32 64 128 256 512 1024 Speedup Processors Amdahl USL](https://reader035.vdocuments.us/reader035/viewer/2022081607/5f01f1577e708231d401cc74/html5/thumbnails/107.jpg)
Performance test as part of
Continuous Integration
![Page 108: Designing for Performance - JfokusUniversal Scalability Law 0 2 4 6 8 10 12 14 16 18 20 1 2 4 8 16 32 64 128 256 512 1024 Speedup Processors Amdahl USL](https://reader035.vdocuments.us/reader035/viewer/2022081607/5f01f1577e708231d401cc74/html5/thumbnails/108.jpg)
Build telemetry into
production systems
![Page 109: Designing for Performance - JfokusUniversal Scalability Law 0 2 4 6 8 10 12 14 16 18 20 1 2 4 8 16 32 64 128 256 512 1024 Speedup Processors Amdahl USL](https://reader035.vdocuments.us/reader035/viewer/2022081607/5f01f1577e708231d401cc74/html5/thumbnails/109.jpg)
AGAIN!!!Build telemetry into
production systems
![Page 110: Designing for Performance - JfokusUniversal Scalability Law 0 2 4 6 8 10 12 14 16 18 20 1 2 4 8 16 32 64 128 256 512 1024 Speedup Processors Amdahl USL](https://reader035.vdocuments.us/reader035/viewer/2022081607/5f01f1577e708231d401cc74/html5/thumbnails/110.jpg)
Counters of:
• Queue Lengths
• Concurrent Users
• Exceptions
• Transactions - orders, trades
• Etc.
![Page 111: Designing for Performance - JfokusUniversal Scalability Law 0 2 4 6 8 10 12 14 16 18 20 1 2 4 8 16 32 64 128 256 512 1024 Speedup Processors Amdahl USL](https://reader035.vdocuments.us/reader035/viewer/2022081607/5f01f1577e708231d401cc74/html5/thumbnails/111.jpg)
Histograms of:
• Response Times
• Service Times
• Queue Lengths
• Concurrent Users
• Etc.
![Page 112: Designing for Performance - JfokusUniversal Scalability Law 0 2 4 6 8 10 12 14 16 18 20 1 2 4 8 16 32 64 128 256 512 1024 Speedup Processors Amdahl USL](https://reader035.vdocuments.us/reader035/viewer/2022081607/5f01f1577e708231d401cc74/html5/thumbnails/112.jpg)
In closing…
![Page 113: Designing for Performance - JfokusUniversal Scalability Law 0 2 4 6 8 10 12 14 16 18 20 1 2 4 8 16 32 64 128 256 512 1024 Speedup Processors Amdahl USL](https://reader035.vdocuments.us/reader035/viewer/2022081607/5f01f1577e708231d401cc74/html5/thumbnails/113.jpg)
Clean => Uncontaminated
![Page 114: Designing for Performance - JfokusUniversal Scalability Law 0 2 4 6 8 10 12 14 16 18 20 1 2 4 8 16 32 64 128 256 512 1024 Speedup Processors Amdahl USL](https://reader035.vdocuments.us/reader035/viewer/2022081607/5f01f1577e708231d401cc74/html5/thumbnails/114.jpg)
Representative => True Portrayal
![Page 115: Designing for Performance - JfokusUniversal Scalability Law 0 2 4 6 8 10 12 14 16 18 20 1 2 4 8 16 32 64 128 256 512 1024 Speedup Processors Amdahl USL](https://reader035.vdocuments.us/reader035/viewer/2022081607/5f01f1577e708231d401cc74/html5/thumbnails/115.jpg)
Measure – Don’t Guess!!!
![Page 116: Designing for Performance - JfokusUniversal Scalability Law 0 2 4 6 8 10 12 14 16 18 20 1 2 4 8 16 32 64 128 256 512 1024 Speedup Processors Amdahl USL](https://reader035.vdocuments.us/reader035/viewer/2022081607/5f01f1577e708231d401cc74/html5/thumbnails/116.jpg)
![Page 117: Designing for Performance - JfokusUniversal Scalability Law 0 2 4 6 8 10 12 14 16 18 20 1 2 4 8 16 32 64 128 256 512 1024 Speedup Processors Amdahl USL](https://reader035.vdocuments.us/reader035/viewer/2022081607/5f01f1577e708231d401cc74/html5/thumbnails/117.jpg)
Questions?
http://mechanical-sympathy.blogspot.com/
Twitter: @mjpt777
“It does not matter how intelligent you are, if you guess and that guess cannot be backed
up by experimental evidence –then it is still a guess.”
- Richard Feynman