Myths and Folklore Martin Thompson - @mjpt777 Top Performance - - PowerPoint PPT Presentation

myths and folklore
SMART_READER_LITE
LIVE PREVIEW

Myths and Folklore Martin Thompson - @mjpt777 Top Performance - - PowerPoint PPT Presentation

Top Performance Myths and Folklore Martin Thompson - @mjpt777 Top Performance Myths and Folklore Martin Thompson - @mjpt777 Top 10 Performance Mistakes Martin Thompson - @mjpt777 10 Not Upgrading 9 Duplicated Work Database Tuning?


slide-1
SLIDE 1

Top Performance Myths and Folklore

Martin Thompson - @mjpt777

slide-2
SLIDE 2

Top Performance Myths and Folklore

Martin Thompson - @mjpt777

slide-3
SLIDE 3

Top 10 Performance Mistakes

Martin Thompson - @mjpt777

slide-4
SLIDE 4
slide-5
SLIDE 5
slide-6
SLIDE 6

10

slide-7
SLIDE 7

Not Upgrading

slide-8
SLIDE 8
slide-9
SLIDE 9
slide-10
SLIDE 10

9

slide-11
SLIDE 11

Duplicated Work

slide-12
SLIDE 12

Database Tuning?

slide-13
SLIDE 13

Where is the real issue?

slide-14
SLIDE 14

8

slide-15
SLIDE 15

Data Dependent Loads

slide-16
SLIDE 16

Aka “Pointer Chasing”

slide-17
SLIDE 17

Are all memory

  • perations equal?
slide-18
SLIDE 18

Sequential Access

  • Average time in ns/op to sum all

longs in a 1GB array?

slide-19
SLIDE 19

Access Pattern Benchmark

Benchmark Mode Score Error Units testSequential avgt 0.832 ± 0.006 ns/op

~1 ns/op

slide-20
SLIDE 20

Really??? Less than 1ns per operation?

slide-21
SLIDE 21
slide-22
SLIDE 22

Random walk per OS Page

  • Average time in ns/op to sum all

longs in a 1GB array?

slide-23
SLIDE 23

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

slide-24
SLIDE 24

Data dependant walk per OS Page

  • Average time in ns/op to sum all

longs in a 1GB array?

slide-25
SLIDE 25

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

slide-26
SLIDE 26

Random heap walk

  • Average time in ns/op to sum all

longs in a 1GB array?

slide-27
SLIDE 27

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

slide-28
SLIDE 28

Data dependant heap walk

  • Average time in ns/op to sum all

longs in a 1GB array?

slide-29
SLIDE 29

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

slide-30
SLIDE 30

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

slide-31
SLIDE 31

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

slide-32
SLIDE 32

What does this mean for data structures?

slide-33
SLIDE 33

Buckets

slide-34
SLIDE 34

1 EUR/USD Hash Buckets Key Value Next

slide-35
SLIDE 35

1 EUR/USD Hash Buckets 2 GBP/EUR Key Value Next Hash Key Value Next

slide-36
SLIDE 36

1 EUR/USD Hash Buckets 2 GBP/EUR Key Value Next Hash Key Value Next 3 GBP/USD Hash Key Value Next

slide-37
SLIDE 37

Buckets Key Value Hash Next

slide-38
SLIDE 38

1 EUR/USD 4

  • 1

Buckets Key Value Hash Next

slide-39
SLIDE 39

1 1 EUR/USD 4

  • 1

Buckets Key Value Hash Next 2 GBP/EUR 2

  • 1
slide-40
SLIDE 40

1 1 EUR/USD 4 2 Buckets Key Value Hash Next 2 GBP/EUR 2

  • 1

3 GBP/USD 4

  • 1
slide-41
SLIDE 41

.net Dictionary is >10X faster than HashMap for 2+ GB of data

slide-42
SLIDE 42

Understand object relationships and then choose appropriate data structures

slide-43
SLIDE 43

Java desperately needs Value Types on the stack and Aggregates on the heap

slide-44
SLIDE 44

Data Structures are becoming evermore important again!

slide-45
SLIDE 45

7

slide-46
SLIDE 46

Too Much Allocation

slide-47
SLIDE 47

“Allocation is free…”

slide-48
SLIDE 48

Reclamation is NOT free!

slide-49
SLIDE 49

Remember Data Dependent Loads?

slide-50
SLIDE 50

Too much allocation or copying will wash out your cache

slide-51
SLIDE 51

6

slide-52
SLIDE 52

Going Parallel

slide-53
SLIDE 53

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

slide-54
SLIDE 54

Amdahl’s Law

2 4 6 8 10 12 14 16 18 20 1 2 4 8 16 32 64 128 256 512 1024

Speedup Processors

Amdahl

slide-55
SLIDE 55

Universal Scalability Law

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

slide-56
SLIDE 56

Universal Scalability Law

C(N) = N / (1 + α(N – 1) + ((β* N) * (N – 1)))

C = capacity or throughput N = number of processors α = contention penalty β = coherence penalty

slide-57
SLIDE 57

Shared mutable state is Evil!

slide-58
SLIDE 58

“You can have a second computer once you’ve shown you know how to use the first one” – Paul Barham

slide-59
SLIDE 59

“You can have a second CPU

  • nce you’ve shown you know

how to use the first one” – Martin Thompson

slide-60
SLIDE 60

5

slide-61
SLIDE 61

