Java Performance
What Developers Must Know

Diego Lemos
We care about performance...

(credit: http://www.morguefile.com/)

...when things go bad.
Panic Driven Actions
●

Add more hardware

●

Work on ugly code

●

Long Meetings (?!)

●

Blame somebody
Milliseconds Matter
●

Amazon:
–

●

Increase 100ms in load time decreased sales by 1%

Google:
–

From loading a 10-result page in 0.4 seconds to a 30result page loading in 0.9 seconds decreased traffic and
ad revenues by 20%
Measure Don’t Guess
●

Support decisions by measurements

●

Tune what matters

(credit: http://xkcd.com)
Generic Application Stack
Application

Profiling
JVM

Heap Analysis
Operating System

Monitor System
Hardware
Tools
●

vmstat, iostat, netstat

●

JMeter, Gatling

●

HPjmeter

●

VisualVM, jconsole
Demo :
Any problem here?

Java heap space
And here?

Everything is OK!
What happened here?

"catalina-exec-8190-104" - Thread t@135
java.lang.Thread.State: BLOCKED
at com.google.code.morphia.Morphia.mapPackage(Morphia.java:72)
Performance Best Practices
●

●
●

●

Test one build a day for performance issues
(continuous integration)
Monitoring (production env.) for compliance
Keep users at the center of performance
tuning efforts
Devs + Ops
Performance Tests on CI
Follow Coding Best Practices
●

KISS
–

●

complex code is hard to optimize

Loose coupling
–
–

●

Optimize without fear of breaking anything else
Avoid contamination (external applications)

Let your objects die young
Performance myths
●

Tune by default (early tuning)

●

Optimize by precaution (over-engineer)

●

The architecture cannot change

●

Hardware will solve the problem
Conclusion
●

Think performance before problems come

●

Devs + ops working together

●

Monitor your application
More on this
●

http://java.dzone.com/kirk-dominating-consumer

●

https://github.com/dlresende/spring-petclinic

●

http://jmeter.apache.org/usermanual/glossary.html

●

http://www.oracle.com/technetwork/java/javase/gc-tunin

●

http://munchweb.com/effect-of-website-speed

●

http://www.javaworld.com/article/2073905/build-ci-sdlc

Java Performance: What developers must know