78
And other Tips & Tricks to make you a “Performance Expert” More on http://blog.dynatrace.com Andreas Grabner - @grabnerandi Java One 2015 – Deep Dive Top Performance Mistakes

JavaOne 2015: Top Performance Patterns Deep Dive

Embed Size (px)

Citation preview

Page 1: JavaOne 2015: Top Performance Patterns Deep Dive

And other Tips & Tricks to make you a “Performance Expert”More on http://blog.dynatrace.comAndreas Grabner - @grabnerandi

Java One 2015 – Deep Dive Top Performance Mistakes

Page 2: JavaOne 2015: Top Performance Patterns Deep Dive

Safe Harbor

Page 3: JavaOne 2015: Top Performance Patterns Deep Dive

AND MANY MORE

Page 4: JavaOne 2015: Top Performance Patterns Deep Dive

0.02ms

0.01ms

Page 5: JavaOne 2015: Top Performance Patterns Deep Dive
Page 6: JavaOne 2015: Top Performance Patterns Deep Dive
Page 7: JavaOne 2015: Top Performance Patterns Deep Dive

15 Years: That’s why I ended up talking about performance

Page 8: JavaOne 2015: Top Performance Patterns Deep Dive

Where do your Stories come

from?

Page 9: JavaOne 2015: Top Performance Patterns Deep Dive

#1: Real Life & Real User Stories

Page 10: JavaOne 2015: Top Performance Patterns Deep Dive

#2: http://bit.ly/onlineperfclinic

Page 11: JavaOne 2015: Top Performance Patterns Deep Dive

#3: http://bit.ly/sharepurepath

Page 12: JavaOne 2015: Top Performance Patterns Deep Dive
Page 13: JavaOne 2015: Top Performance Patterns Deep Dive

20%80%

Page 14: JavaOne 2015: Top Performance Patterns Deep Dive
Page 15: JavaOne 2015: Top Performance Patterns Deep Dive

Frontend PerformanceWe are getting FATer!

Page 16: JavaOne 2015: Top Performance Patterns Deep Dive
Page 17: JavaOne 2015: Top Performance Patterns Deep Dive
Page 18: JavaOne 2015: Top Performance Patterns Deep Dive

Example of a “Bad” Web Deployment 282! Objects on that page9.68MB Page Size

8.8s Page Load Time

Most objects are images delivered from your main

domain

Very long Connect time (1.8s) to your CDN

Page 19: JavaOne 2015: Top Performance Patterns Deep Dive

Mobile landing page of Super Bowl ad

434 Resources in total on that page:230 JPEGs, 75 PNGs, 50 GIFs, …

Total size of ~ 20MB

Page 20: JavaOne 2015: Top Performance Patterns Deep Dive

Fifa.com during Worldcup

Source: http://apmblog.compuware.com/2014/05/21/is-the-fifa-world-cup-website-ready-for-the-tournament/

Page 21: JavaOne 2015: Top Performance Patterns Deep Dive

8MB of background image for STPCon (Word Press)

Page 22: JavaOne 2015: Top Performance Patterns Deep Dive

Make F12 or Browser Agent your friend!

Page 23: JavaOne 2015: Top Performance Patterns Deep Dive

Compare yourself Online!

Page 24: JavaOne 2015: Top Performance Patterns Deep Dive

Key Metrics

# of ResourcesSize of ResourcesTotal Size of Content

Page 25: JavaOne 2015: Top Performance Patterns Deep Dive

• Browser Built-In Developer Tools• Extensions such as YSlow, PageSpeed• Online Tools

• WebPageTest• Google PageSpeed Insights• Dynatrace Performance Center• ...

• Automate!! With Selenium, WebDriver, Cucumber, ...

Tooling

Page 26: JavaOne 2015: Top Performance Patterns Deep Dive

Frontend AvailabilityBack to Basics Please!

Page 27: JavaOne 2015: Top Performance Patterns Deep Dive
Page 28: JavaOne 2015: Top Performance Patterns Deep Dive
Page 29: JavaOne 2015: Top Performance Patterns Deep Dive
Page 30: JavaOne 2015: Top Performance Patterns Deep Dive

Online Services for you: Is it down right now?

Page 31: JavaOne 2015: Top Performance Patterns Deep Dive

Online Services for you: Outage Analyzer

Page 32: JavaOne 2015: Top Performance Patterns Deep Dive

Tip for handling Spike Load: GO LEAN!!

Response time improved 4x

1h before SuperBowl KickOff

1h after Game ended

Page 33: JavaOne 2015: Top Performance Patterns Deep Dive

Key Metrics

HTTP 3xx, 4xx, 5xx# of Domains

Page 34: JavaOne 2015: Top Performance Patterns Deep Dive

