SlideShare a Scribd company logo
Application Profiling
          for
Memory & Performance
Srinath Perera   Pradeep Fernando   Dinuka Malalanayke
  WSO2 Inc           WSO2 Inc           WSO2 Inc
Understanding Server Performance
When Concurrency Increases?


•   Throughput increases, but where will it stop?
•   When there are contention for the server
•   Contention for what?
    o   CPU
    o   Memory
    o   Disk - I/O
    o   Network -I/O
•   If your server running on full capacity, there should be at
    least one resource under contention.
How to measure Contention?


•   CPU - CPU or load average
•   Memory - GC logs, monitor memory, sometime swapping
•   Disk I/O - IOPS per seconds, load average
•   Network I/O - network utilization, load average
•   What is load average? length of processor queue of the OS
•   How much load average is too much?
    o   Load average = number of cores (machine is fully used)
    o   Load average = 2* number of cores (machine is loaded)
If you cannot find contention

•   Either load is too small
•   You have too much locks. Look for lock profile
•   Server might be processing with too less threads (IO and
    CPU thread switches)
Performance Tuning


•   Increase throughput/ latency or both
•   Know that latency vs. throughput is often a tradeoff
•   Run the system and see how it does, make sure you are
    putting in enough load
•   Verify where is the bottleneck? is it CPU, memory, network,
    or disk
•   Start tuning
Tuning



•   When you tune, bottlenecks will shift, you will have to shift
    your focus
•   Can you tune settings (Application, JVM, OS) to improve and
    shift the bottleneck? play with parameters .. we call this
    parameter sweep
•   Then focus on the code, look for right profile
    o   CPU profile
    o   Memory/ Allocation profile
    o   Network profile
    o   IO profile
    o   Database profile
Programmer Nightmares
Programmer Nightmares



                  ClassCastException
                        Permgen Errors
            DeadLocks
                           NullPointer
     Unacceptable Latency
     CPU spin       OutofMemoryException
            ArrayIndexOutOfBoundsException

[image] http://www1.free-clipart.net/gallery2/clipart/Holidays/Halloween/Ghost_-_Boo.jpg
Introducing: Profiling...



•   Best thing would be to write bug free, high performant code
•   Normally development happens in iterative manner - get
    something to work and improve on that.
•   Basic profiling can help you to eliminate most of the memory
    and performance issues.
Right Tools...


•       There are many commercial and open source tools
•       We are going to use,
         o       Jprofiler by ejTechnologies
                     CPU, Memory, Allocation, Network, DB
         o       Eclipse Memory Analyzer tool
                     Find memory leaks
         o       Standard JDK tooling - Jconsole
                     Basic stats




    [image] http://writingsongs.com/pictures/toolbox.jpg
Environment Setup
    With WSO2 Carbon
Setting up JProfiler

•   Profiling modes local/remote
•   Applying common filters for WSO2 products
•   Different views..
JProfiler Contd.


CPU view
 - Call trees, Hot spots
Memory view
 - Allocation Hot spots, Recorded objects, Heap walker
VM telemetry view
 - Memory, Threads status graphs
Probes
  - JDBC , Sockets
JConsole


•   Connect to the running instance local/remote
•   Different memory banks
•   Getting most out of Mbeans.
•   Getting a memory dump and analyzing with Eclipse MAT.
•   Remote JMX URL gets printed in the console during server
    startup:

       JMX Service URL : service:jmx:rmi://localhost:11111/jndi/rmi://localhost:9999/jmxrmi
       username : admin password : admin
JConsole
Memory Analyzer Tool


•   Analyze heap dumps.
•   Identifying OOM issues are trivial with basic leak report.
Usual Suspects

 Some of the common issues...
Permgen Errors


•   Permgen space relates to the 'Programme code' part, a.k.a -
    Loaded classes.
•   ClassLoader leaks
•   Typically happens in Container environments
•   Can uncover by doing deploy/redeploy cycles.
•   If one of the application objects get referenced by an object,
    outside the application, permgen error waiting to happen.
Permgen Errors



Container

                  URLClassLoader             Application




                                      Application Objects
    Container provided
         Objects
Memory Leaks - OOM


•   Languages like C, gave the control of memory to the
    programmer.
•   Java is a managed memory, language.
•   Still the JVM can't free up the memory, if the application is
    holding on to the objects.
