SlideShare une entreprise Scribd logo

Performance optimization techniques for Java code

The presentation covers the the basics of performance optimizations for real-world Java code. It starts with a theoretical overview of the concepts followed by several live demos showing how performance bottlenecks can be diagnosed and eliminated. The demos include some non-trivial multi-threaded examples inspired by real-world applications.

Performance optimization techniques for Java code

1  sur  30
Télécharger pour lire hors ligne
Performance optimization
techniques for Java code
Who am I and why should you
        trust me? 
●   Attila-Mihály Balázs
    http://hype-free.blogspot.com/
●   Former malware researcher (”low-level
    guy”)
●   Current Java dev (”high level dude”)
●   Spent the last ~6 monts optimizing a large
    (1 000 000+ LOC) legacy system
●   Will spend the next 6 months on it too (at
    least )
?
Question everything!
What's this about
●   Core principles
●   Demo 1: collections framework
●   Demo 2, 3, 4: synchronization performance
●   Demo 5: ugly code, is it worth it?
●   Demo 6, 7, 8: playing with Strings
●   Conclusions
●   Q&A
What this is not about
●   Selecting efficient algorithms
●   High level optimizations (architectural
    changes)

●   These are important too! (but require more
    effort, and we are going for the quick win
    here)
Core principles
●   Performance is a balence, and endless
    game of shifting bottlenecks, no silver
    bullets here!

                     CPU
                      CPU    Memory
                              Memory
      Your program




                     Disk
                      Disk   Network
                              Network

Recommandé

Java Performance: What developers must know
Java Performance: What developers must knowJava Performance: What developers must know
Java Performance: What developers must knowDiego Lemos
 
Effectiveness and code optimization in Java
Effectiveness and code optimization in JavaEffectiveness and code optimization in Java
Effectiveness and code optimization in JavaStrannik_2013
 
Testing sync engine
Testing sync engineTesting sync engine
Testing sync engineIlya Puchka
 
Analyzing Java Applications Using Thermostat (Omair Majid)
Analyzing Java Applications Using Thermostat (Omair Majid)Analyzing Java Applications Using Thermostat (Omair Majid)
Analyzing Java Applications Using Thermostat (Omair Majid)Red Hat Developers
 
Thinking Functionally with Clojure
Thinking Functionally with ClojureThinking Functionally with Clojure
Thinking Functionally with ClojureJohn Stevenson
 
Reactive programming using rx java & akka actors - pdx-scala - june 2014
Reactive programming   using rx java & akka actors - pdx-scala - june 2014Reactive programming   using rx java & akka actors - pdx-scala - june 2014
Reactive programming using rx java & akka actors - pdx-scala - june 2014Thomas Lockney
 

Contenu connexe

Tendances

Continuous Performance Regression Testing with JfrUnit
Continuous Performance Regression Testing with JfrUnitContinuous Performance Regression Testing with JfrUnit
Continuous Performance Regression Testing with JfrUnitScyllaDB
 