• Dynatrace Synthetic• Ruxit Synthetic• NewRelic Synthetic• AppDynamics• PingDom• ... Just Google for „Synthetic Monitoring“

Online Services

Page 35: JavaOne 2015: Top Performance Patterns Deep Dive

Backend PerformanceThe Usual Suspects

Page 36: JavaOne 2015: Top Performance Patterns Deep Dive

• Symptoms• HTML takes between 60 and 120s to render• High GC Time

• Developer Assumptions• Bad GC Tuning• Probably bad Database Performance as rendering was simple

• Result: 2 Years of Finger pointing between Dev and DBA

Project: Online Room Reservation System

Page 37: JavaOne 2015: Top Performance Patterns Deep Dive

Developers built own monitoringvoid roomreservationReport(int officeId){ long startTime = System.currentTimeMillis(); Object data = loadDataForOffice(officeId); long dataLoadTime = System.currentTimeMillis() - startTime; generateReport(data, officeId);}

Result:Avg. Data Load Time: 45s!

DB Tool says:Avg. SQL Query: <1ms!

Page 38: JavaOne 2015: Top Performance Patterns Deep Dive

#1: Loading too much data24889! Calls to the Database

API!

High CPU and High Memory Usage to keep all data in Memory

Page 39: JavaOne 2015: Top Performance Patterns Deep Dive

#2: On individual connections 12444! individual

connections

Classical N+1 Query Problem

Individual SQL really <1ms

Page 40: JavaOne 2015: Top Performance Patterns Deep Dive

#3: Putting all data in temp Hashtable

Lots of time spent in Hashtable.get

Called from their Entity Objects

Page 41: JavaOne 2015: Top Performance Patterns Deep Dive

• … you know what code is doing you inherited!!• … you are not making mistakes like this

• Explore the Right Tools• Built-In Database Analysis Tools• “Logging” options of Frameworks such as Hibernate, …• JMX, Perf Counters, … of your Application Servers• Performance Tracing Tools: Dynatrace, Ruxit, NewRelic,

AppDynamics, Your Profiler of Choice …

Lessons Learned – Don’t Assume …

Page 42: JavaOne 2015: Top Performance Patterns Deep Dive

Key Metrics# of SQL Calls# of same SQL Execs (1+N)# of ConnectionsRows/Data Transferred

Page 43: JavaOne 2015: Top Performance Patterns Deep Dive

Backend PerformanceArchitectural Mistakes with „Migrating“ to (Micro)Services

Page 44: JavaOne 2015: Top Performance Patterns Deep Dive

26.7s Execution Time

33! Calls to the same Web Service

171! SQL Queries through LINQ by this Web Service – request

similar data for each call

Architecture Violation: Direct access to DB instead from frontend logic

Page 45: JavaOne 2015: Top Performance Patterns Deep Dive

21671! Calls to Oracle

3136! Calls to H2 mostly executed on async background

threads

33! Different connections used

DB Exceptions on both Databases

DB Exceptions on both Databases

40! internal Web Service Calls that do all these DB

Updates

Page 46: JavaOne 2015: Top Performance Patterns Deep Dive

Key Metrics# of Service CallsPayload of Service Calls# of Involved Threads1+N Service Call Pattern!

Page 47: JavaOne 2015: Top Performance Patterns Deep Dive

• Dynatrace• Ruxit• NewRelic• AppDynamics• Any Profiler that can trace across tiers• Google for Tracing or APM (Application Performance Management)

Tooling

Page 48: JavaOne 2015: Top Performance Patterns Deep Dive

LoggingWE CAN LOG THIS!!

LOG

Page 49: JavaOne 2015: Top Performance Patterns Deep Dive

Log Hotspots in Frameworks!callAppenders clear CPU and I/O Hotspot

Excessive logging through Spring Framework

Page 50: JavaOne 2015: Top Performance Patterns Deep Dive

Debug Log and outdated log4j library#1: Top Problem: log4j.callAppenders

-> 71% Sync Time

#2: Most of logging done from fillDetail method

#3: Doing “DEBUG” log output: Is this necessary?

Page 51: JavaOne 2015: Top Performance Patterns Deep Dive

Key Metrics

# of Log EntriesSize of Logs per Use Case

Page 52: JavaOne 2015: Top Performance Patterns Deep Dive

Response Time is not the only Performance IndicatorLook at Resources as well

Page 53: JavaOne 2015: Top Performance Patterns Deep Dive

Is this a successful new Build?

Page 54: JavaOne 2015: Top Performance Patterns Deep Dive

Look at Resource Usage: CPU, Memory, …

Page 55: JavaOne 2015: Top Performance Patterns Deep Dive

Memory? Look at Heap Generations

Page 56: JavaOne 2015: Top Performance Patterns Deep Dive

Root Cause: Dependency Injection

Page 57: JavaOne 2015: Top Performance Patterns Deep Dive