•   Unnecessary accumulation of objects,
    o   Object creation for each and every connection
    o   Slow output rate in the input/output system
    o   Collecting clusterwide messages without an upper bound.
DeadLocks



                          Resource A




                          Resource B




•   Re-designing the lock acquiring sequence
•   Using LockManagers that keeps track of lock acquisition
Liveness issues...




•   Starvation - A thread can starve for CPU cycles, if it is
    blocked by a lock-wait.
•   Poor Responsiveness
•   LiveLock scenarios
Programming Best Practices



•   Think about memory aspects/ data retrieval process while
    writing code.
•   Optimize the critical Path (look at CPU profile).
•   Make use of Standard libs as much as possible.
•   Profile your apps before releasing them to production.
WSO2 make use of profiling ?
Identity Server - Losing weight




• Carbon server optimized to run in constrained memory
  environment.
• No front end components - 'createWorker' ant task.
• Selective Admin service loading. -Doptimized=true
• Removed unwanted functionality based on the use-case,
  (p2 - provisioning, etc)
Raspberry-Pi Clusters



   •   Application server
       cluster running on R-
       Pis.
   •   Powering the
       WSO2Con 2013
       mobile app
   •   512MB of RAM and
       ARM processor.
Demo

CPU spin and Memory leak scenario
Questions
Thank You

More Related Content

PDF
Mastering PostgreSQL Administration
 
PDF
PostgreSQL Replication Tutorial
PDF
Linux Instrumentation
PDF
Kernel Recipes 2017: Using Linux perf at Netflix
PDF
Vmlinux: anatomy of bzimage and how x86 64 processor is booted
PDF
Linux 4.x Tracing Tools: Using BPF Superpowers
PPTX
Linux Kernel Booting Process (2) - For NLKB
PDF
USENIX ATC 2017: Visualizing Performance with Flame Graphs
Mastering PostgreSQL Administration
 
PostgreSQL Replication Tutorial
Linux Instrumentation
Kernel Recipes 2017: Using Linux perf at Netflix
Vmlinux: anatomy of bzimage and how x86 64 processor is booted
Linux 4.x Tracing Tools: Using BPF Superpowers
Linux Kernel Booting Process (2) - For NLKB
USENIX ATC 2017: Visualizing Performance with Flame Graphs

What's hot (20)

PDF
Apache Spark Core – Practical Optimization
PDF
Linux Performance Analysis: New Tools and Old Secrets
PPTX
Achieving High Availability in PostgreSQL
ODP
OpenGurukul : Database : PostgreSQL
PPTX
Postgresql Database Administration Basic - Day1
PDF
Advanced Apache Cassandra Operations with JMX
PDF
5 Steps to PostgreSQL Performance
PDF
Mastering PostgreSQL Administration
PDF
Apache Iceberg - A Table Format for Hige Analytic Datasets
PDF
Memory management in Linux kernel
PDF
Performance Wins with eBPF: Getting Started (2021)
PDF
LISA2019 Linux Systems Performance
PDF
Oracle Database 12c Multitenant for Consolidation
PDF
What’s New in the Upcoming Apache Spark 3.0
PDF
Linux Kernel - Virtual File System
PDF
InfluxDB IOx Tech Talks: Replication, Durability and Subscriptions in InfluxD...
PDF
The evolution of Apache Calcite and its Community
PDF
Spark 2.x Troubleshooting Guide
 
PDF
Performance Analysis Tools for Linux Kernel
PDF
MariaDB 10: The Complete Tutorial
Apache Spark Core – Practical Optimization
Linux Performance Analysis: New Tools and Old Secrets
Achieving High Availability in PostgreSQL
OpenGurukul : Database : PostgreSQL
Postgresql Database Administration Basic - Day1
Advanced Apache Cassandra Operations with JMX
5 Steps to PostgreSQL Performance
Mastering PostgreSQL Administration
Apache Iceberg - A Table Format for Hige Analytic Datasets
Memory management in Linux kernel
Performance Wins with eBPF: Getting Started (2021)
LISA2019 Linux Systems Performance
Oracle Database 12c Multitenant for Consolidation
What’s New in the Upcoming Apache Spark 3.0
Linux Kernel - Virtual File System
InfluxDB IOx Tech Talks: Replication, Durability and Subscriptions in InfluxD...
The evolution of Apache Calcite and its Community
Spark 2.x Troubleshooting Guide
 
