SlideShare a Scribd company logo
Optimizing Java Performance
When App is on Fire

by Konstantin Pavlov
blog.konstantinpavlov.net
kpavlov
What’s the High Load?
•

There is no exact definition of “High Load”

•

Let's say, over 10000+ incoming events per second, over 1000
events per one seconds on peak

•

Example: Market quotes processing
“20% efforts gives 80% of success”

– Pareto Principle
How to Optimize
•

Measure, not guess

•

Consider Not Doing Things

•

Minimize I/O

•

Reduce database operations

•

Reduce network operations

•

Reduce memory allocations and garbage collection

•

Use logging judiciously

•

Optimizing is iterative process
Measure, Not Guess
•

Record and compare throughput before and after changes

•

Samplers and profilers are your best friends: jvisualVM, JProfiler, etc.

•

Different environments have different results

•

Try to test on production-like environment

•

If production-like environment is not available, compare relative
performance change on single environment
Consider Not Doing
•

Use caching proxies for web applications

•

Review your algorithms

•

In some cases exit earlier. e.g. No need to prepare a data which will
not be used later
Minimize I/O
•

If CPU is idle then I/O is likely a bottleneck

•

File system operations

•

Network operations, data serialization/deserialization.

•

Logging

•

Database operations
Distributing Objects
•

Main rule of distributing objects: "Do not distribute objects. If
possible” (Martin Fowler, “Enterprise Integration Patterns”)

•

CAP Theorem: "It's impossible in distributed system to achieve
Consistency, Availability and Partition Tolerance at the same time"

•

Pros: Less I/O and serialization, simpler interfaces, no coping data
between POJOs

•

Cons: Higher resource consumption on single node, may not scale
well, temptation to make architectural mess
Reduce Database I/O
•

Make sure your DBMS has enough resources

•

Minimize DB access. Cache objects in-memory, if possible

•

Consider using stored procedures to reduce communication
between server and DB. DBMS is designed to process data

•

Find the slowest query, optimize it, then take next and so on…

•

Read/write only necessary columns
Use Logging Judiciously
•

Consider what to log. Review toString() methods

•

Consider when to log. Decision to log or not takes time itself.
Logger.isDebugEnabled() takes time

•

Choose appropriate log levels

•

When using {}-placeholders don’t evaluate expressions
Reduce GC
•

Do not create unnecessary objects

•

Use builders carefully. HashCodeBuilder and EqualsBuilder may
produce GC overhead in collections

•

Review comparators used in TreeSets

•

Reduce boxing/unboxing
Reduce CPU Load

•

HashCode and Equals when called frequently may be a bottleneck
Iterative Optimization
Result p = measurePerformance();
while (!satisfied(p)) {
optimize();
p = measurePerformance();
}
Thank you!

More Related Content

What's hot

ASP.NET Scalability - VBUG London
ASP.NET Scalability - VBUG LondonASP.NET Scalability - VBUG London
ASP.NET Scalability - VBUG London
Phil Pursglove
 
ASP.NET Scalability - WebDD
ASP.NET Scalability - WebDDASP.NET Scalability - WebDD
ASP.NET Scalability - WebDD
Phil Pursglove
 

What's hot (20)

Getting started with Laravel & Elasticsearch
Getting started with Laravel & ElasticsearchGetting started with Laravel & Elasticsearch
Getting started with Laravel & Elasticsearch
 
Laravel and SOLR
Laravel and SOLRLaravel and SOLR
Laravel and SOLR
 
Developing for Your Target Market - Social, Games & Mobile - AWS India Summit...
Developing for Your Target Market - Social, Games & Mobile - AWS India Summit...Developing for Your Target Market - Social, Games & Mobile - AWS India Summit...
Developing for Your Target Market - Social, Games & Mobile - AWS India Summit...
 
Fine tuning Hybrid Mobile App
Fine tuning Hybrid Mobile AppFine tuning Hybrid Mobile App
Fine tuning Hybrid Mobile App
 
Azure Web Sites
Azure Web SitesAzure Web Sites
Azure Web Sites
 
The State of Rust Web Frameworks
The State of Rust Web FrameworksThe State of Rust Web Frameworks
The State of Rust Web Frameworks
 
AtlasCamp 2014: Preparing Your Plugin for JIRA Data Center
AtlasCamp 2014: Preparing Your Plugin for JIRA Data CenterAtlasCamp 2014: Preparing Your Plugin for JIRA Data Center
AtlasCamp 2014: Preparing Your Plugin for JIRA Data Center
 
Tips & Tricks SQL in the City Seattle 2014
Tips & Tricks SQL in the City Seattle 2014Tips & Tricks SQL in the City Seattle 2014
Tips & Tricks SQL in the City Seattle 2014
 