Prevent: Monitor Memory Metrics for every Build

Page 58: JavaOne 2015: Top Performance Patterns Deep Dive

#3: Growing “Old Gen” is a good indicator

for a Mem Leak

#4: Heavy GC kicks in when

Old Generation is

full!

#5: Throughput of Application

goes to 0 due to no memory

available

#1: Eden Space stays constant. Objects being propagated to

Survivor Space

#2: GC Activity in Young Generation ultimately moves objects into Old

Generation

Page 59: JavaOne 2015: Top Performance Patterns Deep Dive

Key Metrics# of Objects per Generation# of GC RunsTotal Impact of GC

Page 60: JavaOne 2015: Top Performance Patterns Deep Dive

Tips & TricksAnd more Metrics of course

Page 61: JavaOne 2015: Top Performance Patterns Deep Dive

Tip: Layer Breakdown over Time

With increasing load: Which LAYER doesn’t SCALE?

Page 62: JavaOne 2015: Top Performance Patterns Deep Dive

Tip: Exceptions and Log Messages

How are # of EXCEPTIONS evolving over time?

How many SEVERE LOG messages to we write in relation to Exceptions?

Page 63: JavaOne 2015: Top Performance Patterns Deep Dive

Tip: Failed Transactions

Are more TRANSACTIONS FAILING (HTTP 5xx, 4xx, …)

under heavier load?

Page 64: JavaOne 2015: Top Performance Patterns Deep Dive

Tip: Database Activity

Do we see increased in AVG # of SQL Executions over Time?

Do TOTAL # of SQL Executions increase with load? Shouldn’t

it flatten due to CACHES?

Page 65: JavaOne 2015: Top Performance Patterns Deep Dive

Tip: Database History Dashboard

How many SQL Statements are PREPARED?

What’s the overall Execution Time of different SQL Types (SELECT, INSERT, DELETE, …)

Page 66: JavaOne 2015: Top Performance Patterns Deep Dive

Tip: DB Connection Pool UtilizationDo we have enough DB

CONNECTIONS per pool?

Page 67: JavaOne 2015: Top Performance Patterns Deep Dive

For more Key Metricshttp://blog.dynatrace.com

http://blog.ruxit.com

Page 68: JavaOne 2015: Top Performance Patterns Deep Dive

We want to get from here …

Page 69: JavaOne 2015: Top Performance Patterns Deep Dive

To here!

Page 70: JavaOne 2015: Top Performance Patterns Deep Dive

Use these application metrics as additional Quality Gates

Page 71: JavaOne 2015: Top Performance Patterns Deep Dive

71

What you currently measure

What you should measure

Quality Metrics in your CI # Test Failures

Overall Duration

Execution Time per test# calls to API# executed SQL statements# Web Service Calls# JMS Messages# Objects Allocated# Exceptions# Log Messages# HTTP 4xx/5xxRequest/Response SizePage Load/Rendering Time…

Page 72: JavaOne 2015: Top Performance Patterns Deep Dive

Connecting your Tests with Quality

12 0 120ms3 1 68ms

Build 20 testPurchase OKtestSearch OK

Build 17 testPurchase OKtestSearch OK

Build 18 testPurchase FAILEDtestSearch OK

Build 19 testPurchase OKtestSearch OK

Build # Test Case Status # SQL # Excep CPU

12 0 120ms3 1 68ms

12 5 60ms3 1 68ms

75 0 230ms3 1 68ms

Test Framework Results Architectural Data

We identified a regresesion

Problem solved

Exceptions probably reason for failed testsProblem fixed but now we have an

architectural regressionProblem fixed but now we have an

architectural regressionNow we have the functional and architectural confidence

Let’s look behind the scenes

Page 73: JavaOne 2015: Top Performance Patterns Deep Dive

#1: Analyzing each Test

#2: Metrics for each Test

#3: Detecting Regression based on Measure

Page 74: JavaOne 2015: Top Performance Patterns Deep Dive

Quality-Metrics based Build Status

Page 75: JavaOne 2015: Top Performance Patterns Deep Dive

Pull data into Jenkins, Bamboo ...

Page 76: JavaOne 2015: Top Performance Patterns Deep Dive

Making Quality a first-class citizen„Too hard“

„we‘ll get round to this later“

„not cool enough“

Page 77: JavaOne 2015: Top Performance Patterns Deep Dive

Questions and/or DemoSlides: slideshare.net/grabnerandiGet Tools: bit.ly/dttrialYouTube Tutorials: bit.ly/dttutorialsContact Me: [email protected] Me: @grabnerandiRead More: blog.dynatrace.com

Page 78: JavaOne 2015: Top Performance Patterns Deep Dive

Andreas GrabnerDynatrace Developer Advocate@grabnerandihttp://blog.dynatrace.com