129
Top Performance Myths and Folklore Martin Thompson - @mjpt777

Top Performance Myths and FolkloreTop Performance Myths and Folklore Martin Thompson - @mjpt777. Top Performance Myths and Folklore Martin Thompson - @mjpt777. Top 10 Performance Mistakes

  • Upload
    others

  • View
    7

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Top Performance Myths and FolkloreTop Performance Myths and Folklore Martin Thompson - @mjpt777. Top Performance Myths and Folklore Martin Thompson - @mjpt777. Top 10 Performance Mistakes

Top Performance

Myths and Folklore

Martin Thompson - @mjpt777

Page 2: Top Performance Myths and FolkloreTop Performance Myths and Folklore Martin Thompson - @mjpt777. Top Performance Myths and Folklore Martin Thompson - @mjpt777. Top 10 Performance Mistakes

Top Performance

Myths and Folklore

Martin Thompson - @mjpt777

Page 3: Top Performance Myths and FolkloreTop Performance Myths and Folklore Martin Thompson - @mjpt777. Top Performance Myths and Folklore Martin Thompson - @mjpt777. Top 10 Performance Mistakes

Top 10

Performance Mistakes

Martin Thompson - @mjpt777

Page 4: Top Performance Myths and FolkloreTop Performance Myths and Folklore Martin Thompson - @mjpt777. Top Performance Myths and Folklore Martin Thompson - @mjpt777. Top 10 Performance Mistakes
Page 5: Top Performance Myths and FolkloreTop Performance Myths and Folklore Martin Thompson - @mjpt777. Top Performance Myths and Folklore Martin Thompson - @mjpt777. Top 10 Performance Mistakes
Page 6: Top Performance Myths and FolkloreTop Performance Myths and Folklore Martin Thompson - @mjpt777. Top Performance Myths and Folklore Martin Thompson - @mjpt777. Top 10 Performance Mistakes

10

Page 7: Top Performance Myths and FolkloreTop Performance Myths and Folklore Martin Thompson - @mjpt777. Top Performance Myths and Folklore Martin Thompson - @mjpt777. Top 10 Performance Mistakes

Not Upgrading

Page 8: Top Performance Myths and FolkloreTop Performance Myths and Folklore Martin Thompson - @mjpt777. Top Performance Myths and Folklore Martin Thompson - @mjpt777. Top 10 Performance Mistakes
Page 9: Top Performance Myths and FolkloreTop Performance Myths and Folklore Martin Thompson - @mjpt777. Top Performance Myths and Folklore Martin Thompson - @mjpt777. Top 10 Performance Mistakes
Page 10: Top Performance Myths and FolkloreTop Performance Myths and Folklore Martin Thompson - @mjpt777. Top Performance Myths and Folklore Martin Thompson - @mjpt777. Top 10 Performance Mistakes

9

Page 11: Top Performance Myths and FolkloreTop Performance Myths and Folklore Martin Thompson - @mjpt777. Top Performance Myths and Folklore Martin Thompson - @mjpt777. Top 10 Performance Mistakes

Duplicated Work

Page 12: Top Performance Myths and FolkloreTop Performance Myths and Folklore Martin Thompson - @mjpt777. Top Performance Myths and Folklore Martin Thompson - @mjpt777. Top 10 Performance Mistakes

Database Tuning?

Page 13: Top Performance Myths and FolkloreTop Performance Myths and Folklore Martin Thompson - @mjpt777. Top Performance Myths and Folklore Martin Thompson - @mjpt777. Top 10 Performance Mistakes

Where is the real issue?

Page 14: Top Performance Myths and FolkloreTop Performance Myths and Folklore Martin Thompson - @mjpt777. Top Performance Myths and Folklore Martin Thompson - @mjpt777. Top 10 Performance Mistakes

8

Page 15: Top Performance Myths and FolkloreTop Performance Myths and Folklore Martin Thompson - @mjpt777. Top Performance Myths and Folklore Martin Thompson - @mjpt777. Top 10 Performance Mistakes

Data Dependent Loads

Page 16: Top Performance Myths and FolkloreTop Performance Myths and Folklore Martin Thompson - @mjpt777. Top Performance Myths and Folklore Martin Thompson - @mjpt777. Top 10 Performance Mistakes

Aka “Pointer Chasing”

Page 17: Top Performance Myths and FolkloreTop Performance Myths and Folklore Martin Thompson - @mjpt777. Top Performance Myths and Folklore Martin Thompson - @mjpt777. Top 10 Performance Mistakes

Are all memory

operations equal?