How To Get The Most Out Of Your Hibernate, JBoss EAP 7 Application (Ståle Ped...
How To Get The Most Out Of Your Hibernate, JBoss EAP 7 Application (Ståle Ped...How To Get The Most Out Of Your Hibernate, JBoss EAP 7 Application (Ståle Ped...
How To Get The Most Out Of Your Hibernate, JBoss EAP 7 Application (Ståle Ped...Red Hat Developers
 
The journey of a symfony app from 150ms to 20ms
The journey of a symfony app from 150ms to 20msThe journey of a symfony app from 150ms to 20ms
The journey of a symfony app from 150ms to 20msAlexandru Bumbacea
 
Benchmarks, performance, scalability, and capacity what's behind the numbers
Benchmarks, performance, scalability, and capacity what's behind the numbersBenchmarks, performance, scalability, and capacity what's behind the numbers
Benchmarks, performance, scalability, and capacity what's behind the numbersJustin Dorfman
 
S3, Cassandra or Outer Space? Dumping Time Series Data using Spark - Demi Be...
S3, Cassandra or Outer Space? Dumping Time Series Data using Spark  - Demi Be...S3, Cassandra or Outer Space? Dumping Time Series Data using Spark  - Demi Be...
S3, Cassandra or Outer Space? Dumping Time Series Data using Spark - Demi Be...Codemotion
 
Cassandra To Infinity And Beyond
Cassandra To Infinity And BeyondCassandra To Infinity And Beyond
Cassandra To Infinity And BeyondRomain Hardouin
 
BUD17-218: Scheduler Load tracking update and improvement
BUD17-218: Scheduler Load tracking update and improvement BUD17-218: Scheduler Load tracking update and improvement
BUD17-218: Scheduler Load tracking update and improvement Linaro
 
Create Your Own Operating System
Create Your Own Operating SystemCreate Your Own Operating System
Create Your Own Operating SystemOmkar Walavalkar
 
P99CONF — What We Need to Unlearn About Persistent Storage
P99CONF — What We Need to Unlearn About Persistent StorageP99CONF — What We Need to Unlearn About Persistent Storage
P99CONF — What We Need to Unlearn About Persistent StorageScyllaDB
 
Deployment of the Machine Learning at the production level
Deployment of the Machine Learning at the production levelDeployment of the Machine Learning at the production level
Deployment of the Machine Learning at the production levelIllarion Khlestov
 
Prometheus london
Prometheus londonPrometheus london
Prometheus londonwyukawa
 
Stress driven development
Stress driven developmentStress driven development
Stress driven developmentmitesh_sharma
 
Telemetry indepth
Telemetry indepthTelemetry indepth
Telemetry indepthTianyou Li
 
Get Lower Latency and Higher Throughput for Java Applications
Get Lower Latency and Higher Throughput for Java ApplicationsGet Lower Latency and Higher Throughput for Java Applications
Get Lower Latency and Higher Throughput for Java ApplicationsScyllaDB
 

Tendances (20)

Continuous Performance Regression Testing with JfrUnit
Continuous Performance Regression Testing with JfrUnitContinuous Performance Regression Testing with JfrUnit
Continuous Performance Regression Testing with JfrUnit
 
How To Get The Most Out Of Your Hibernate, JBoss EAP 7 Application (Ståle Ped...
How To Get The Most Out Of Your Hibernate, JBoss EAP 7 Application (Ståle Ped...How To Get The Most Out Of Your Hibernate, JBoss EAP 7 Application (Ståle Ped...
How To Get The Most Out Of Your Hibernate, JBoss EAP 7 Application (Ståle Ped...
 
The journey of a symfony app from 150ms to 20ms
The journey of a symfony app from 150ms to 20msThe journey of a symfony app from 150ms to 20ms
The journey of a symfony app from 150ms to 20ms
 
Benchmarks, performance, scalability, and capacity what's behind the numbers
Benchmarks, performance, scalability, and capacity what's behind the numbersBenchmarks, performance, scalability, and capacity what's behind the numbers
Benchmarks, performance, scalability, and capacity what's behind the numbers
 
S3, Cassandra or Outer Space? Dumping Time Series Data using Spark - Demi Be...
S3, Cassandra or Outer Space? Dumping Time Series Data using Spark  - Demi Be...S3, Cassandra or Outer Space? Dumping Time Series Data using Spark  - Demi Be...
S3, Cassandra or Outer Space? Dumping Time Series Data using Spark - Demi Be...
 
Test driving QML
Test driving QMLTest driving QML
Test driving QML
 
NRD: Nagios Result Distributor
NRD: Nagios Result DistributorNRD: Nagios Result Distributor
NRD: Nagios Result Distributor
 
Cassandra To Infinity And Beyond
Cassandra To Infinity And BeyondCassandra To Infinity And Beyond
Cassandra To Infinity And Beyond
 
BUD17-218: Scheduler Load tracking update and improvement
BUD17-218: Scheduler Load tracking update and improvement BUD17-218: Scheduler Load tracking update and improvement
BUD17-218: Scheduler Load tracking update and improvement
 
Create Your Own Operating System
Create Your Own Operating SystemCreate Your Own Operating System
Create Your Own Operating System
 
P99CONF — What We Need to Unlearn About Persistent Storage
P99CONF — What We Need to Unlearn About Persistent StorageP99CONF — What We Need to Unlearn About Persistent Storage
P99CONF — What We Need to Unlearn About Persistent Storage
 
Deployment of the Machine Learning at the production level
Deployment of the Machine Learning at the production levelDeployment of the Machine Learning at the production level
Deployment of the Machine Learning at the production level
 
Prometheus london
Prometheus londonPrometheus london
Prometheus london
 
Stress driven development
Stress driven developmentStress driven development
Stress driven development
 
Netty training
Netty trainingNetty training
Netty training
 
Telemetry indepth
Telemetry indepthTelemetry indepth
Telemetry indepth
 
Training – Going Async
Training – Going AsyncTraining – Going Async
Training – Going Async
 
Js on-microcontrollers
Js on-microcontrollersJs on-microcontrollers
Js on-microcontrollers
 
Get Lower Latency and Higher Throughput for Java Applications
Get Lower Latency and Higher Throughput for Java ApplicationsGet Lower Latency and Higher Throughput for Java Applications
Get Lower Latency and Higher Throughput for Java Applications
 
Into the domain
Into the domainInto the domain
Into the domain
 

En vedette

Code Optimization
Code OptimizationCode Optimization
Code Optimizationguest9f8315
 
code optimization
code optimization code optimization
code optimization Sanjeev Raaz
 
Sun jdk 1.6内存管理 -使用篇
Sun jdk 1.6内存管理 -使用篇Sun jdk 1.6内存管理 -使用篇
Sun jdk 1.6内存管理 -使用篇bluedavy lin
 
Optimizing your java applications for multi core hardware
Optimizing your java applications for multi core hardwareOptimizing your java applications for multi core hardware
Optimizing your java applications for multi core hardwareIndicThreads
 
OOP in Java - Ver1.1
OOP in Java -  Ver1.1OOP in Java -  Ver1.1
OOP in Java - Ver1.1vdlinh08
 
Java Performance Tuning
Java Performance TuningJava Performance Tuning
Java Performance TuningMinh Hoang
 
Java performance tuning
Java performance tuningJava performance tuning
Java performance tuningJerry Kurian
 
BKK16-302: Android Optimizing Compiler: New Member Assimilation Guide
BKK16-302: Android Optimizing Compiler: New Member Assimilation GuideBKK16-302: Android Optimizing Compiler: New Member Assimilation Guide
BKK16-302: Android Optimizing Compiler: New Member Assimilation GuideLinaro
 
Introduction of Java GC Tuning and Java Java Mission Control
Introduction of Java GC Tuning and Java Java Mission ControlIntroduction of Java GC Tuning and Java Java Mission Control
Introduction of Java GC Tuning and Java Java Mission ControlLeon Chen
 
Jvm Performance Tunning
Jvm Performance TunningJvm Performance Tunning
Jvm Performance TunningTerry Cho
 
LAS16-201: ART JIT in Android N
LAS16-201: ART JIT in Android NLAS16-201: ART JIT in Android N
LAS16-201: ART JIT in Android NLinaro
 
Online auction system srs riport
Online auction system srs  riportOnline auction system srs  riport
Online auction system srs riportDilip Prajapati
 
Code generator
Code generatorCode generator
Code generatorTech_MX
 
Basic Blocks and Flow Graphs
Basic Blocks and Flow GraphsBasic Blocks and Flow Graphs
Basic Blocks and Flow GraphsJenny Galino
 
Lex (lexical analyzer)
Lex (lexical analyzer)Lex (lexical analyzer)
Lex (lexical analyzer)Sami Said
 

En vedette (20)

Code optimization
Code optimizationCode optimization
Code optimization
 
Code Optimization
Code OptimizationCode Optimization
Code Optimization
 
code optimization
code optimization code optimization
code optimization
 
Sun jdk 1.6内存管理 -使用篇
Sun jdk 1.6内存管理 -使用篇Sun jdk 1.6内存管理 -使用篇
Sun jdk 1.6内存管理 -使用篇
 
Optimizing your java applications for multi core hardware
Optimizing your java applications for multi core hardwareOptimizing your java applications for multi core hardware
Optimizing your java applications for multi core hardware
 
OOP in Java - Ver1.1
OOP in Java -  Ver1.1OOP in Java -  Ver1.1
OOP in Java - Ver1.1
 
Memory leak
Memory leakMemory leak
Memory leak
 
Java Performance Tuning
Java Performance TuningJava Performance Tuning
Java Performance Tuning
 
Memory Leak In java
Memory Leak In javaMemory Leak In java
Memory Leak In java
 
Java performance tuning
Java performance tuningJava performance tuning
Java performance tuning
 
Basic Block
Basic BlockBasic Block
Basic Block
 
BKK16-302: Android Optimizing Compiler: New Member Assimilation Guide
BKK16-302: Android Optimizing Compiler: New Member Assimilation GuideBKK16-302: Android Optimizing Compiler: New Member Assimilation Guide
BKK16-302: Android Optimizing Compiler: New Member Assimilation Guide
 
Introduction of Java GC Tuning and Java Java Mission Control
Introduction of Java GC Tuning and Java Java Mission ControlIntroduction of Java GC Tuning and Java Java Mission Control
Introduction of Java GC Tuning and Java Java Mission Control
 
Jvm Performance Tunning
Jvm Performance TunningJvm Performance Tunning
Jvm Performance Tunning
 
Gc in android
Gc in androidGc in android
Gc in android
 
LAS16-201: ART JIT in Android N
LAS16-201: ART JIT in Android NLAS16-201: ART JIT in Android N
LAS16-201: ART JIT in Android N
 
Online auction system srs riport
Online auction system srs  riportOnline auction system srs  riport
Online auction system srs riport
 
Code generator
Code generatorCode generator
Code generator
 
Basic Blocks and Flow Graphs
Basic Blocks and Flow GraphsBasic Blocks and Flow Graphs
Basic Blocks and Flow Graphs
 
Lex (lexical analyzer)
Lex (lexical analyzer)Lex (lexical analyzer)
Lex (lexical analyzer)
 

Similaire à Performance optimization techniques for Java code

Utopia Kingdoms scaling case. From 4 users to 50.000+
Utopia Kingdoms scaling case. From 4 users to 50.000+Utopia Kingdoms scaling case. From 4 users to 50.000+
Utopia Kingdoms scaling case. From 4 users to 50.000+Python Ireland
 
Utopia Kindgoms scaling case: From 4 to 50K users
Utopia Kindgoms scaling case: From 4 to 50K usersUtopia Kindgoms scaling case: From 4 to 50K users
Utopia Kindgoms scaling case: From 4 to 50K usersJaime Buelta
 
Property-based testing an open-source compiler, pflua (FOSDEM 2015)
Property-based testing an open-source compiler, pflua (FOSDEM 2015)Property-based testing an open-source compiler, pflua (FOSDEM 2015)
Property-based testing an open-source compiler, pflua (FOSDEM 2015)Igalia
 
Gatling - Bordeaux JUG
Gatling - Bordeaux JUGGatling - Bordeaux JUG
Gatling - Bordeaux JUGslandelle
 
Machine Learning With H2O vs SparkML
Machine Learning With H2O vs SparkMLMachine Learning With H2O vs SparkML
Machine Learning With H2O vs SparkMLArnab Biswas
 
Speeding up Page Load Times by Using Starling
Speeding up Page Load Times by Using StarlingSpeeding up Page Load Times by Using Starling
Speeding up Page Load Times by Using StarlingErik Osterman
 
Ratpack the story so far
Ratpack the story so farRatpack the story so far
Ratpack the story so farPhill Barber
 
JVM Performance Tuning
JVM Performance TuningJVM Performance Tuning
JVM Performance TuningJeremy Leisy
 
SciPipe - A light-weight workflow library inspired by flow-based programming
SciPipe - A light-weight workflow library inspired by flow-based programmingSciPipe - A light-weight workflow library inspired by flow-based programming
SciPipe - A light-weight workflow library inspired by flow-based programmingSamuel Lampa
 
Spil Storage Platform (Erlang) @ EUG-NL
Spil Storage Platform (Erlang) @ EUG-NLSpil Storage Platform (Erlang) @ EUG-NL
Spil Storage Platform (Erlang) @ EUG-NLThijs Terlouw
 
The Good, the Bad and the Ugly things to do with android
The Good, the Bad and the Ugly things to do with androidThe Good, the Bad and the Ugly things to do with android
The Good, the Bad and the Ugly things to do with androidStanojko Markovik
 
Powering Tensorflow with big data using Apache Beam, Flink, and Spark - OSCON...
Powering Tensorflow with big data using Apache Beam, Flink, and Spark - OSCON...Powering Tensorflow with big data using Apache Beam, Flink, and Spark - OSCON...
Powering Tensorflow with big data using Apache Beam, Flink, and Spark - OSCON...Holden Karau
 
Programming with Threads in Java
Programming with Threads in JavaProgramming with Threads in Java
Programming with Threads in Javakoji lin
 

Similaire à Performance optimization techniques for Java code (20)

Utopia Kingdoms scaling case. From 4 users to 50.000+
Utopia Kingdoms scaling case. From 4 users to 50.000+Utopia Kingdoms scaling case. From 4 users to 50.000+
Utopia Kingdoms scaling case. From 4 users to 50.000+
 
Utopia Kindgoms scaling case: From 4 to 50K users
Utopia Kindgoms scaling case: From 4 to 50K usersUtopia Kindgoms scaling case: From 4 to 50K users
Utopia Kindgoms scaling case: From 4 to 50K users
 
Gpgpu intro
Gpgpu introGpgpu intro
Gpgpu intro
 
Property-based testing an open-source compiler, pflua (FOSDEM 2015)
Property-based testing an open-source compiler, pflua (FOSDEM 2015)Property-based testing an open-source compiler, pflua (FOSDEM 2015)
Property-based testing an open-source compiler, pflua (FOSDEM 2015)
 
Introduction to multicore .ppt
Introduction to multicore .pptIntroduction to multicore .ppt
Introduction to multicore .ppt
 
Java vs. C/C++
Java vs. C/C++Java vs. C/C++
Java vs. C/C++
 
Gatling - Bordeaux JUG
Gatling - Bordeaux JUGGatling - Bordeaux JUG
Gatling - Bordeaux JUG
 
Machine Learning With H2O vs SparkML
Machine Learning With H2O vs SparkMLMachine Learning With H2O vs SparkML
Machine Learning With H2O vs SparkML
 
Speeding up Page Load Times by Using Starling
Speeding up Page Load Times by Using StarlingSpeeding up Page Load Times by Using Starling
Speeding up Page Load Times by Using Starling
 
Ratpack the story so far
Ratpack the story so farRatpack the story so far
Ratpack the story so far
 
Play Framework
Play FrameworkPlay Framework
Play Framework
 
OpenMp
OpenMpOpenMp
OpenMp
 
JVM Performance Tuning
JVM Performance TuningJVM Performance Tuning
JVM Performance Tuning
 
SciPipe - A light-weight workflow library inspired by flow-based programming
SciPipe - A light-weight workflow library inspired by flow-based programmingSciPipe - A light-weight workflow library inspired by flow-based programming
SciPipe - A light-weight workflow library inspired by flow-based programming
 
Spil Storage Platform (Erlang) @ EUG-NL
Spil Storage Platform (Erlang) @ EUG-NLSpil Storage Platform (Erlang) @ EUG-NL
Spil Storage Platform (Erlang) @ EUG-NL
 
Shootout at the PAAS Corral
Shootout at the PAAS CorralShootout at the PAAS Corral
Shootout at the PAAS Corral
 
The Good, the Bad and the Ugly things to do with android
The Good, the Bad and the Ugly things to do with androidThe Good, the Bad and the Ugly things to do with android
The Good, the Bad and the Ugly things to do with android
 
Java under the hood
Java under the hoodJava under the hood
Java under the hood
 
Powering Tensorflow with big data using Apache Beam, Flink, and Spark - OSCON...
Powering Tensorflow with big data using Apache Beam, Flink, and Spark - OSCON...Powering Tensorflow with big data using Apache Beam, Flink, and Spark - OSCON...
Powering Tensorflow with big data using Apache Beam, Flink, and Spark - OSCON...
 
Programming with Threads in Java
Programming with Threads in JavaProgramming with Threads in Java
Programming with Threads in Java
 

Dernier

Avoiding Bad Stats and the Benefits of Playing Trivia with Friends: PancakesC...
Avoiding Bad Stats and the Benefits of Playing Trivia with Friends: PancakesC...Avoiding Bad Stats and the Benefits of Playing Trivia with Friends: PancakesC...
Avoiding Bad Stats and the Benefits of Playing Trivia with Friends: PancakesC...Adrian Sanabria
 
2024 February Patch Tuesday
2024 February Patch Tuesday2024 February Patch Tuesday
2024 February Patch TuesdayIvanti
 
Early Tech Adoption: Foolish or Pragmatic? - 17th ISACA South Florida WOW Con...
Early Tech Adoption: Foolish or Pragmatic? - 17th ISACA South Florida WOW Con...Early Tech Adoption: Foolish or Pragmatic? - 17th ISACA South Florida WOW Con...
Early Tech Adoption: Foolish or Pragmatic? - 17th ISACA South Florida WOW Con...Adrian Sanabria
 
My self introduction to know others abut me
My self  introduction to know others abut meMy self  introduction to know others abut me
My self introduction to know others abut meManoj Prabakar B
 
Zi-Stick UBS Dongle ZIgbee from Aeotec manual
Zi-Stick UBS Dongle ZIgbee from  Aeotec manualZi-Stick UBS Dongle ZIgbee from  Aeotec manual
Zi-Stick UBS Dongle ZIgbee from Aeotec manualDomotica daVinci
 
AWS reInvent 2023 recaps from Chicago AWS user group
AWS reInvent 2023 recaps from Chicago AWS user groupAWS reInvent 2023 recaps from Chicago AWS user group
AWS reInvent 2023 recaps from Chicago AWS user groupAWS Chicago
 
Manual sensor Zigbee 3.0 MOES ZSS-X-PIRL-C
Manual  sensor Zigbee 3.0 MOES ZSS-X-PIRL-CManual  sensor Zigbee 3.0 MOES ZSS-X-PIRL-C
Manual sensor Zigbee 3.0 MOES ZSS-X-PIRL-CDomotica daVinci
 
Microsoft Azure News - Feb 2024
Microsoft Azure News - Feb 2024Microsoft Azure News - Feb 2024
Microsoft Azure News - Feb 2024Daniel Toomey
 
Tete thermostatique Zigbee MOES BRT-100 V2.pdf
Tete thermostatique Zigbee MOES BRT-100 V2.pdfTete thermostatique Zigbee MOES BRT-100 V2.pdf
Tete thermostatique Zigbee MOES BRT-100 V2.pdfDomotica daVinci
 
5 Things You Shouldn’t Do at Salesforce World Tour Sydney 2024!
5 Things You Shouldn’t Do at Salesforce World Tour Sydney 2024!5 Things You Shouldn’t Do at Salesforce World Tour Sydney 2024!
5 Things You Shouldn’t Do at Salesforce World Tour Sydney 2024!XfilesPro
 
Q1 Memory Fabric Forum: Advantages of Optical CXL​ for Disaggregated Compute ...
Q1 Memory Fabric Forum: Advantages of Optical CXL​ for Disaggregated Compute ...Q1 Memory Fabric Forum: Advantages of Optical CXL​ for Disaggregated Compute ...
Q1 Memory Fabric Forum: Advantages of Optical CXL​ for Disaggregated Compute ...Memory Fabric Forum
 
Q1 Memory Fabric Forum: SMART CXL Product Lineup
Q1 Memory Fabric Forum: SMART CXL Product LineupQ1 Memory Fabric Forum: SMART CXL Product Lineup
Q1 Memory Fabric Forum: SMART CXL Product LineupMemory Fabric Forum
 
Navigating the Never Normal Strategies for Portfolio Leaders
Navigating the Never Normal Strategies for Portfolio LeadersNavigating the Never Normal Strategies for Portfolio Leaders
Navigating the Never Normal Strategies for Portfolio LeadersOnePlan Solutions
 
M.Aathiraju Self Intro.docx-AD21001_____
M.Aathiraju Self Intro.docx-AD21001_____M.Aathiraju Self Intro.docx-AD21001_____
M.Aathiraju Self Intro.docx-AD21001_____Aathiraju
 
zigbee motion sensor user manual NAS-PD07B2.pdf
zigbee motion sensor user manual NAS-PD07B2.pdfzigbee motion sensor user manual NAS-PD07B2.pdf
zigbee motion sensor user manual NAS-PD07B2.pdfDomotica daVinci
 
Curtain Module Manual Zigbee Neo CS01-1C.pdf
Curtain Module Manual Zigbee Neo CS01-1C.pdfCurtain Module Manual Zigbee Neo CS01-1C.pdf
Curtain Module Manual Zigbee Neo CS01-1C.pdfDomotica daVinci
 
Importance of magazines in education ppt
Importance of magazines in education pptImportance of magazines in education ppt
Importance of magazines in education pptsafnarafeek2002
 
21ST CENTURY LITERACY FROM TRADITIONAL TO MODERN
21ST CENTURY LITERACY FROM TRADITIONAL TO MODERN21ST CENTURY LITERACY FROM TRADITIONAL TO MODERN
21ST CENTURY LITERACY FROM TRADITIONAL TO MODERNRonnelBaroc
 
DNA LIGASE BIOTECHNOLOGY BIOLOGY STUDY OF LIFE
DNA LIGASE BIOTECHNOLOGY BIOLOGY STUDY OF LIFEDNA LIGASE BIOTECHNOLOGY BIOLOGY STUDY OF LIFE
DNA LIGASE BIOTECHNOLOGY BIOLOGY STUDY OF LIFEandreiandasan
 
Power of 2024 - WITforce Odyssey.pptx.pdf
Power of 2024 - WITforce Odyssey.pptx.pdfPower of 2024 - WITforce Odyssey.pptx.pdf
Power of 2024 - WITforce Odyssey.pptx.pdfkatalinjordans1
 

Dernier (20)

Avoiding Bad Stats and the Benefits of Playing Trivia with Friends: PancakesC...
Avoiding Bad Stats and the Benefits of Playing Trivia with Friends: PancakesC...Avoiding Bad Stats and the Benefits of Playing Trivia with Friends: PancakesC...
Avoiding Bad Stats and the Benefits of Playing Trivia with Friends: PancakesC...
 
2024 February Patch Tuesday
2024 February Patch Tuesday2024 February Patch Tuesday
2024 February Patch Tuesday
 
Early Tech Adoption: Foolish or Pragmatic? - 17th ISACA South Florida WOW Con...
Early Tech Adoption: Foolish or Pragmatic? - 17th ISACA South Florida WOW Con...Early Tech Adoption: Foolish or Pragmatic? - 17th ISACA South Florida WOW Con...
Early Tech Adoption: Foolish or Pragmatic? - 17th ISACA South Florida WOW Con...
 
My self introduction to know others abut me
My self  introduction to know others abut meMy self  introduction to know others abut me
My self introduction to know others abut me
 
Zi-Stick UBS Dongle ZIgbee from Aeotec manual
Zi-Stick UBS Dongle ZIgbee from  Aeotec manualZi-Stick UBS Dongle ZIgbee from  Aeotec manual
Zi-Stick UBS Dongle ZIgbee from Aeotec manual
 
AWS reInvent 2023 recaps from Chicago AWS user group
AWS reInvent 2023 recaps from Chicago AWS user groupAWS reInvent 2023 recaps from Chicago AWS user group
AWS reInvent 2023 recaps from Chicago AWS user group
 
Manual sensor Zigbee 3.0 MOES ZSS-X-PIRL-C
Manual  sensor Zigbee 3.0 MOES ZSS-X-PIRL-CManual  sensor Zigbee 3.0 MOES ZSS-X-PIRL-C
Manual sensor Zigbee 3.0 MOES ZSS-X-PIRL-C
 
Microsoft Azure News - Feb 2024
Microsoft Azure News - Feb 2024Microsoft Azure News - Feb 2024
Microsoft Azure News - Feb 2024
 
Tete thermostatique Zigbee MOES BRT-100 V2.pdf
Tete thermostatique Zigbee MOES BRT-100 V2.pdfTete thermostatique Zigbee MOES BRT-100 V2.pdf
Tete thermostatique Zigbee MOES BRT-100 V2.pdf
 
5 Things You Shouldn’t Do at Salesforce World Tour Sydney 2024!
5 Things You Shouldn’t Do at Salesforce World Tour Sydney 2024!5 Things You Shouldn’t Do at Salesforce World Tour Sydney 2024!
5 Things You Shouldn’t Do at Salesforce World Tour Sydney 2024!
 
Q1 Memory Fabric Forum: Advantages of Optical CXL​ for Disaggregated Compute ...
Q1 Memory Fabric Forum: Advantages of Optical CXL​ for Disaggregated Compute ...Q1 Memory Fabric Forum: Advantages of Optical CXL​ for Disaggregated Compute ...
Q1 Memory Fabric Forum: Advantages of Optical CXL​ for Disaggregated Compute ...
 
Q1 Memory Fabric Forum: SMART CXL Product Lineup
Q1 Memory Fabric Forum: SMART CXL Product LineupQ1 Memory Fabric Forum: SMART CXL Product Lineup
Q1 Memory Fabric Forum: SMART CXL Product Lineup
 
Navigating the Never Normal Strategies for Portfolio Leaders
Navigating the Never Normal Strategies for Portfolio LeadersNavigating the Never Normal Strategies for Portfolio Leaders
Navigating the Never Normal Strategies for Portfolio Leaders
 
M.Aathiraju Self Intro.docx-AD21001_____
M.Aathiraju Self Intro.docx-AD21001_____M.Aathiraju Self Intro.docx-AD21001_____
M.Aathiraju Self Intro.docx-AD21001_____
 
zigbee motion sensor user manual NAS-PD07B2.pdf
zigbee motion sensor user manual NAS-PD07B2.pdfzigbee motion sensor user manual NAS-PD07B2.pdf
zigbee motion sensor user manual NAS-PD07B2.pdf
 
Curtain Module Manual Zigbee Neo CS01-1C.pdf
Curtain Module Manual Zigbee Neo CS01-1C.pdfCurtain Module Manual Zigbee Neo CS01-1C.pdf
Curtain Module Manual Zigbee Neo CS01-1C.pdf
 
Importance of magazines in education ppt
Importance of magazines in education pptImportance of magazines in education ppt
Importance of magazines in education ppt
 
21ST CENTURY LITERACY FROM TRADITIONAL TO MODERN
21ST CENTURY LITERACY FROM TRADITIONAL TO MODERN21ST CENTURY LITERACY FROM TRADITIONAL TO MODERN
21ST CENTURY LITERACY FROM TRADITIONAL TO MODERN
 
DNA LIGASE BIOTECHNOLOGY BIOLOGY STUDY OF LIFE
DNA LIGASE BIOTECHNOLOGY BIOLOGY STUDY OF LIFEDNA LIGASE BIOTECHNOLOGY BIOLOGY STUDY OF LIFE
DNA LIGASE BIOTECHNOLOGY BIOLOGY STUDY OF LIFE
 
Power of 2024 - WITforce Odyssey.pptx.pdf
Power of 2024 - WITforce Odyssey.pptx.pdfPower of 2024 - WITforce Odyssey.pptx.pdf
Power of 2024 - WITforce Odyssey.pptx.pdf
 

Performance optimization techniques for Java code

  • 2. Who am I and why should you trust me?  ● Attila-Mihály Balázs http://hype-free.blogspot.com/ ● Former malware researcher (”low-level guy”) ● Current Java dev (”high level dude”) ● Spent the last ~6 monts optimizing a large (1 000 000+ LOC) legacy system ● Will spend the next 6 months on it too (at least )
  • 4. What's this about ● Core principles ● Demo 1: collections framework ● Demo 2, 3, 4: synchronization performance ● Demo 5: ugly code, is it worth it? ● Demo 6, 7, 8: playing with Strings ● Conclusions ● Q&A
  • 5. What this is not about ● Selecting efficient algorithms ● High level optimizations (architectural changes) ● These are important too! (but require more effort, and we are going for the quick win here)
  • 6. Core principles ● Performance is a balence, and endless game of shifting bottlenecks, no silver bullets here! CPU CPU Memory Memory Your program Disk Disk Network Network
  • 7. Perform on all levels! ● Performance has many levels: – Compiler (JIT): 5 to 6: 100%(1) – Memory: L1/L2 cache, main memory – Disk: cache, RAID, SSD – Network: 10Mbit, 100Mbit, 1000Mbit ● Until recently we had it easy (performance doubled every 18 months) ● Now we need to do some work (1) http://java.sun.com/performance/reference/whitepapers/6_performance.html
  • 8. Core principles ● Measure, measure, measure! (before, during, after). ● Try using realistic data! ● Watch out for the Heisenberg effect (more on this later) ● Some things are not intuitive: – Pop-question: if processing 1000 messages takes 1 second, how long does the processing of 1 message take?
  • 9. Core principles ● Troughput ● Latency ● Thread context, context switching ● Lock contention ● Queueing theory ● Profiling ● Sampling
  • 10. Feasibility – ”numbers everyone should know” (2) ● L1 cache reference 0.5 ns ● Branch mispredict 5 ns ● L2 cache reference 7 ns ● Mutex lock/unlock 100 ns ● Main memory reference 100 ns ● Compress 1K bytes with Zippy 10,000 ns ● Send 2K bytes over 1 Gbps network 20,000 ns ● Read 1 MB sequentially from memory 250,000 ns ● Round trip within same datacenter 500,000 ns ● Disk seek 10,000,000 ns ● Read 1 MB sequentially from network 10,000,000 ns ● Read 1 MB sequentially from disk 30,000,000 ns ● Send packet CA->Netherlands->CA 150,000,000 n (2) http://research.google.com/people/jeff/stanford-295-talk.pdf
  • 11. Feasability ● Amdahl's law: The speedup of a program using multiple processors in parallel computing is limited by the time needed for the sequential fraction of the program.
  • 12. Course of action ● Have a clear (written?), measourable goal: operation X should take less than 100ms in 99.9% of the cases ● Measure (profile) ● Is the goal met? → The End ● Optimize hotspots → go to step 2
  • 13. Tools ● VisualVM ● JProfiler ● YourKit ● Eclipse TPTP ● Netbeans Profiler
  • 14. Demo 1: collections framework ● Name 3 things wrong with this code: Vector<String> v1; … if (!v1.contains(s)) { v1.add(s); }
  • 15. Demo 1: collections framework ● Wrong data structure (list / array instead of set), hence slooow performance for large data sets (but not for small ones!) ● Extra synchronization if used by a single thread only ● Not actually thread safe! (only ”exception safe”)
  • 16. Demo 1: lessons ● Use existing classes ● Use realistic sample data ● Thread safety is hard! ● Heisenberg (observer) effect
  • 17. Demo 2, 3, 4: synchronization performance ● If I have N units of work and use 4, it must be faster than using a single thread, right? ● What does lock contention look like? ● What does a ”synchronization train(wreck)” look like?
  • 18. Demo 2, 3, 4: lessons ● Use existing classes – ReadWriteLock – java.util.concurrent.* ● Use realistic sample data (too short / too long units of work) ● Sometimes throwing a threadpool at it makes it worse! ● Consider using a private copy of the variable for each thread
  • 19. Demo 5: ugly code, is it worth it? ● Parsing a logfile
  • 20. Demo 5: lessons ● Sometimes yes, but always profile first!
  • 21. Demo 6: String.substring ● How are strings stored in Java?
  • 22. Demo 6: Lesson ● You can look inside the JRE when needed!
  • 24. Demo 7: Lessons ● You shouldn't use String.intern: – Slow – You have to use it everywhere – Needs hand-tuning ● Use a WeakHashMap for caching (don't forget to synchronize!) ● Use String.equals (not ==)
  • 25. Demo 8: charsets – ASCII – ISO-8859-1 – UTF-8 – UTF-16
  • 26. Demo 8: lessons ● Use UTF-8 where possible
  • 27. Conclusions ● Measure twice, cut once ● Don't trust advice you didn't test! (including mine) ● Most of the time you don't need to sacrifice clean code for performant code
  • 28. Conclusions ● Slides: – Google Groups – http://hype-free.blogspot.com/ – x_at_y_or_z@yahoo.com ● Source code: – http://code.google.com/p/hype- free/source/browse/#svn/trunk/java- perfopt-201003 ● Profiler evaluation licenses
  • 29. Resources ● https://visualvm.dev.java.net/ ● http://www.ej-technologies.com/ ● http://blog.ej-technologies.com/ ● http://www.yourkit.com/ ● http://www.yourkit.com/docs/index.jsp ● http://www.yourkit.com/eap/index.jsp