80
And other Tips & Tricks to make you a “Performance Expert” More @ http://blog.dynatrace.com – Tools @ http://bit.ly/dtpersonal Andreas Grabner - @grabnerandi Deep Dive Into Top Performance Mistakes

Top Java Performance Problems and Metrics To Check in Your Pipeline

Embed Size (px)

Citation preview

Page 1: Top Java Performance Problems and Metrics To Check in Your Pipeline

And other Tips & Tricks to make you a “Performance Expert”More @ http://blog.dynatrace.com – Tools @ http://bit.ly/dtpersonal

Andreas Grabner - @grabnerandi

Deep Dive Into Top Performance Mistakes

Page 2: Top Java Performance Problems and Metrics To Check in Your Pipeline

Why Performanc

e?Confidential, Dynatrace, LLC

Page 3: Top Java Performance Problems and Metrics To Check in Your Pipeline

700 deployments / YEAR

10 + deployments / DAY

50 – 60 deployments / DAY

Every 11.6 SECONDS

Page 4: Top Java Performance Problems and Metrics To Check in Your Pipeline

Not only fast delivered but also delivering fast!

-1000ms +2%

Response Time Conversions

-1000ms +10%

+100ms -1%

Page 5: Top Java Performance Problems and Metrics To Check in Your Pipeline

#1: Which Geo has which “User Experience”?

#2: Who are these users?

Page 6: Top Java Performance Problems and Metrics To Check in Your Pipeline

Daily Deployments + Mkt Push

Increase # of unhappy users!

Drop in Conversion Rate

Overall increase of Users!

Page 7: Top Java Performance Problems and Metrics To Check in Your Pipeline

Satisfied Users Click more Content

Page 8: Top Java Performance Problems and Metrics To Check in Your Pipeline

Tolerating Users click less content

Page 9: Top Java Performance Problems and Metrics To Check in Your Pipeline

Frustrated Users mainly click on Support

Page 10: Top Java Performance Problems and Metrics To Check in Your Pipeline

Update of Dependency Injection Library impacts Memory & CPU

Page 11: Top Java Performance Problems and Metrics To Check in Your Pipeline

App with Regular Load supported by

10 ContainersTwice the Load but 48 (=4.8x!) Containers! App doesn’t scale!!

Does it really scale?

Page 12: Top Java Performance Problems and Metrics To Check in Your Pipeline

How to analyze

perf?Confidential, Dynatrace, LLC

Page 13: Top Java Performance Problems and Metrics To Check in Your Pipeline

Time: Wall Clock, CPU, I/O, Wait/Sync, Susp, Page Load

Throughput: # of Requests per Timeinterval

Resources: CPU Cycles, Memory, I/O, Log Messages, ...

Pools and Queues: Sizes, Utilization, Acquisition Time, # Publishers vs # Subscribers, Process Time

Interactions: # SQLs, # Messages, # Services, # Images, # CSS

Errors: Exceptions, HTTPs, TCP Packet Loss

Page 14: Top Java Performance Problems and Metrics To Check in Your Pipeline

AND MANY MORE

Page 15: Top Java Performance Problems and Metrics To Check in Your Pipeline

0.02ms

0.01ms

Page 16: Top Java Performance Problems and Metrics To Check in Your Pipeline
Page 17: Top Java Performance Problems and Metrics To Check in Your Pipeline

https://dynatrace.github.io/ufo/

“In Your Face” Data!

Page 18: Top Java Performance Problems and Metrics To Check in Your Pipeline

Where do your Stories come

from?

Page 19: Top Java Performance Problems and Metrics To Check in Your Pipeline
Page 20: Top Java Performance Problems and Metrics To Check in Your Pipeline

Share Your PurePath - http://bit.ly/sharepurepath

Page 21: Top Java Performance Problems and Metrics To Check in Your Pipeline

3rd parties

Akamai

Cloudfront

Synthetic

Apache

IIS

Node.js

nginx

Java

.NET

PHP

IBM

WMQ

ESBsMongoDB

Hbase

Cassandra

CICs

IMS

ORACLE

MSSQL

MySQL

DB2

Mobile

Collector

Plugins

Dynatrace Server

Hosts

Session Storage

Splunk

Elasticsearch

Solr

Rich Client

Web Interface

Web

Page 22: Top Java Performance Problems and Metrics To Check in Your Pipeline

Dev/Arch

Arch Validation

Method Level Hotspots

Every SQL + Bind

+ Exceptions, Logs, Memory Allocation, Threads, Actual Code ...

Page 23: Top Java Performance Problems and Metrics To Check in Your Pipeline

Export & Share