Page 18: Top Performance Myths and FolkloreTop Performance Myths and Folklore Martin Thompson - @mjpt777. Top Performance Myths and Folklore Martin Thompson - @mjpt777. Top 10 Performance Mistakes

Sequential Access

-

Average time in ns/op to sum all

longs in a 1GB array?

Page 19: Top Performance Myths and FolkloreTop Performance Myths and Folklore Martin Thompson - @mjpt777. Top Performance Myths and Folklore Martin Thompson - @mjpt777. Top 10 Performance Mistakes

Access Pattern Benchmark

Benchmark Mode Score Error Units

testSequential avgt 0.832 ± 0.006 ns/op

~1 ns/op

Page 20: Top Performance Myths and FolkloreTop Performance Myths and Folklore Martin Thompson - @mjpt777. Top Performance Myths and Folklore Martin Thompson - @mjpt777. Top 10 Performance Mistakes

Really???

Less than 1ns per operation?

Page 21: Top Performance Myths and FolkloreTop Performance Myths and Folklore Martin Thompson - @mjpt777. Top Performance Myths and Folklore Martin Thompson - @mjpt777. Top 10 Performance Mistakes
Page 22: Top Performance Myths and FolkloreTop Performance Myths and Folklore Martin Thompson - @mjpt777. Top Performance Myths and Folklore Martin Thompson - @mjpt777. Top 10 Performance Mistakes

Random walk per OS Page

-

Average time in ns/op to sum all

longs in a 1GB array?

Page 23: Top Performance Myths and FolkloreTop Performance Myths and Folklore Martin Thompson - @mjpt777. Top Performance Myths and Folklore Martin Thompson - @mjpt777. Top 10 Performance Mistakes

Access Pattern Benchmark

Benchmark Mode Score Error Units

testSequential avgt 0.832 ± 0.006 ns/op

testRandomPage avgt 2.703 ± 0.025 ns/op

~3 ns/op

Page 24: Top Performance Myths and FolkloreTop Performance Myths and Folklore Martin Thompson - @mjpt777. Top Performance Myths and Folklore Martin Thompson - @mjpt777. Top 10 Performance Mistakes

Data dependant walk per OS Page

-

Average time in ns/op to sum all

longs in a 1GB array?

Page 25: Top Performance Myths and FolkloreTop Performance Myths and Folklore Martin Thompson - @mjpt777. Top Performance Myths and Folklore Martin Thompson - @mjpt777. Top 10 Performance Mistakes

Access Pattern Benchmark

Benchmark Mode Score Error Units

testSequential avgt 0.832 ± 0.006 ns/op

testRandomPage avgt 2.703 ± 0.025 ns/op

testDependentRandomPage avgt 7.102 ± 0.326 ns/op

~7 ns/op

Page 26: Top Performance Myths and FolkloreTop Performance Myths and Folklore Martin Thompson - @mjpt777. Top Performance Myths and Folklore Martin Thompson - @mjpt777. Top 10 Performance Mistakes

Random heap walk

-

Average time in ns/op to sum all

longs in a 1GB array?

Page 27: Top Performance Myths and FolkloreTop Performance Myths and Folklore Martin Thompson - @mjpt777. Top Performance Myths and Folklore Martin Thompson - @mjpt777. Top 10 Performance Mistakes

Access Pattern Benchmark

Benchmark Mode Score Error Units

testSequential avgt 0.832 ± 0.006 ns/op

testRandomPage avgt 2.703 ± 0.025 ns/op

testDependentRandomPage avgt 7.102 ± 0.326 ns/op

testRandomHeap avgt 19.896 ± 3.110 ns/op

~20 ns/op

Page 28: Top Performance Myths and FolkloreTop Performance Myths and Folklore Martin Thompson - @mjpt777. Top Performance Myths and Folklore Martin Thompson - @mjpt777. Top 10 Performance Mistakes

Data dependant heap walk

-

Average time in ns/op to sum all

longs in a 1GB array?

Page 29: Top Performance Myths and FolkloreTop Performance Myths and Folklore Martin Thompson - @mjpt777. Top Performance Myths and Folklore Martin Thompson - @mjpt777. Top 10 Performance Mistakes

Access Pattern Benchmark

Benchmark Mode Score Error Units

testSequential avgt 0.832 ± 0.006 ns/op

testRandomPage avgt 2.703 ± 0.025 ns/op

testDependentRandomPage avgt 7.102 ± 0.326 ns/op

testRandomHeap avgt 19.896 ± 3.110 ns/op

testDependentRandomHeap avgt 89.516 ± 4.573 ns/op

~90 ns/op

