20140228 fp and_performance

31
FP and Performance Beyond Big “O” Notation Jamie Allen Director of Consulting

Upload: shinolajla

Post on 26-Jan-2015

117 views

Category:

Documents


0 download

DESCRIPTION

 

TRANSCRIPT

Page 1: 20140228 fp and_performance

FP and PerformanceBeyond Big

“O” NotationJamie Allen

Director of Consulting

Page 2: 20140228 fp and_performance

Who Am I?

2

• Director of Consulting for

• Author of Effective Akka

@jamie_allen

Page 3: 20140228 fp and_performance

Big “O” Notation

3

Page 4: 20140228 fp and_performance

Many Developers Don’t Look Further

4

Page 5: 20140228 fp and_performance

Reactive Applications

5

Page 6: 20140228 fp and_performance

What is Performance?

6

Throughput

Latency

Footprint

Page 7: 20140228 fp and_performance

Power Consumption!

7

Page 8: 20140228 fp and_performance

There are no standards

The only rules you must follow is your non-functional requirements!

8

Page 9: 20140228 fp and_performance

We Love Functional Programming!• But what is it?

•Just first class functions?•Referential transparency?•Immutability?•Category theory?

9

Page 10: 20140228 fp and_performance

Abstractions!• They help us reason about our logic• Decoupling• Simplicity• Correctness• Reuse

10

Page 11: 20140228 fp and_performance

Double Edged Sword• We live in a world of abstractions already!•Languages on the JVM are DSL for bytecode•Bytecode is an abstraction over macro instructions

•Macro instructions are an abstraction over micro instructions

11

Page 12: 20140228 fp and_performance

JVM == Imperative• The JVM is built to execute imperative logic very fast• The more we stray from imperative logic constructs, the more we pay in terms of performance

12

Page 13: 20140228 fp and_performance

Penalties• Increased allocations• More bytecode executed to perform tasks• Less control over runtime performance

13

Page 14: 20140228 fp and_performance

There Is A Fine Line Here• We love to write “elegant” code, but this is defined by your personal aesthetic•Some people love prefix notation and s-expressions

•Some people see beauty in c-style constructs

14

Page 15: 20140228 fp and_performance

Rap Genius

15

Page 16: 20140228 fp and_performance

What About The Environment?

16

Page 17: 20140228 fp and_performance

We Can’t Ignore the Cost!

17

Page 18: 20140228 fp and_performance

Languages Impose Constraints• “Choose-a-phone” languages versus those

with strictly defined language constructs

18

Page 19: 20140228 fp and_performance

Languages “Pick” Abstractions For You• Example: CSP versus Actor models

•Why must we choose?•Why can’t we have both in libraries?•Why can’t both be relevant to solving problems in an application?

19

Page 20: 20140228 fp and_performance

We Need to be Treated Like Adults!• Every program will behave differently• Choosing a language that imposes strict rules forces us to make ugly choices

20

Page 21: 20140228 fp and_performance

How Many Libs Have Performance Tests?

• Very few• You give up control of your ability to optimize when you use libraries

21

Page 22: 20140228 fp and_performance

Asynchrony• A wonderful tool for leveraging cores on a machine• Not faster than a single thread per se• We must pay attention to Amdahl’s Law

22

Page 23: 20140228 fp and_performance

HardwareFrom the bottom up, computers

understand queues and message passing

23

Page 24: 20140228 fp and_performance

Things to Avoid

• Parallel Collections• STM• Returns out of closures• Boxing• Lambdas! :)

24

Page 25: 20140228 fp and_performance

Digression: Don’t Use OSX• It’s lousy for doing performance analysis• The JVM has issues, particularly with visibility

25

Page 26: 20140228 fp and_performance

Tools Also Have Issues• Many tools only give you information after the JVM is at a safepoint• What does that tell us about our memory consumption or thread stacks?

26

Page 27: 20140228 fp and_performance

Tools That I Trust• jHiccup (pauses and stalls)• Java Microbenchmarking Harness• PrintGCStats (post-mortem tool on GC output in file)• GC:

• jClarity Censum• GarbageCat• VisualVM with Visual GC plugin

• htop (visualize user vs kernel usage)• dstat (replaces vmstat, iostat and ifstat)

• --cpu, --mem, --aio, --top-io, --top-bio• OProfile (system wide Linux profiler)

27

Page 28: 20140228 fp and_performance

Pinning to Cores• Use numactl for pinning to cores and sockets• taskset pins to cores only, no control over cross-socket communication, which has latency penalties, but useful for laptop tests

28

Page 29: 20140228 fp and_performance

JVM Flags to Use• Pay close attention to the output from:

•+PrintGCDetails•+PrintGCDateStamp•+PrintGCCause•+PrintGCApplicationStoppedTime•+PrintTenuringDistribution (age of objects in survivor

spaces)•+PrintSafepointStatistics (reason and timings)•+PrintFlagsFinal (show entire JVM config)•+PrintAssembly (must use

+UnlockDiagnosticVMOptions)

29

Page 30: 20140228 fp and_performance

Don’t Overuse Memory Barriers• Volatile variables aren’t required for every field• Think about how to organize updates to fields and then update ONE volatile var last to publish all

30

Page 31: 20140228 fp and_performance

Thank You!

31