performance? that's what version 2 is for!

37
Performance? That's what version 2 is for! Eduard Tudenhöfner

Upload: nas-tra

Post on 26-May-2015

98 views

Category:

Technology


1 download

DESCRIPTION

Presentation about performance that I held at the adesso developer day in 2012

TRANSCRIPT

Page 1: Performance? That's what version 2 is for!

Performance? That's what version 2 is for!

Eduard Tudenhöfner

Page 2: Performance? That's what version 2 is for!

Performance? That's what version 2 is for!

Overview

► Introduction / Motivation

► Performance Issues & Solution Strategies

► How to proactively reduce risk of Performance Issues?

► Conclusion

Page 3: Performance? That's what version 2 is for!

Introduction / Motivation

Page 4: Performance? That's what version 2 is for!

Why is performance important?

StressProfit

RevenueEfficiency

Less Resources

Higher Fault Tolerance

Stability

Monitoring

SecuritySecurity

Bottlenecks Economical

Conversion Rate

SALES

FASTERSatisfied customers

BETTER Reputation

SLA Monitoring

Real User Experience

Maintenance SPEED MATTERS

Trustworthy

Performance

More SPEED

Key Performance Indicators

USABILITY

Success Factor

Page 5: Performance? That's what version 2 is for!

Investing in Performance really pays off

Why is performance important?

A page that was 2 seconds slower results in a 4.3%

drop in revenue/user(Bing)

400 ms delay cause 0.59% dropin searches/user

(Google)

400 ms slowdown cause 5-9% drop in full-page traffic

(Yahoo)

Introducing gzip compression resultedin 13-25% speedup and cut outbound

network traffic by 50%(Netflix)

Source: www.stevesouders.com

Page 6: Performance? That's what version 2 is for!

Consequences of Poor Performance

Consequences

► Damaged customer relations

– Reputation of the company suffers

– People will continue to associate poor performance with the product, even when the issue is fixed later on

► Lost income & Delayed project schedules

– Revenue is lost

– Penalties have to be paid due to late delivery

► Increased development & maintenance costs

– Delivering features requires more time and effort if performance issues are hindering the acceptance of those features

– Additional time and resources are required if performance issues are found

Page 7: Performance? That's what version 2 is for!

Consequences of Poor Performance

The cost to fix a performance issue

► Is a Technical Debt (defined by Ward Cunningham)

– doing things the quick&dirty way sets us up with technical debt

– technical debt incurs interest payments (in the form of additional effort)

– The later technical debt is payed

back, the higher the interest will be

► So should we pay huge interest at the end or pay back technical debt every development cycle?

Source: Steven Haines. Pro Java EE 5: Performance Management and Optimization

Page 8: Performance? That's what version 2 is for!

Performance Issues & Solution Strategies

Page 9: Performance? That's what version 2 is for!

Performance Issues & Solution Strategies

Client

Application Server

Databases

Legacy Systems / Service Provider

Page 10: Performance? That's what version 2 is for!

Client

Application Server

Databases

Legacy Systems / Service Provider

Application

Performance Issues & Solution Strategies

Page 11: Performance? That's what version 2 is for!

Client

Application Server

Databases

Legacy Systems / Service Provider

Application

Performance Issues & Solution Strategies

Page 12: Performance? That's what version 2 is for!

Client (UI / Browser)

► Bloated Clients

► Very expensive DOM manipulations

► Too many requests required until a page is fully loaded– Time to first impression

– JavaScript files are at the wrong places

► Unsuitable communication patterns

– long running synchronous calls that block the UI

► Network bandwidth

– especially in the mobile area

Performance Issues & Solution Strategies

Page 13: Performance? That's what version 2 is for!

Performance Issues & Solution Strategiesdone with: www.webpagetest.orgChrome / DSL (1.5 Mbps/384Kbps)

50ms RTT

Page 14: Performance? That's what version 2 is for!

Performance Issues & Solution Strategies

49 requests

3.9 s till page is fully loaded

done with: www.webpagetest.orgChrome / DSL (1.5 Mbps/384Kbps)

50ms RTT

Rendering starts after 3.4 s

DOM completeafter 2.6 s

two uncompressedimages

Page 15: Performance? That's what version 2 is for!

Solution Approach

► Reducing RTTs by– Reducing number of resources

– Avoiding bad requests

– Minimizing redirects

– Combining CSS / JS resources (e.g. during build process)

► Reducing Request overhead by

– Using compression (gzip, deflate)

– Minifying CSS / JS resources (cssminifier.com, jscompress.com)

► Placement of CSS and JS files

– CSS at the top / JS at the bottom

● browser should start rendering as early as possible (user perceives a faster loading page)

● anything below the script is blocked from rendering and downloading until after the script is loaded (even when threads are available)→ entire page is delayed

Performance Issues & Solution Strategies

Page 16: Performance? That's what version 2 is for!

How to achieve that in Java (e.g. in JSF)?

► JAWR (jawr.java.net)– Built-in minification