Page 30: Top Performance Myths and FolkloreTop Performance Myths and Folklore Martin Thompson - @mjpt777. Top Performance Myths and Folklore Martin Thompson - @mjpt777. Top 10 Performance Mistakes

Need to ADD 40+ ns/opfor NUMA access on a server!!!

Page 31: Top Performance Myths and FolkloreTop Performance Myths and Folklore Martin Thompson - @mjpt777. Top Performance Myths and Folklore Martin Thompson - @mjpt777. Top 10 Performance Mistakes

Access Pattern Benchmark

Benchmark Mode Score Error Units

testSequential avgt 0.832 ± 0.006 ns/op

testRandomPage avgt 2.703 ± 0.025 ns/op

testDependentRandomPage avgt 7.102 ± 0.326 ns/op

testRandomHeap avgt 19.896 ± 3.110 ns/op

testDependentRandomHeap avgt 89.516 ± 4.573 ns/op

Page 32: Top Performance Myths and FolkloreTop Performance Myths and Folklore Martin Thompson - @mjpt777. Top Performance Myths and Folklore Martin Thompson - @mjpt777. Top 10 Performance Mistakes

What does this mean for

data structures?

Page 33: Top Performance Myths and FolkloreTop Performance Myths and Folklore Martin Thompson - @mjpt777. Top Performance Myths and Folklore Martin Thompson - @mjpt777. Top 10 Performance Mistakes

Buckets

Page 34: Top Performance Myths and FolkloreTop Performance Myths and Folklore Martin Thompson - @mjpt777. Top Performance Myths and Folklore Martin Thompson - @mjpt777. Top 10 Performance Mistakes

1

EUR/USD

Hash

Buckets

Key Value Next

Page 35: Top Performance Myths and FolkloreTop Performance Myths and Folklore Martin Thompson - @mjpt777. Top Performance Myths and Folklore Martin Thompson - @mjpt777. Top 10 Performance Mistakes

1

EUR/USD

Hash

Buckets

2 GBP/EUR

Key Value Next

HashKey Value Next

Page 36: Top Performance Myths and FolkloreTop Performance Myths and Folklore Martin Thompson - @mjpt777. Top Performance Myths and Folklore Martin Thompson - @mjpt777. Top 10 Performance Mistakes

1

EUR/USD

Hash

Buckets

2 GBP/EUR

Key Value Next

HashKey Value Next

3

GBP/USD

HashKey Value Next

Page 37: Top Performance Myths and FolkloreTop Performance Myths and Folklore Martin Thompson - @mjpt777. Top Performance Myths and Folklore Martin Thompson - @mjpt777. Top 10 Performance Mistakes

Buckets Key Value Hash Next

Page 38: Top Performance Myths and FolkloreTop Performance Myths and Folklore Martin Thompson - @mjpt777. Top Performance Myths and Folklore Martin Thompson - @mjpt777. Top 10 Performance Mistakes

0

1 EUR/USD 4 -1

Buckets Key Value Hash Next

Page 39: Top Performance Myths and FolkloreTop Performance Myths and Folklore Martin Thompson - @mjpt777. Top Performance Myths and Folklore Martin Thompson - @mjpt777. Top 10 Performance Mistakes

1

0

1 EUR/USD 4 -1

Buckets Key Value Hash Next

2 GBP/EUR 2 -1

Page 40: Top Performance Myths and FolkloreTop Performance Myths and Folklore Martin Thompson - @mjpt777. Top Performance Myths and Folklore Martin Thompson - @mjpt777. Top 10 Performance Mistakes

1

0

1 EUR/USD 4 2

Buckets Key Value Hash Next

2 GBP/EUR 2 -1

3 GBP/USD 4 -1

Page 41: Top Performance Myths and FolkloreTop Performance Myths and Folklore Martin Thompson - @mjpt777. Top Performance Myths and Folklore Martin Thompson - @mjpt777. Top 10 Performance Mistakes

.net Dictionary is >10X faster than

HashMap for 2+ GB of data

Page 42: Top Performance Myths and FolkloreTop Performance Myths and Folklore Martin Thompson - @mjpt777. Top Performance Myths and Folklore Martin Thompson - @mjpt777. Top 10 Performance Mistakes

Understand object relationships

and then choose appropriate

data structures

Page 43: Top Performance Myths and FolkloreTop Performance Myths and Folklore Martin Thompson - @mjpt777. Top Performance Myths and Folklore Martin Thompson - @mjpt777. Top 10 Performance Mistakes

Java desperately needs

Value Types on the stack

and Aggregates on the heap