Zone.js
Zone.jsZone.js
Zone.js
 
RavenDB 3.5
RavenDB 3.5RavenDB 3.5
RavenDB 3.5
 
Ohio Valley Oracle Application User Group
Ohio Valley Oracle Application User GroupOhio Valley Oracle Application User Group
Ohio Valley Oracle Application User Group
 
In Memory Cahce Structure
In Memory Cahce StructureIn Memory Cahce Structure
In Memory Cahce Structure
 
SPA vs. MPA
SPA vs. MPASPA vs. MPA
SPA vs. MPA
 
Ajax
AjaxAjax
Ajax
 
ASP.NET Scalability - VBUG London
ASP.NET Scalability - VBUG LondonASP.NET Scalability - VBUG London
ASP.NET Scalability - VBUG London
 
ASP.NET Scalability - WebDD
ASP.NET Scalability - WebDDASP.NET Scalability - WebDD
ASP.NET Scalability - WebDD
 
MongoDB World 2018: Solving Your Backup Needs Using MongoDB Ops Manager, Clou...
MongoDB World 2018: Solving Your Backup Needs Using MongoDB Ops Manager, Clou...MongoDB World 2018: Solving Your Backup Needs Using MongoDB Ops Manager, Clou...
MongoDB World 2018: Solving Your Backup Needs Using MongoDB Ops Manager, Clou...
 
Mtn view sql server nov 2014
Mtn view sql server nov 2014Mtn view sql server nov 2014
Mtn view sql server nov 2014
 
Introducing Backblaze B2, the lowest cost cloud storage on the planet.
Introducing Backblaze B2, the lowest cost cloud storage on the planet.Introducing Backblaze B2, the lowest cost cloud storage on the planet.
Introducing Backblaze B2, the lowest cost cloud storage on the planet.
 
Вадим Абрамчук — Big Drupal: Issues We Met
Вадим Абрамчук — Big Drupal: Issues We MetВадим Абрамчук — Big Drupal: Issues We Met
Вадим Абрамчук — Big Drupal: Issues We Met
 

Viewers also liked

Creating High Performance Big Data Applications with the Java Persistence API
Creating High Performance Big Data Applications with the Java Persistence APICreating High Performance Big Data Applications with the Java Persistence API
Creating High Performance Big Data Applications with the Java Persistence API
DATAVERSITY
 
Java Performance
Java PerformanceJava Performance
Java Performance
SSA KPI
 
SSO with the WSO2 Identity Server
SSO with the WSO2 Identity ServerSSO with the WSO2 Identity Server
SSO with the WSO2 Identity Server
WSO2
 
High-performance Team Development
High-performance Team DevelopmentHigh-performance Team Development
High-performance Team Development
Peter Pfeiffer
 

Viewers also liked (20)

High Performance With Java
High Performance With JavaHigh Performance With Java
High Performance With Java
 
Creating High Performance Big Data Applications with the Java Persistence API
Creating High Performance Big Data Applications with the Java Persistence APICreating High Performance Big Data Applications with the Java Persistence API
Creating High Performance Big Data Applications with the Java Persistence API
 
Java performance
Java performanceJava performance
Java performance
 
Performance van Java 8 en verder - Jeroen Borgers
Performance van Java 8 en verder - Jeroen BorgersPerformance van Java 8 en verder - Jeroen Borgers
Performance van Java 8 en verder - Jeroen Borgers
 
High Performance Web Design
High Performance Web DesignHigh Performance Web Design
High Performance Web Design
 
Java Performance
Java PerformanceJava Performance
Java Performance
 
Java Performance & Profiling
Java Performance & ProfilingJava Performance & Profiling
Java Performance & Profiling
 
WSO2 Identity Server
WSO2 Identity ServerWSO2 Identity Server
WSO2 Identity Server
 
Microservices for performance - GOTO Chicago 2016
Microservices for performance - GOTO Chicago 2016Microservices for performance - GOTO Chicago 2016
Microservices for performance - GOTO Chicago 2016
 
Java Performance, Threading and Concurrent Data Structures
Java Performance, Threading and Concurrent Data StructuresJava Performance, Threading and Concurrent Data Structures
Java Performance, Threading and Concurrent Data Structures
 
High performance java ee with j cache and cdi
High performance java ee with j cache and cdiHigh performance java ee with j cache and cdi
High performance java ee with j cache and cdi
 
SSO with the WSO2 Identity Server
SSO with the WSO2 Identity ServerSSO with the WSO2 Identity Server
SSO with the WSO2 Identity Server
 
Practical Steps For Building High Performance Teams
Practical Steps For Building High Performance TeamsPractical Steps For Building High Performance Teams
Practical Steps For Building High Performance Teams
 