Not Understanding TCP

slide-62
SLIDE 62

TCP – Sequenced Flow 1

Client Server

slide-63
SLIDE 63

TCP – Sequenced Flow 1

Client Server

SYN

slide-64
SLIDE 64

TCP – Sequenced Flow 1

Client Server

SYN SYN, ACK

slide-65
SLIDE 65

TCP – Sequenced Flow 1

Client Server

SYN SYN, ACK ACK

slide-66
SLIDE 66

TCP – Sequenced Flow 1

Client Server

SYN SYN, ACK ACK Data == MSS

slide-67
SLIDE 67

TCP – Sequenced Flow 1

Client Server

SYN SYN, ACK ACK Data == MSS

slide-68
SLIDE 68

TCP – Sequenced Flow 1

Client Server

SYN SYN, ACK ACK Data == MSS Delayed ACK

slide-69
SLIDE 69

TCP – Sequenced Flow 1

Client Server

SYN SYN, ACK ACK Data == MSS Delayed ACK Data < MSS

slide-70
SLIDE 70

TCP – Sequenced Flow – TCP_NODELAY

Client Server

SYN SYN, ACK ACK

slide-71
SLIDE 71

TCP – Sequenced Flow – TCP_NODELAY

Client Server

SYN SYN, ACK ACK Data == MSS

slide-72
SLIDE 72

TCP – Sequenced Flow – TCP_NODELAY

Client Server

SYN SYN, ACK ACK Data == MSS Data < MSS

slide-73
SLIDE 73

TCP – Sequenced Flow – TCP_NODELAY

Client Server

SYN SYN, ACK ACK Data == MSS ACK Data < MSS

slide-74
SLIDE 74

4

slide-75
SLIDE 75

Synchronous Communications

slide-76
SLIDE 76

Client Server

slide-77
SLIDE 77

Client Server

slide-78
SLIDE 78

Client Server

slide-79
SLIDE 79

Client Server

slide-80
SLIDE 80

Client Server

slide-81
SLIDE 81

Client Server

slide-82
SLIDE 82

Client Server

slide-83
SLIDE 83

Asynchronous Communications

slide-84
SLIDE 84

Client Server

slide-85
SLIDE 85

Client Server

slide-86
SLIDE 86

Client Server

slide-87
SLIDE 87

Client Server

slide-88
SLIDE 88

Client Server

slide-89
SLIDE 89

Client Server

slide-90
SLIDE 90

Client Server

slide-91
SLIDE 91

Synchronous Communications is the crystal meth

  • f distributed computing
slide-92
SLIDE 92

3

slide-93
SLIDE 93

Text Encoding

slide-94
SLIDE 94
slide-95
SLIDE 95

“But it’s human readable...”

slide-96
SLIDE 96

“Binary is hard to work with...”

slide-97
SLIDE 97
slide-98
SLIDE 98

while (i >= 0) { int remainder = quotient % 10; quotient = quotient / 10; results[i--] = (byte)('0' + remainder); }

slide-99
SLIDE 99

Communications Battery life and bandwidth?

slide-100
SLIDE 100

2

slide-101
SLIDE 101

API Design

slide-102
SLIDE 102

public void characters( char[] ch, int start, int length) throws SAXException

slide-103
SLIDE 103

public void characters( char[] ch, int start, int length) throws SAXException public void startElement( String uri, String localName, String qName, Attributes atts) throws SAXException

slide-104
SLIDE 104

API Design can be composed for usability vs performance trade offs

slide-105
SLIDE 105

public String[] split(String regex)

slide-106
SLIDE 106

public String[] split(String regex) public Iterable<String> split(String regex)

slide-107
SLIDE 107

public String[] split(String regex) public Iterable<String> split(String regex) public void split( String regex, Collection<String> dst)

slide-108
SLIDE 108

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(); }

slide-109
SLIDE 109

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(); }

slide-110
SLIDE 110

// Keep and reuse List<SelectionKey> keys = new ArrayList<>(); selector.selectNow(keys, READABLE); keys.forEach(keyHandler);

slide-111
SLIDE 111

1

slide-112
SLIDE 112

20,000 40,000 60,000 80,000 100,000 120,000 140,000 160,000 1 2 3 4 5 6 7 8 Time (nanoseconds)

slide-113
SLIDE 113

Average (Mean) Logging Duration

20,000 40,000 60,000 80,000 100,000 120,000 140,000 160,000 1 2 3 4 5 6 7 8 Time (nanoseconds)

slide-114
SLIDE 114

Why do we Log?

slide-115
SLIDE 115

Recording Events Recording Errors Instrumentation Debugging

slide-116
SLIDE 116

Recording Events

slide-117
SLIDE 117
slide-118
SLIDE 118

Big Data

slide-119
SLIDE 119

Recording Errors

slide-120
SLIDE 120

public class DistinctErrorLog { public void record(Throwable observation)

slide-121
SLIDE 121

Instrumentation

slide-122
SLIDE 122

systemCounters.get(FAILED_LOGIN).increment();

slide-123
SLIDE 123

Debugging

slide-124
SLIDE 124

Byte Buddy

slide-125
SLIDE 125

In Closing…

slide-126
SLIDE 126

Where are you spending you Computing Resource Budget?

slide-127
SLIDE 127

Run a profiler regularly!!!

slide-128
SLIDE 128
slide-129
SLIDE 129

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?