Page 44: Top Performance Myths and FolkloreTop Performance Myths and Folklore Martin Thompson - @mjpt777. Top Performance Myths and Folklore Martin Thompson - @mjpt777. Top 10 Performance Mistakes

Data Structures are becoming

evermore important again!

Page 45: Top Performance Myths and FolkloreTop Performance Myths and Folklore Martin Thompson - @mjpt777. Top Performance Myths and Folklore Martin Thompson - @mjpt777. Top 10 Performance Mistakes

7

Page 46: Top Performance Myths and FolkloreTop Performance Myths and Folklore Martin Thompson - @mjpt777. Top Performance Myths and Folklore Martin Thompson - @mjpt777. Top 10 Performance Mistakes

Too Much Allocation

Page 47: Top Performance Myths and FolkloreTop Performance Myths and Folklore Martin Thompson - @mjpt777. Top Performance Myths and Folklore Martin Thompson - @mjpt777. Top 10 Performance Mistakes

“Allocation is free…”

Page 48: Top Performance Myths and FolkloreTop Performance Myths and Folklore Martin Thompson - @mjpt777. Top Performance Myths and Folklore Martin Thompson - @mjpt777. Top 10 Performance Mistakes

Reclamation is NOT free!

Page 49: Top Performance Myths and FolkloreTop Performance Myths and Folklore Martin Thompson - @mjpt777. Top Performance Myths and Folklore Martin Thompson - @mjpt777. Top 10 Performance Mistakes

Remember

Data Dependent Loads?

Page 50: Top Performance Myths and FolkloreTop Performance Myths and Folklore Martin Thompson - @mjpt777. Top Performance Myths and Folklore Martin Thompson - @mjpt777. Top 10 Performance Mistakes

Too much allocation or copying

will wash out your cache

Page 51: Top Performance Myths and FolkloreTop Performance Myths and Folklore Martin Thompson - @mjpt777. Top Performance Myths and Folklore Martin Thompson - @mjpt777. Top 10 Performance Mistakes

6

Page 52: Top Performance Myths and FolkloreTop Performance Myths and Folklore Martin Thompson - @mjpt777. Top Performance Myths and Folklore Martin Thompson - @mjpt777. Top 10 Performance Mistakes

Going Parallel

Page 53: Top Performance Myths and FolkloreTop Performance Myths and Folklore Martin Thompson - @mjpt777. Top Performance Myths and Folklore Martin Thompson - @mjpt777. Top 10 Performance Mistakes

http://www.frankmcsherry.org/assets/COST.pdf

Page 54: Top Performance Myths and FolkloreTop Performance Myths and Folklore Martin Thompson - @mjpt777. Top Performance Myths and Folklore Martin Thompson - @mjpt777. Top 10 Performance Mistakes

Amdahl’s 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

Page 55: Top Performance Myths and FolkloreTop Performance Myths and Folklore Martin Thompson - @mjpt777. Top Performance Myths and Folklore Martin Thompson - @mjpt777. Top 10 Performance Mistakes

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 56: Top Performance Myths and FolkloreTop Performance Myths and Folklore Martin Thompson - @mjpt777. Top Performance Myths and Folklore Martin Thompson - @mjpt777. Top 10 Performance Mistakes

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 57: Top Performance Myths and FolkloreTop Performance Myths and Folklore Martin Thompson - @mjpt777. Top Performance Myths and Folklore Martin Thompson - @mjpt777. Top 10 Performance Mistakes

Shared mutable state is Evil!

Page 58: Top Performance Myths and FolkloreTop Performance Myths and Folklore Martin Thompson - @mjpt777. Top Performance Myths and Folklore Martin Thompson - @mjpt777. Top 10 Performance Mistakes

“You can have a second

computer once you’ve shown

you know how to use the first one”

– Paul Barham

Page 59: Top Performance Myths and FolkloreTop Performance Myths and Folklore Martin Thompson - @mjpt777. Top Performance Myths and Folklore Martin Thompson - @mjpt777. Top 10 Performance Mistakes

“You can have a second CPU

once you’ve shown you know

how to use the first one”

– Martin Thompson

Page 60: Top Performance Myths and FolkloreTop Performance Myths and Folklore Martin Thompson - @mjpt777. Top Performance Myths and Folklore Martin Thompson - @mjpt777. Top 10 Performance Mistakes

5

Page 61: Top Performance Myths and FolkloreTop Performance Myths and Folklore Martin Thompson - @mjpt777. Top Performance Myths and Folklore Martin Thompson - @mjpt777. Top 10 Performance Mistakes

Not Understanding TCP