High-performance Team Development
High-performance Team DevelopmentHigh-performance Team Development
High-performance Team Development
 
Leading High Performance Teams
Leading High Performance TeamsLeading High Performance Teams
Leading High Performance Teams
 
WSO2 Identity Server 5.3.0 - Product Release Webinar
WSO2 Identity Server 5.3.0 - Product Release WebinarWSO2 Identity Server 5.3.0 - Product Release Webinar
WSO2 Identity Server 5.3.0 - Product Release Webinar
 
High Performance Java EE with JCache and CDI
High Performance Java EE with JCache and CDIHigh Performance Java EE with JCache and CDI
High Performance Java EE with JCache and CDI
 
SAML Smackdown
SAML SmackdownSAML Smackdown
SAML Smackdown
 
High Performance Flow Matching Architecture for Openflow Data Plane
High Performance Flow Matching Architecture for Openflow Data PlaneHigh Performance Flow Matching Architecture for Openflow Data Plane
High Performance Flow Matching Architecture for Openflow Data Plane
 
SAML Protocol Overview
SAML Protocol OverviewSAML Protocol Overview
SAML Protocol Overview
 

Similar to Optimizing Java Performance

How_To_Soup_Up_Your_Farm
How_To_Soup_Up_Your_FarmHow_To_Soup_Up_Your_Farm
How_To_Soup_Up_Your_Farm
Nigel Price
 
5 Common Mistakes You are Making on your Website
 5 Common Mistakes You are Making on your Website 5 Common Mistakes You are Making on your Website
5 Common Mistakes You are Making on your Website
Acquia
 
Building a highly scalable and available cloud application
Building a highly scalable and available cloud applicationBuilding a highly scalable and available cloud application
Building a highly scalable and available cloud application
Noam Sheffer
 
Storage Systems For Scalable systems
Storage Systems For Scalable systemsStorage Systems For Scalable systems
Storage Systems For Scalable systems
elliando dias
 

Similar to Optimizing Java Performance (20)

Scaling apps for the big time
Scaling apps for the big timeScaling apps for the big time
Scaling apps for the big time
 
Java Developers, make the database work for you (NLJUG JFall 2010)
Java Developers, make the database work for you (NLJUG JFall 2010)Java Developers, make the database work for you (NLJUG JFall 2010)
Java Developers, make the database work for you (NLJUG JFall 2010)
 
071410 sun a_1515_feldman_stephen
071410 sun a_1515_feldman_stephen071410 sun a_1515_feldman_stephen
071410 sun a_1515_feldman_stephen
 
How_To_Soup_Up_Your_Farm
How_To_Soup_Up_Your_FarmHow_To_Soup_Up_Your_Farm
How_To_Soup_Up_Your_Farm
 
Make Life Suck Less (Building Scalable Systems)
Make Life Suck Less (Building Scalable Systems)Make Life Suck Less (Building Scalable Systems)
Make Life Suck Less (Building Scalable Systems)
 
SharePoint 2013 Performance Analysis - Robi Vončina
SharePoint 2013 Performance Analysis - Robi VončinaSharePoint 2013 Performance Analysis - Robi Vončina
SharePoint 2013 Performance Analysis - Robi Vončina
 
Performance tuning Grails applications
Performance tuning Grails applicationsPerformance tuning Grails applications
Performance tuning Grails applications
 
Performance tuning Grails applications
 Performance tuning Grails applications Performance tuning Grails applications
Performance tuning Grails applications
 
Best practices with development of enterprise-scale SharePoint solutions - Pa...
Best practices with development of enterprise-scale SharePoint solutions - Pa...Best practices with development of enterprise-scale SharePoint solutions - Pa...
Best practices with development of enterprise-scale SharePoint solutions - Pa...
 
Development of concurrent services using In-Memory Data Grids
Development of concurrent services using In-Memory Data GridsDevelopment of concurrent services using In-Memory Data Grids
Development of concurrent services using In-Memory Data Grids
 
Load testing with Visual Studio and Azure - Andrew Siemer
Load testing with Visual Studio and Azure - Andrew SiemerLoad testing with Visual Studio and Azure - Andrew Siemer
Load testing with Visual Studio and Azure - Andrew Siemer
 
Drupal performance
Drupal performanceDrupal performance
Drupal performance
 
5 Common Mistakes You are Making on your Website
 5 Common Mistakes You are Making on your Website 5 Common Mistakes You are Making on your Website
5 Common Mistakes You are Making on your Website
 
Datadog: a Real-Time Metrics Database for One Quadrillion Points/Day
Datadog: a Real-Time Metrics Database for One Quadrillion Points/DayDatadog: a Real-Time Metrics Database for One Quadrillion Points/Day
Datadog: a Real-Time Metrics Database for One Quadrillion Points/Day
 