– Enforced caching

– Bundling of resources

– CSS image sprite generation

– Can be integrated in Ant / Maven

– Can be used with (JSF, Spring MVC, Wicket, Grails, ...)

Performance Issues & Solution Strategies

Page 17: Performance? That's what version 2 is for!

JAWR

Performance Issues & Solution Strategies

source: jawr.java.net

What we would like to achieve

How we want to structure

our work

How we can define files bundles

Page 18: Performance? That's what version 2 is for!

Client

Application Server

Databases

Legacy Systems / Service Provider

Application

Performance Issues & Solution Strategies

Page 19: Performance? That's what version 2 is for!

Application Server / Application

► Memory issues– Memory leaks / OutOfMemoryErrors (but not every leak leads to OOME)

– Unnecessary creation of expensive objects

– Static fields and Lists / ThreadLocal usage within AppServer

– inappropriate GC strategy / Heap sizing (for generational GC)

► Caching

– Wrong caching strategy

– Too much or the wrong stuff is cached

► Remote boundaries too fine-grained

– remote communication often done transparently for the developer

– increased round trips

– increased serializations/deserializations

Performance Issues & Solution Strategies

survivor

survivor

eden

old

perm

Page 20: Performance? That's what version 2 is for!

Application Server / Application

► Synchronization issues– synchronized blocks are too wide (method locks vs block locks) → code is locked that

is not necessary

– issue will not be present when doing tests with a small number of users

– can't scale when number of requests grows (the surprise comes when doing load tests or putting application to production)

– not taking advantage of lock-free data structures (java.util.concurrent.atomic)

► Verbose Logging

– What is the cost of getInstName() and getInst()?

– too much is logged / unnecessary string concatenations

► Not taken advantage of the possiblities of the underlying containers (Web, EJB, …)

– unsuitable pool sizes (Thread Pools, EJB Pools, Connection Pools, …)

Performance Issues & Solution Strategies

log.debug("Starting " + getInstName() + "/" + getInst());

Page 21: Performance? That's what version 2 is for!

Solution Approaches

► Memory – Generation sizing (for generational GC)

● -XX:NewRatio=3 → 1:3 (Young:Old) → Young takes ¼ of what was specified with -Xmx

● Sizing proportion between Old/Young generation is important for performance● e.g. if too many short-lived objects are created, they are moved to the old

generation● An oversized young generation can also cause performance problems

– Space on old generation is reserved for emergencies (so that all objects can be copied)

● Memory analysis with e.g. VisualVM, -verbose:gc

– ThreadLocal variables in an application server

● Threads are reused but data is kept● Need to delete ThreadLocal variables before thread is reused by application

server

– Static fields and Lists

● Best Approach: use only for data that never changes

Performance Issues & Solution Strategies

survivor

survivor

eden

old

perm

Page 22: Performance? That's what version 2 is for!

VisualVM with VisualGC Plugin

Performance Issues & Solution Strategies

Page 23: Performance? That's what version 2 is for!

Solution Approaches

► Memory – Generation sizing (for generational GC)

● -XX:NewRatio=3 → 1:3 (Young:Old) → Young takes ¼ of what was specified with -Xmx

● Sizing proportion between Old/Young generation is important for performance

● e.g. if too many short-lived objects are created, they are moved to the old generation

● An oversized young generation can also cause performance problems

– Space on old generation is reserved for emergencies (so that all objects can be copied)

● Memory analysis with e.g. VisualVM, -verbose:gc

– ThreadLocal variables in an application server

● Threads are reused but data is kept

● Need to delete ThreadLocal variables before thread is reused by application server

– Static fields and Lists

● Best Approach: use only for data that never changes

Performance Issues & Solution Strategies

survivor

survivor

eden

old

perm

Page 24: Performance? That's what version 2 is for!

Solution Approaches

► Remote boundaries – Decrease number of remote calls → „The best call is the call that is not

done“

– Boundaries should be more coarse-grained e.g. by using wrapper classes (of course that contain only the really required information)

– Depending on the communication parties (heterogeneous/homogeneous), the right protocol should be used

► Logging

– carefully plan what to log and on which level

=> Log messages should have the ability to run fast in production environment and at same time help in identifying any issue in QA and TEST environment

Performance Issues & Solution Strategies

Page 25: Performance? That's what version 2 is for!

Client

Application Server

Databases

Legacy Systems / Service Provider

Application

Performance Issues & Solution Strategies

Page 26: Performance? That's what version 2 is for!