Page 62: Top Performance Myths and FolkloreTop Performance Myths and Folklore Martin Thompson - @mjpt777. Top Performance Myths and Folklore Martin Thompson - @mjpt777. Top 10 Performance Mistakes

TCP – Sequenced Flow 1

Client Server

Page 63: Top Performance Myths and FolkloreTop Performance Myths and Folklore Martin Thompson - @mjpt777. Top Performance Myths and Folklore Martin Thompson - @mjpt777. Top 10 Performance Mistakes

TCP – Sequenced Flow 1

Client Server

SYN

Page 64: Top Performance Myths and FolkloreTop Performance Myths and Folklore Martin Thompson - @mjpt777. Top Performance Myths and Folklore Martin Thompson - @mjpt777. Top 10 Performance Mistakes

TCP – Sequenced Flow 1

Client Server

SYN

SYN, ACK

Page 65: Top Performance Myths and FolkloreTop Performance Myths and Folklore Martin Thompson - @mjpt777. Top Performance Myths and Folklore Martin Thompson - @mjpt777. Top 10 Performance Mistakes

TCP – Sequenced Flow 1

Client Server

SYN

SYN, ACK

ACK

Page 66: Top Performance Myths and FolkloreTop Performance Myths and Folklore Martin Thompson - @mjpt777. Top Performance Myths and Folklore Martin Thompson - @mjpt777. Top 10 Performance Mistakes

TCP – Sequenced Flow 1

Client Server

SYN

SYN, ACK

ACK

Data == MSS

Page 67: Top Performance Myths and FolkloreTop Performance Myths and Folklore Martin Thompson - @mjpt777. Top Performance Myths and Folklore Martin Thompson - @mjpt777. Top 10 Performance Mistakes

TCP – Sequenced Flow 1

Client Server

SYN

SYN, ACK

ACK

Data == MSS

Page 68: Top Performance Myths and FolkloreTop Performance Myths and Folklore Martin Thompson - @mjpt777. Top Performance Myths and Folklore Martin Thompson - @mjpt777. Top 10 Performance Mistakes

TCP – Sequenced Flow 1

Client Server

SYN

SYN, ACK

ACK

Data == MSS

Delayed ACK

Page 69: Top Performance Myths and FolkloreTop Performance Myths and Folklore Martin Thompson - @mjpt777. Top Performance Myths and Folklore Martin Thompson - @mjpt777. Top 10 Performance Mistakes

TCP – Sequenced Flow 1

Client Server

SYN

SYN, ACK

ACK

Data == MSS

Delayed ACK

Data < MSS

Page 70: Top Performance Myths and FolkloreTop Performance Myths and Folklore Martin Thompson - @mjpt777. Top Performance Myths and Folklore Martin Thompson - @mjpt777. Top 10 Performance Mistakes

TCP – Sequenced Flow – TCP_NODELAY

Client Server

SYN

SYN, ACK

ACK

Page 71: Top Performance Myths and FolkloreTop Performance Myths and Folklore Martin Thompson - @mjpt777. Top Performance Myths and Folklore Martin Thompson - @mjpt777. Top 10 Performance Mistakes

TCP – Sequenced Flow – TCP_NODELAY

Client Server

SYN

SYN, ACK

ACK

Data == MSS

Page 72: Top Performance Myths and FolkloreTop Performance Myths and Folklore Martin Thompson - @mjpt777. Top Performance Myths and Folklore Martin Thompson - @mjpt777. Top 10 Performance Mistakes

TCP – Sequenced Flow – TCP_NODELAY

Client Server

SYN

SYN, ACK

ACK

Data == MSS

Data < MSS

Page 73: Top Performance Myths and FolkloreTop Performance Myths and Folklore Martin Thompson - @mjpt777. Top Performance Myths and Folklore Martin Thompson - @mjpt777. Top 10 Performance Mistakes

TCP – Sequenced Flow – TCP_NODELAY

Client Server

SYN

SYN, ACK

ACK

Data == MSS

ACK

Data < MSS

Page 74: Top Performance Myths and FolkloreTop Performance Myths and Folklore Martin Thompson - @mjpt777. Top Performance Myths and Folklore Martin Thompson - @mjpt777. Top 10 Performance Mistakes

4

Page 75: Top Performance Myths and FolkloreTop Performance Myths and Folklore Martin Thompson - @mjpt777. Top Performance Myths and Folklore Martin Thompson - @mjpt777. Top 10 Performance Mistakes

Synchronous Communications

Page 76: Top Performance Myths and FolkloreTop Performance Myths and Folklore Martin Thompson - @mjpt777. Top Performance Myths and Folklore Martin Thompson - @mjpt777. Top 10 Performance Mistakes