Share Your PurePath - http://bit.ly/sharepurepath

Page 24: Top Java Performance Problems and Metrics To Check in Your Pipeline
Page 25: Top Java Performance Problems and Metrics To Check in Your Pipeline

20%80%

Page 26: Top Java Performance Problems and Metrics To Check in Your Pipeline
Page 27: Top Java Performance Problems and Metrics To Check in Your Pipeline
Page 28: Top Java Performance Problems and Metrics To Check in Your Pipeline

Frontend PerformanceWe are getting FATer!

Page 29: Top Java Performance Problems and Metrics To Check in Your Pipeline

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 30: Top Java Performance Problems and Metrics To Check in Your Pipeline

Fifa.com during Worldcup

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

Page 31: Top Java Performance Problems and Metrics To Check in Your Pipeline

8MB of background image for STPCon (Word Press)

Page 32: Top Java Performance Problems and Metrics To Check in Your Pipeline

Time of D

eployment

Availability dropped to 0%

Availability And Response Time

Page 33: Top Java Performance Problems and Metrics To Check in Your Pipeline

Tip for handling Spike Load: GO LEAN!!

Response time improved 4x

1h before SuperBowl KickOff

1h after Game ended

Page 34: Top Java Performance Problems and Metrics To Check in Your Pipeline

Make F12 or Browser Agent your friend!

Page 35: Top Java Performance Problems and Metrics To Check in Your Pipeline

Key Metrics# of ResourcesSize of ResourcesTotal Size of ContentHTTP 3xx, 4xx, 5xx# of Domains

Page 36: Top Java Performance Problems and Metrics To Check in Your Pipeline
Page 37: Top Java Performance Problems and Metrics To Check in Your Pipeline
Page 38: Top Java Performance Problems and Metrics To Check in Your Pipeline

Backend PerformanceThe Usual Suspects

Page 39: Top Java Performance Problems and Metrics To Check in Your Pipeline

• 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 40: Top Java Performance Problems and Metrics To Check in Your Pipeline

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 41: Top Java Performance Problems and Metrics To Check in Your Pipeline

#1: Loading too much data

24889! Calls to the Database API!

High Memory Usage results in GC resulting to high GC to keep all

data in Memory

Page 42: Top Java Performance Problems and Metrics To Check in Your Pipeline

#2: On individual connections 12444! individual

connections

Classical N+1 Query Problem

Individual SQL really <1ms

Page 43: Top Java Performance Problems and Metrics To Check in Your Pipeline

#3: Putting all data in temp Hashtable

Lots of time spent in Hashtable.get

Called from their Entity Objects

Page 44: Top Java Performance Problems and Metrics To Check in Your Pipeline

• … 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 45: Top Java Performance Problems and Metrics To Check in Your Pipeline

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

Page 46: Top Java Performance Problems and Metrics To Check in Your Pipeline

LoggingWE CAN LOG THIS!!

Or we just throw a lot ofExceptions

LOG

Page 47: Top Java Performance Problems and Metrics To Check in Your Pipeline

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

Excessive logging through Spring Framework

Page 48: Top Java Performance Problems and Metrics To Check in Your Pipeline

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 49: Top Java Performance Problems and Metrics To Check in Your Pipeline

Overhead caused by ExceptionsfillInStackTrace is Top 2 in CPU Hotspots

All these Exceptions that never show up in a log file are consuming all CPU

Page 50: Top Java Performance Problems and Metrics To Check in Your Pipeline

Too Many Exceptions vs Log Messages

2-5 Log Messages per 5 MinLooking at the important

(SEVERE, FATAL, …) log messages written

Up to 20000 Custom ExceptionsThat’s about 4000x the number of Exceptions per Log Message

Page 51: Top Java Performance Problems and Metrics To Check in Your Pipeline

Key Metrics

# of Log EntriesSize of Logs per Use Case

Page 52: Top Java Performance Problems and Metrics To Check in Your Pipeline

Pools & QueuesProper Sizing!!

Page 53: Top Java Performance Problems and Metrics To Check in Your Pipeline

Wrong Pool Sizes Configured

Do we have enough DB CONNECTIONS per pool?

Page 54: Top Java Performance Problems and Metrics To Check in Your Pipeline

Threading Issues

Page 55: Top Java Performance Problems and Metrics To Check in Your Pipeline

Threading Issues (Analysis) Tip: I like the Thread Column as it tells me where we spawn off async threads and

where the “main threads” might be waiting

Page 56: Top Java Performance Problems and Metrics To Check in Your Pipeline

Sync / Wait1.63s in Object.wait

Means that this thread is put to hold

Waiting on the next Connection to become