Performance Analysis Tools for Linux Kernel
MariaDB 10: The Complete Tutorial
Ad

Similar to Application Profiling for Memory and Performance (20)

PDF
Application Profiling for Memory and Performance
PPTX
Attack on the Core
KEY
Deployment Strategy
PDF
Deployment
KEY
Deployment Strategies
KEY
Deployment Strategies (Mongo Austin)
PDF
Experiences with Debugging Data Races
PPTX
Using the big guns: Advanced OS performance tools for troubleshooting databas...
PPTX
Fastest Servlets in the West
PDF
NSC #2 - D3 02 - Peter Hlavaty - Attack on the Core
PPTX
Computer system organization
PDF
Machine Learning With H2O vs SparkML
PDF
"You Don't Know NODE.JS" by Hengki Mardongan Sihombing (Urbanhire)
PPTX
Spark Tips & Tricks
PPT
Compilers and interpreters
PDF
Java troubleshooting thread dump
PDF
TechGIG_Memory leaks in_java_webnair_26th_july_2012
PDF
Oracle WebLogic Diagnostics & Perfomance tuning
PDF
Web Sphere Problem Determination Ext
PPTX
Azug - successfully breeding rabits
Application Profiling for Memory and Performance
Attack on the Core
Deployment Strategy
Deployment
Deployment Strategies
Deployment Strategies (Mongo Austin)
Experiences with Debugging Data Races
Using the big guns: Advanced OS performance tools for troubleshooting databas...
Fastest Servlets in the West
NSC #2 - D3 02 - Peter Hlavaty - Attack on the Core
Computer system organization
Machine Learning With H2O vs SparkML
"You Don't Know NODE.JS" by Hengki Mardongan Sihombing (Urbanhire)
Spark Tips & Tricks
Compilers and interpreters
Java troubleshooting thread dump
TechGIG_Memory leaks in_java_webnair_26th_july_2012
Oracle WebLogic Diagnostics & Perfomance tuning
Web Sphere Problem Determination Ext
Azug - successfully breeding rabits
Ad

Recently uploaded (20)

PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PPTX
A Presentation on Artificial Intelligence
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Approach and Philosophy of On baking technology
PDF
Empathic Computing: Creating Shared Understanding
PDF
Modernizing your data center with Dell and AMD
PPT
Teaching material agriculture food technology
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Electronic commerce courselecture one. Pdf
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PDF
cuic standard and advanced reporting.pdf
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
A Presentation on Artificial Intelligence
Diabetes mellitus diagnosis method based random forest with bat algorithm
Approach and Philosophy of On baking technology
Empathic Computing: Creating Shared Understanding
Modernizing your data center with Dell and AMD
Teaching material agriculture food technology
The AUB Centre for AI in Media Proposal.docx
Unlocking AI with Model Context Protocol (MCP)
Review of recent advances in non-invasive hemoglobin estimation
Network Security Unit 5.pdf for BCA BBA.
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
Spectral efficient network and resource selection model in 5G networks
Dropbox Q2 2025 Financial Results & Investor Presentation
Electronic commerce courselecture one. Pdf
CIFDAQ's Market Insight: SEC Turns Pro Crypto
cuic standard and advanced reporting.pdf
How UI/UX Design Impacts User Retention in Mobile Apps.pdf