Client Server

Page 77: Top Performance Myths and FolkloreTop Performance Myths and Folklore Martin Thompson - @mjpt777. Top Performance Myths and Folklore Martin Thompson - @mjpt777. Top 10 Performance Mistakes

Client Server

Page 78: Top Performance Myths and FolkloreTop Performance Myths and Folklore Martin Thompson - @mjpt777. Top Performance Myths and Folklore Martin Thompson - @mjpt777. Top 10 Performance Mistakes

Client Server

Page 79: Top Performance Myths and FolkloreTop Performance Myths and Folklore Martin Thompson - @mjpt777. Top Performance Myths and Folklore Martin Thompson - @mjpt777. Top 10 Performance Mistakes

Client Server

Page 80: Top Performance Myths and FolkloreTop Performance Myths and Folklore Martin Thompson - @mjpt777. Top Performance Myths and Folklore Martin Thompson - @mjpt777. Top 10 Performance Mistakes

Client Server

Page 81: Top Performance Myths and FolkloreTop Performance Myths and Folklore Martin Thompson - @mjpt777. Top Performance Myths and Folklore Martin Thompson - @mjpt777. Top 10 Performance Mistakes

Client Server

Page 82: Top Performance Myths and FolkloreTop Performance Myths and Folklore Martin Thompson - @mjpt777. Top Performance Myths and Folklore Martin Thompson - @mjpt777. Top 10 Performance Mistakes

Client Server

Page 83: Top Performance Myths and FolkloreTop Performance Myths and Folklore Martin Thompson - @mjpt777. Top Performance Myths and Folklore Martin Thompson - @mjpt777. Top 10 Performance Mistakes

Asynchronous Communications

Page 84: Top Performance Myths and FolkloreTop Performance Myths and Folklore Martin Thompson - @mjpt777. Top Performance Myths and Folklore Martin Thompson - @mjpt777. Top 10 Performance Mistakes

Client Server

Page 85: Top Performance Myths and FolkloreTop Performance Myths and Folklore Martin Thompson - @mjpt777. Top Performance Myths and Folklore Martin Thompson - @mjpt777. Top 10 Performance Mistakes

Client Server

Page 86: Top Performance Myths and FolkloreTop Performance Myths and Folklore Martin Thompson - @mjpt777. Top Performance Myths and Folklore Martin Thompson - @mjpt777. Top 10 Performance Mistakes

Client Server

Page 87: Top Performance Myths and FolkloreTop Performance Myths and Folklore Martin Thompson - @mjpt777. Top Performance Myths and Folklore Martin Thompson - @mjpt777. Top 10 Performance Mistakes

Client Server

Page 88: Top Performance Myths and FolkloreTop Performance Myths and Folklore Martin Thompson - @mjpt777. Top Performance Myths and Folklore Martin Thompson - @mjpt777. Top 10 Performance Mistakes

Client Server

Page 89: Top Performance Myths and FolkloreTop Performance Myths and Folklore Martin Thompson - @mjpt777. Top Performance Myths and Folklore Martin Thompson - @mjpt777. Top 10 Performance Mistakes

Client Server

Page 90: Top Performance Myths and FolkloreTop Performance Myths and Folklore Martin Thompson - @mjpt777. Top Performance Myths and Folklore Martin Thompson - @mjpt777. Top 10 Performance Mistakes

Client Server

Page 91: Top Performance Myths and FolkloreTop Performance Myths and Folklore Martin Thompson - @mjpt777. Top Performance Myths and Folklore Martin Thompson - @mjpt777. Top 10 Performance Mistakes

Synchronous Communications

is the crystal meth

of distributed computing

Page 92: Top Performance Myths and FolkloreTop Performance Myths and Folklore Martin Thompson - @mjpt777. Top Performance Myths and Folklore Martin Thompson - @mjpt777. Top 10 Performance Mistakes

3

Page 93: Top Performance Myths and FolkloreTop Performance Myths and Folklore Martin Thompson - @mjpt777. Top Performance Myths and Folklore Martin Thompson - @mjpt777. Top 10 Performance Mistakes

Text Encoding

Page 94: Top Performance Myths and FolkloreTop Performance Myths and Folklore Martin Thompson - @mjpt777. Top Performance Myths and Folklore Martin Thompson - @mjpt777. Top 10 Performance Mistakes
Page 95: Top Performance Myths and FolkloreTop Performance Myths and Folklore Martin Thompson - @mjpt777. Top Performance Myths and Folklore Martin Thompson - @mjpt777. Top 10 Performance Mistakes

“But it’s human readable...”

