designing for performance - jfokusuniversal scalability law 0 2 4 6 8 10 12 14 16 18 20 1 2 4 8 16...

117
Designing for Performance Martin Thompson - @mjpt777

Upload: others

Post on 04-Jun-2020

0 views

Category:

Documents


0 download

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

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

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

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

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

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

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

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

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

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
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

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

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

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

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

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

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

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

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

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

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

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

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

- 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

- 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

- 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

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

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

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

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

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

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

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

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

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
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

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

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

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

“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

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

- 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

- 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

- 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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// 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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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
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

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