Application Profiling for Memory and Performance

  • 1. Application Profiling for Memory & Performance Srinath Perera Pradeep Fernando Dinuka Malalanayke WSO2 Inc WSO2 Inc WSO2 Inc
  • 3. When Concurrency Increases? • Throughput increases, but where will it stop? • When there are contention for the server • Contention for what? o CPU o Memory o Disk - I/O o Network -I/O • If your server running on full capacity, there should be at least one resource under contention.
  • 4. How to measure Contention? • CPU - CPU or load average • Memory - GC logs, monitor memory, sometime swapping • Disk I/O - IOPS per seconds, load average • Network I/O - network utilization, load average • What is load average? length of processor queue of the OS • How much load average is too much? o Load average = number of cores (machine is fully used) o Load average = 2* number of cores (machine is loaded)
  • 5. If you cannot find contention • Either load is too small • You have too much locks. Look for lock profile • Server might be processing with too less threads (IO and CPU thread switches)
  • 6. Performance Tuning • Increase throughput/ latency or both • Know that latency vs. throughput is often a tradeoff • Run the system and see how it does, make sure you are putting in enough load • Verify where is the bottleneck? is it CPU, memory, network, or disk • Start tuning
  • 7. Tuning • When you tune, bottlenecks will shift, you will have to shift your focus • Can you tune settings (Application, JVM, OS) to improve and shift the bottleneck? play with parameters .. we call this parameter sweep • Then focus on the code, look for right profile o CPU profile o Memory/ Allocation profile o Network profile o IO profile o Database profile
  • 9. Programmer Nightmares ClassCastException Permgen Errors DeadLocks NullPointer Unacceptable Latency CPU spin OutofMemoryException ArrayIndexOutOfBoundsException [image] http://www1.free-clipart.net/gallery2/clipart/Holidays/Halloween/Ghost_-_Boo.jpg
  • 10. Introducing: Profiling... • Best thing would be to write bug free, high performant code • Normally development happens in iterative manner - get something to work and improve on that. • Basic profiling can help you to eliminate most of the memory and performance issues.
  • 11. Right Tools... • There are many commercial and open source tools • We are going to use, o Jprofiler by ejTechnologies  CPU, Memory, Allocation, Network, DB o Eclipse Memory Analyzer tool  Find memory leaks o Standard JDK tooling - Jconsole  Basic stats [image] http://writingsongs.com/pictures/toolbox.jpg
  • 12. Environment Setup With WSO2 Carbon
  • 13. Setting up JProfiler • Profiling modes local/remote • Applying common filters for WSO2 products • Different views..
  • 14. JProfiler Contd. CPU view - Call trees, Hot spots Memory view - Allocation Hot spots, Recorded objects, Heap walker VM telemetry view - Memory, Threads status graphs Probes - JDBC , Sockets
  • 15. JConsole • Connect to the running instance local/remote • Different memory banks • Getting most out of Mbeans. • Getting a memory dump and analyzing with Eclipse MAT. • Remote JMX URL gets printed in the console during server startup: JMX Service URL : service:jmx:rmi://localhost:11111/jndi/rmi://localhost:9999/jmxrmi username : admin password : admin
  • 17. Memory Analyzer Tool • Analyze heap dumps. • Identifying OOM issues are trivial with basic leak report.
  • 18. Usual Suspects Some of the common issues...
  • 19. Permgen Errors • Permgen space relates to the 'Programme code' part, a.k.a - Loaded classes. • ClassLoader leaks • Typically happens in Container environments • Can uncover by doing deploy/redeploy cycles. • If one of the application objects get referenced by an object, outside the application, permgen error waiting to happen.
  • 20. Permgen Errors Container URLClassLoader Application Application Objects Container provided Objects
  • 21. Memory Leaks - OOM • Languages like C, gave the control of memory to the programmer. • Java is a managed memory, language. • Still the JVM can't free up the memory, if the application is holding on to the objects. • Unnecessary accumulation of objects, o Object creation for each and every connection o Slow output rate in the input/output system o Collecting clusterwide messages without an upper bound.
  • 22. DeadLocks Resource A Resource B • Re-designing the lock acquiring sequence • Using LockManagers that keeps track of lock acquisition
  • 23. Liveness issues... • Starvation - A thread can starve for CPU cycles, if it is blocked by a lock-wait. • Poor Responsiveness • LiveLock scenarios
  • 24. Programming Best Practices • Think about memory aspects/ data retrieval process while writing code. • Optimize the critical Path (look at CPU profile). • Make use of Standard libs as much as possible. • Profile your apps before releasing them to production.
  • 25. WSO2 make use of profiling ?
  • 26. Identity Server - Losing weight • Carbon server optimized to run in constrained memory environment. • No front end components - 'createWorker' ant task. • Selective Admin service loading. -Doptimized=true • Removed unwanted functionality based on the use-case, (p2 - provisioning, etc)
  • 27. Raspberry-Pi Clusters • Application server cluster running on R- Pis. • Powering the WSO2Con 2013 mobile app • 512MB of RAM and ARM processor.
  • 28. Demo CPU spin and Memory leak scenario