Page 96: Top Performance Myths and FolkloreTop Performance Myths and Folklore Martin Thompson - @mjpt777. Top Performance Myths and Folklore Martin Thompson - @mjpt777. Top 10 Performance Mistakes

“Binary is hard to work with...”

Page 97: Top Performance Myths and FolkloreTop Performance Myths and Folklore Martin Thompson - @mjpt777. Top Performance Myths and Folklore Martin Thompson - @mjpt777. Top 10 Performance Mistakes
Page 98: Top Performance Myths and FolkloreTop Performance Myths and Folklore Martin Thompson - @mjpt777. Top Performance Myths and Folklore Martin Thompson - @mjpt777. Top 10 Performance Mistakes

while (i >= 0)

{

int remainder = quotient % 10;

quotient = quotient / 10;

results[i--] = (byte)('0' + remainder);

}

Page 99: Top Performance Myths and FolkloreTop Performance Myths and Folklore Martin Thompson - @mjpt777. Top Performance Myths and Folklore Martin Thompson - @mjpt777. Top 10 Performance Mistakes

Communications

Battery life and bandwidth?

Page 100: Top Performance Myths and FolkloreTop Performance Myths and Folklore Martin Thompson - @mjpt777. Top Performance Myths and Folklore Martin Thompson - @mjpt777. Top 10 Performance Mistakes

2

Page 101: Top Performance Myths and FolkloreTop Performance Myths and Folklore Martin Thompson - @mjpt777. Top Performance Myths and Folklore Martin Thompson - @mjpt777. Top 10 Performance Mistakes

API Design

Page 102: Top Performance Myths and FolkloreTop Performance Myths and Folklore Martin Thompson - @mjpt777. Top Performance Myths and Folklore Martin Thompson - @mjpt777. Top 10 Performance Mistakes

public void characters(

char[] ch,

int start,

int length) throws SAXException

Page 103: Top Performance Myths and FolkloreTop Performance Myths and Folklore Martin Thompson - @mjpt777. Top Performance Myths and Folklore Martin Thompson - @mjpt777. Top 10 Performance Mistakes

public void characters(

char[] ch,

int start,

int length) throws SAXException

public void startElement(

String uri,

String localName,

String qName,

Attributes atts) throws SAXException

Page 104: Top Performance Myths and FolkloreTop Performance Myths and Folklore Martin Thompson - @mjpt777. Top Performance Myths and Folklore Martin Thompson - @mjpt777. Top 10 Performance Mistakes

API Design can be composed for

usability vs performance trade offs

Page 105: Top Performance Myths and FolkloreTop Performance Myths and Folklore Martin Thompson - @mjpt777. Top Performance Myths and Folklore Martin Thompson - @mjpt777. Top 10 Performance Mistakes

public String[] split(String regex)

Page 106: Top Performance Myths and FolkloreTop Performance Myths and Folklore Martin Thompson - @mjpt777. Top Performance Myths and Folklore Martin Thompson - @mjpt777. Top 10 Performance Mistakes

public String[] split(String regex)

public Iterable<String> split(String regex)

Page 107: Top Performance Myths and FolkloreTop Performance Myths and Folklore Martin Thompson - @mjpt777. Top Performance Myths and Folklore Martin Thompson - @mjpt777. Top 10 Performance Mistakes

public String[] split(String regex)

public Iterable<String> split(String regex)

public void split(

String regex, Collection<String> dst)

Page 108: Top Performance Myths and FolkloreTop Performance Myths and Folklore Martin Thompson - @mjpt777. Top Performance Myths and Folklore Martin Thompson - @mjpt777. Top 10 Performance Mistakes

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 109: Top Performance Myths and FolkloreTop Performance Myths and Folklore Martin Thompson - @mjpt777. Top Performance Myths and Folklore Martin Thompson - @mjpt777. Top 10 Performance Mistakes

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 110: Top Performance Myths and FolkloreTop Performance Myths and Folklore Martin Thompson - @mjpt777. Top Performance Myths and Folklore Martin Thompson - @mjpt777. Top 10 Performance Mistakes

// Keep and reuse

List<SelectionKey> keys = new ArrayList<>();

selector.selectNow(keys, READABLE);

keys.forEach(keyHandler);

Page 111: Top Performance Myths and FolkloreTop Performance Myths and Folklore Martin Thompson - @mjpt777. Top Performance Myths and Folklore Martin Thompson - @mjpt777. Top 10 Performance Mistakes

1

Page 112: Top Performance Myths and FolkloreTop Performance Myths and Folklore Martin Thompson - @mjpt777. Top Performance Myths and Folklore Martin Thompson - @mjpt777. Top 10 Performance Mistakes

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