From ddd to DDD : My journey from data-driven development to Domain-Driven De...
From ddd to DDD : My journey from data-driven development to Domain-Driven De...From ddd to DDD : My journey from data-driven development to Domain-Driven De...
From ddd to DDD : My journey from data-driven development to Domain-Driven De...
 
Building a highly scalable and available cloud application
Building a highly scalable and available cloud applicationBuilding a highly scalable and available cloud application
Building a highly scalable and available cloud application
 
Leveraging MongoDB: An Introductory Case Study
Leveraging MongoDB: An Introductory Case StudyLeveraging MongoDB: An Introductory Case Study
Leveraging MongoDB: An Introductory Case Study
 
Basic Application Performance Optimization Techniques (Backend)
Basic Application Performance Optimization Techniques (Backend)Basic Application Performance Optimization Techniques (Backend)
Basic Application Performance Optimization Techniques (Backend)
 
Storage Systems For Scalable systems
Storage Systems For Scalable systemsStorage Systems For Scalable systems
Storage Systems For Scalable systems
 
Make Life Suck Less (Building Scalable Systems)
Make Life Suck Less (Building Scalable Systems)Make Life Suck Less (Building Scalable Systems)
Make Life Suck Less (Building Scalable Systems)
 

Recently uploaded

Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo DiehlFuture Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Peter Udo Diehl
 

Recently uploaded (20)

НАДІЯ ФЕДЮШКО БАЦ «Професійне зростання QA спеціаліста»
НАДІЯ ФЕДЮШКО БАЦ  «Професійне зростання QA спеціаліста»НАДІЯ ФЕДЮШКО БАЦ  «Професійне зростання QA спеціаліста»
НАДІЯ ФЕДЮШКО БАЦ «Професійне зростання QA спеціаліста»
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
ODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User GroupODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User Group
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
 
UiPath Test Automation using UiPath Test Suite series, part 1
UiPath Test Automation using UiPath Test Suite series, part 1UiPath Test Automation using UiPath Test Suite series, part 1
UiPath Test Automation using UiPath Test Suite series, part 1
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
 
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo DiehlFuture Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
 

Optimizing Java Performance

  • 1. Optimizing Java Performance When App is on Fire by Konstantin Pavlov blog.konstantinpavlov.net kpavlov
  • 2. What’s the High Load? • There is no exact definition of “High Load” • Let's say, over 10000+ incoming events per second, over 1000 events per one seconds on peak • Example: Market quotes processing
  • 3. “20% efforts gives 80% of success” – Pareto Principle
  • 4. How to Optimize • Measure, not guess • Consider Not Doing Things • Minimize I/O • Reduce database operations • Reduce network operations • Reduce memory allocations and garbage collection • Use logging judiciously • Optimizing is iterative process
  • 5. Measure, Not Guess • Record and compare throughput before and after changes • Samplers and profilers are your best friends: jvisualVM, JProfiler, etc. • Different environments have different results • Try to test on production-like environment • If production-like environment is not available, compare relative performance change on single environment
  • 6. Consider Not Doing • Use caching proxies for web applications • Review your algorithms • In some cases exit earlier. e.g. No need to prepare a data which will not be used later
  • 7. Minimize I/O • If CPU is idle then I/O is likely a bottleneck • File system operations • Network operations, data serialization/deserialization. • Logging • Database operations
  • 8. Distributing Objects • Main rule of distributing objects: "Do not distribute objects. If possible” (Martin Fowler, “Enterprise Integration Patterns”) • CAP Theorem: "It's impossible in distributed system to achieve Consistency, Availability and Partition Tolerance at the same time" • Pros: Less I/O and serialization, simpler interfaces, no coping data between POJOs • Cons: Higher resource consumption on single node, may not scale well, temptation to make architectural mess
  • 9. Reduce Database I/O • Make sure your DBMS has enough resources • Minimize DB access. Cache objects in-memory, if possible • Consider using stored procedures to reduce communication between server and DB. DBMS is designed to process data • Find the slowest query, optimize it, then take next and so on… • Read/write only necessary columns
  • 10. Use Logging Judiciously • Consider what to log. Review toString() methods • Consider when to log. Decision to log or not takes time itself. Logger.isDebugEnabled() takes time • Choose appropriate log levels • When using {}-placeholders don’t evaluate expressions
  • 11. Reduce GC • Do not create unnecessary objects • Use builders carefully. HashCodeBuilder and EqualsBuilder may produce GC overhead in collections • Review comparators used in TreeSets • Reduce boxing/unboxing
  • 12. Reduce CPU Load • HashCode and Equals when called frequently may be a bottleneck
  • 13. Iterative Optimization Result p = measurePerformance(); while (!satisfied(p)) { optimize(); p = measurePerformance(); }