available!

Page 57: Top Java Performance Problems and Metrics To Check in Your Pipeline

Key Metrics

Pool and Queue SizesTime in Sync & Wait

Page 58: Top Java Performance Problems and Metrics To Check in Your Pipeline

(Micro)ServicesArchitectural Mistakes with „Migrating“ to (Micro)Services

Page 59: Top Java Performance Problems and Metrics To Check in Your Pipeline

Example #2: Online Sports Club Search Service

2015201420xx

Response Time

2016+

1) Started as a small project

2) Slowly growing user base

3) Expanding to new markets –

1st performance degradation!

4) Adding more markets – performance becomes

a business impact Users

4) Potentially start loosing users

Page 60: Top Java Performance Problems and Metrics To Check in Your Pipeline

Early 2015: Monolithic App

Can‘t scale vertically endlessly!

2.68s Load Time

94.09% CPU Bound

Page 61: Top Java Performance Problems and Metrics To Check in Your Pipeline

Proposal: Service approach!

Front Endto Cloud

Scale Backendin Containers!

Page 62: Top Java Performance Problems and Metrics To Check in Your Pipeline

7:00 a.m.Low Load and Service runningon minimum redundancy

12:00 p.m.Scaled up service during peak loadwith failover of problematic node

7:00 p.m.Scaled down again to lower loadand move to different geo location

Testing the Backend Service alone scales well …

Page 63: Top Java Performance Problems and Metrics To Check in Your Pipeline

Go live – 7:00 a.m.

Page 64: Top Java Performance Problems and Metrics To Check in Your Pipeline

Go live – 12:00 p.m.

Page 65: Top Java Performance Problems and Metrics To Check in Your Pipeline

What Went Wrong?

Page 66: Top Java Performance Problems and Metrics To Check in Your Pipeline

26.7s Load Time5kB Payload

33! Service Calls

99kB - 3kB for each call!

171! Total SQL Count

Architecture ViolationDirect access to DB from frontend service

Single search query end-to-end

Page 67: Top Java Performance Problems and Metrics To Check in Your Pipeline

The fixed end-to-end use case“Re-architect” vs. “Migrate” to Service-Orientation

2.5s (vs 26.7) 5kB Payload

1! (vs 33!) Service Call

5kB (vs 99) Payload!

3! (vs 177) Total SQL Count

Page 68: Top Java Performance Problems and Metrics To Check in Your Pipeline
Page 69: Top Java Performance Problems and Metrics To Check in Your Pipeline

You measure it! from Dev (to) Ops

Page 70: Top Java Performance Problems and Metrics To Check in Your Pipeline

Build 17 testNewsAlert OK

testSearch OK

Build # Use Case Stat # API Calls # SQL Payload CPU

1 5 2kb 70ms

1 3 5kb 120ms

Use Case Tests and Monitors Service & App Metrics

Build 26 testNewsAlert OK

testSearch OK

Build 25 testNewsAlert OK

testSearch OK

1 4 1kb 60ms

34 171 104kb 550ms

Ops#ServInst Usage RT

1 0.5% 7.2s

1 63% 5.2s

1 4 1kb 60ms

2 3 10kb 150ms

1 0.6% 4.2s

5 75% 2.5s

Build 35 testNewsAlert -

testSearch OK

- - - -

2 3 10kb 150ms

- - -

8 80% 2.0s

Metrics from and for Dev(to)Ops

Re-architecture into „Services“ + Performance Fixes

Scenario: Monolithic App with 2 Key Features

Page 71: Top Java Performance Problems and Metrics To Check in Your Pipeline

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

Page 72: Top Java Performance Problems and Metrics To Check in Your Pipeline

Tips & TricksAnd more Metrics of course

Page 73: Top Java Performance Problems and Metrics To Check in Your Pipeline

Tip: Layer Breakdown over Time

With increasing load: Which LAYER doesn’t SCALE?

Page 74: Top Java Performance Problems and Metrics To Check in Your Pipeline

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 75: Top Java Performance Problems and Metrics To Check in Your Pipeline

Tip: Failed Transactions

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

under heavier load?

Page 76: Top Java Performance Problems and Metrics To Check in Your Pipeline

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 77: Top Java Performance Problems and Metrics To Check in Your Pipeline

Tip: Database History Dashboard

How many SQL Statements are PREPARED?

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

Page 78: Top Java Performance Problems and Metrics To Check in Your Pipeline

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

http://blog.ruxit.com

Page 79: Top Java Performance Problems and Metrics To Check in Your Pipeline

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

Page 80: Top Java Performance Problems and Metrics To Check in Your Pipeline

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