Databases (from an application's point-of-view)

► More / Less data is retrieved than actually required

► Same data is retrieved over and over again (n+1 query problem)

► High normalization good for reducing redundancy, but bad for performance

► Inappropriate connection pool sizes

► Usage of O/R mappers– can lead to unexpected behavior if used in a wrong way

– possibilities of JPA framework not known or not used efficiently

Performance Issues & Solution Strategies

Page 27: Performance? That's what version 2 is for!

Solution Approaches

► Data Retrieval– Read-Only queries (query.setHint(“eclipselink.read-only“, “true“))

● improves performance by avoiding copying and change tracking the objects

– Fetch Joins

– Batch Reads

– Other loading optimizations

● Use projection queries where appropriate

● Use pagination for large result sets (query.setMaxResults(), query.setFirstResults())

● Use named queries (likely to be precompiled by provider, reusability)

► Updating Data

– Batch Update

● allows a bunch of update operations to be performed as a single DB access

● reduces round trips to the database

Performance Issues & Solution Strategies

<property name="eclipselink.jdbc.batch-writing" value="Oracle-JDBC"/>

Page 28: Performance? That's what version 2 is for!

Fetch Joins - Example

Performance Issues & Solution Strategies

Query query = em.createQuery(“SELECT po from PurchaseOrder po WHERE po.status = 'ACTIVE' AND po.customer.address.city = 'Stuttgart'”);

List<PurchaseOrder> orders = query.getResultList();

for (PurchaseOrder order: orders) { order.getCustomer().getName();}

{returns N purchase orders} → 100 positions = 101 SQLs

Better:SELECT po from PurchaseOrder po FETCH JOIN po.customer...

{returns N purchase orders} → 100 positions = 1 SQL

→ related objects will be joined into the query instead of being queried independently

Page 29: Performance? That's what version 2 is for!

Batch Reads - Example

Performance Issues & Solution Strategies

Query query = em.createQuery(“SELECT po from PurchaseOrder po WHERE po.status = 'ACTIVE' AND po.customer.address.city = 'Stuttgart'”);

query.setHint(“eclipselink.batch”, “po.customer”);

...

{returns N purchase orders} → 100 positions = 2 SQLs (one additional for each relationship)

→ subsequent queries of related objects can be optimized in batches instead of being retrieved one-by-one

→ Batch reading is more efficient than joining because it avoids reading duplicate data.

Page 30: Performance? That's what version 2 is for!

Solution Approaches

► Data Retrieval– Read-Only queries (query.setHint(“eclipselink.read-only“, “true“))

● improves performance by avoiding copying and change tracking the objects

– Fetch Joins

– Batch Reads

– Other loading optimizations

● Use projection queries where appropriate● Use pagination for large result sets (query.setMaxResults(), query.setFirstResults())● Use named queries (likely to be precompiled by provider, reusability)

► Updating Data

– Batch Update

● allows a bunch of update operations to be performed as a single DB access● reduces round trips to the database

Performance Issues & Solution Strategies

<property name="eclipselink.jdbc.batch-writing" value="Oracle-JDBC"/>

Page 31: Performance? That's what version 2 is for!

Client

Application Server

Databases

Legacy Systems / Service Provider

Application

Performance Issues & Solution Strategies

Page 32: Performance? That's what version 2 is for!

Legacy Systems / Service Provider

► They are often out ouf our control

► Legacy Systems– often very difficult to troubleshoot legacy systems

– running dinosaurs

– limited insight into those systems

► Service Providers– No influence on them

– SLAs

Performance Issues & Solution Strategies

Page 33: Performance? That's what version 2 is for!

How to proactively reduce risk of Performance Issues?

Page 34: Performance? That's what version 2 is for!

How to proactively reduce risk of Performance Issues?

Pragmatic Solution Approach

► 1. From a general point-of-view– Define someone that is responsible for Performance Management in the project

– Identify Performance Risks early

– Define Performance Objectives (measurable & realistic)

● otherwise there is a risk that objectives are simply ignored because too difficult to achieve

– Conduct Architectural Reviews (continually)

● to find out whether the architecture is really capable of meeting performance objectives

– Do Performance Tests (before application goes to production)

– Monitor your Application (especially in PreProduction & Production)

● to find out how the application is really used (application usage pattterns)

● to identify trends (important for capacity planning)

– Know your users

Page 35: Performance? That's what version 2 is for!

Pragmatic Solution Approach

► 2. From a technical point-of-view– Know the used technologies

– Always look out for possible performance improvements in those technical areas

● Important: analyze the effects of „improvements“ and „Best Practices“

– Pay back technical debt as soon as possible

– Add small performance tests and not just unit tests (and automate them)

How to proactively reduce risk of Performance Issues?

Page 36: Performance? That's what version 2 is for!

Conclusion

Conclusion

► Investing time & money in performance really pays off

► There needs to be someone responsible for APM

► Performance issues can reside anywhere in an architecture– Architectural reviews, performance tests, aware

developers/architects/testers can help in reducing the risk

► From the managements point-of-view it seems that performance engineering seems to cause initially more costs than bringing value

– Problem: difficult to demonstrate success, but poorly performing applications are clearly observable as failures

“Why do we have performance engineers if we don't have performance problems?” by Connie U. Smith

Page 37: Performance? That's what version 2 is for!

Thank you for your Attention!

Please also have a look at the PERT Wiki space at https://www.adesso.de/wiki/index.php/PERT

[email protected]@adesso.dewww.adesso.de