ose

con

ds)

Page 113: Top Performance Myths and FolkloreTop Performance Myths and Folklore Martin Thompson - @mjpt777. Top Performance Myths and Folklore Martin Thompson - @mjpt777. Top 10 Performance Mistakes

Average (Mean) Logging Duration

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

ose

con

ds)

Page 114: Top Performance Myths and FolkloreTop Performance Myths and Folklore Martin Thompson - @mjpt777. Top Performance Myths and Folklore Martin Thompson - @mjpt777. Top 10 Performance Mistakes

Why do we Log?

Page 115: Top Performance Myths and FolkloreTop Performance Myths and Folklore Martin Thompson - @mjpt777. Top Performance Myths and Folklore Martin Thompson - @mjpt777. Top 10 Performance Mistakes

Recording Events

Recording Errors

Instrumentation

Debugging

Page 116: Top Performance Myths and FolkloreTop Performance Myths and Folklore Martin Thompson - @mjpt777. Top Performance Myths and Folklore Martin Thompson - @mjpt777. Top 10 Performance Mistakes

Recording Events

Page 117: Top Performance Myths and FolkloreTop Performance Myths and Folklore Martin Thompson - @mjpt777. Top Performance Myths and Folklore Martin Thompson - @mjpt777. Top 10 Performance Mistakes
Page 118: Top Performance Myths and FolkloreTop Performance Myths and Folklore Martin Thompson - @mjpt777. Top Performance Myths and Folklore Martin Thompson - @mjpt777. Top 10 Performance Mistakes

Big Data

Page 119: Top Performance Myths and FolkloreTop Performance Myths and Folklore Martin Thompson - @mjpt777. Top Performance Myths and Folklore Martin Thompson - @mjpt777. Top 10 Performance Mistakes

Recording Errors

Page 120: Top Performance Myths and FolkloreTop Performance Myths and Folklore Martin Thompson - @mjpt777. Top Performance Myths and Folklore Martin Thompson - @mjpt777. Top 10 Performance Mistakes

public class DistinctErrorLog

{

public void record(Throwable observation)

Page 121: Top Performance Myths and FolkloreTop Performance Myths and Folklore Martin Thompson - @mjpt777. Top Performance Myths and Folklore Martin Thompson - @mjpt777. Top 10 Performance Mistakes

Instrumentation

Page 122: Top Performance Myths and FolkloreTop Performance Myths and Folklore Martin Thompson - @mjpt777. Top Performance Myths and Folklore Martin Thompson - @mjpt777. Top 10 Performance Mistakes

systemCounters.get(FAILED_LOGIN).increment();

Page 123: Top Performance Myths and FolkloreTop Performance Myths and Folklore Martin Thompson - @mjpt777. Top Performance Myths and Folklore Martin Thompson - @mjpt777. Top 10 Performance Mistakes

Debugging

Page 124: Top Performance Myths and FolkloreTop Performance Myths and Folklore Martin Thompson - @mjpt777. Top Performance Myths and Folklore Martin Thompson - @mjpt777. Top 10 Performance Mistakes

Byte Buddy

Page 125: Top Performance Myths and FolkloreTop Performance Myths and Folklore Martin Thompson - @mjpt777. Top Performance Myths and Folklore Martin Thompson - @mjpt777. Top 10 Performance Mistakes

In Closing…

Page 126: Top Performance Myths and FolkloreTop Performance Myths and Folklore Martin Thompson - @mjpt777. Top Performance Myths and Folklore Martin Thompson - @mjpt777. Top 10 Performance Mistakes

Where are you spending you

Computing Resource Budget?

Page 127: Top Performance Myths and FolkloreTop Performance Myths and Folklore Martin Thompson - @mjpt777. Top Performance Myths and Folklore Martin Thompson - @mjpt777. Top 10 Performance Mistakes

Run a profiler regularly!!!

Page 128: Top Performance Myths and FolkloreTop Performance Myths and Folklore Martin Thompson - @mjpt777. Top Performance Myths and Folklore Martin Thompson - @mjpt777. Top 10 Performance Mistakes
Page 129: Top Performance Myths and FolkloreTop Performance Myths and Folklore Martin Thompson - @mjpt777. Top Performance Myths and Folklore Martin Thompson - @mjpt777. Top 10 Performance Mistakes

Blog: http://mechanical-sympathy.blogspot.com/

Twitter: @mjpt777

“Any intelligent fool can make things bigger, more complex, and more violent.

It takes a touch of genius, and a lot of courage, to move in the opposite direction.”

- Albert Einstein

Questions?