SlideShare a Scribd company logo
1 of 37
Mark Thomas
 Tomcat Optimisation   Senior Consultant
& Performance Tuning   SpringSource
Who am I?
•Apache Tomcat committer for over 5 years

•Resolved 1,500+ Tomcat bugs

•Apache Tomcat PMC member

•Member of the Apache Software Foundation

•Member of the ASF security committee

•Created the Tomcat security pages

•Senior Software Engineer and Consultant at
 SpringSource
Agenda
•The optimisation / tuning process

•Tomcat tuning options

 •logging
 •connectors
 •content cache
 •JVM

•Scaling Tomcat

•Hints and tips
Agenda
•The optimisation / tuning process

•Tomcat tuning options
 •logging
 •connectors
 •content cache
 •JVM

•Scaling Tomcat

•Hints and tips
The process
•Understand the system architecture

•Stabilise the system

•Set the performance target(s)

•Measure current performance

•Identify the current bottleneck

•Fix the root cause of the bottleneck

•Repeat until you meet the target
Common errors
•Optimising code that doesn't need it

•Insufficient testing

 •realistic data volumes
 •realistic user load

•Lack of clear performance targets

•Guessing where the bottleneck is

•Fixing the symptom rather than the cause
Agenda
•The optimisation / tuning process

•Tomcat tuning options
 •logging
 •connectors
 •content cache
 •JVM

•Scaling Tomcat

•Hints and tips
Tomcat tuning
•Applications typically account for >80% of request
 processing time

•Remember the tuning process

 •focus your efforts on the bottlenecks
Agenda
•The optimisation / tuning process

•Tomcat tuning options
 •logging
 •connectors
 •content cache
 •JVM

•Scaling Tomcat

•Hints and tips
Production logging
•Default configuration is generic

•Some settings not ideal for production

 •catch-all logger logs to file and stdout
 •no overflow protection
 •logging is synchronised
Production logging
•Remove duplicate logging (logging.properties)
        .handlers = 1catalina.org.apache.juli.FileHandler,
                    java.util.logging.ConsoleHandler
•becomes
        .handlers = 1catalina.org.apache.juli.FileHandler


•to add rotation
     1catalina.java.util.logging.FileHandler.pattern =
          ${catalina.base}/logs/catalina.%g.log
     1catalina.java.util.logging.FileHandler.limit = 20000000
     1catalina.java.util.logging.FileHandler.count = 5
Production logging
•Synchronous logging:

 •can become a bottleneck
 •don't want disk IO to become the limiting factor

•Asynchronous logging:

 •log queue uses memory
 •limit queue size to avoid out of memory errors
 •fall back to synchronised   logging and/or drop some log messages
Agenda
•The optimisation / tuning process

•Tomcat tuning options
 •logging
 •connectors
 •content cache
 •JVM

•Scaling Tomcat

•Hints and tips
Connector tuning
•Need to understand

 •your application usage patterns

 •TCP connections

 •HTTP transactions
 •HTTP Keep-Alive
 •SSL
Connector tuning
•Additional considerations for load balancing

 •Layer 4 or Layer 7
 •Connection pools
Which connector?
•Java Blocking IO

 •Oldest – most stable
 •JSSE based SSL

•Native (APR)

 •Non-blocking
 •Uses OpenSSL

•Java Non-blocking IO

 •JSSE based SSL
Which connector?

Requirement        Preference order
Stability          BIO       APR      NIO
SSL                APR       NIO      BIO
Low concurrency    BIO       APR      NIO
High concurrency   BIO       APR      NIO
No Keep-Alive

High concurrency   APR       NIO      BIO
Keep-Alive
Which connector?
•Why would you use the NIO connector?

•The Native (APR) connector is unstable on Solaris

•NIO is a pure Java solution

•It is easy to switch between NIO and BIO with SSL
Connector tuning

•maxThreads
 •typical values 200 – 800
 •maximum number of concurrent requests
 •for BIO, maximum number of open/active
  connections
 •400 is a good starting value
 •heavy CPU usage → decrease
 •light CPU usage → increase
Connector tuning
•maxKeepAliveRequests
 •typical values 1, 100
 •maximum number of HTTP requests per TCP
  connection
 •set to 1 to disable keep alive
 •disable for BIO with very high concurrency, layer 4
  load balancer, no SSL
 •enable for SSL, APR/NIO, layer 7 load balancer
•Note BIO connector automatically disables keep alive
 when concurrent connections are high
Connector tuning
•connectionTimeout
 •typical value 3000
 •default of 20000 is too high for production use
 •also used for keep alive time-out
 •increase for slow clients
 •increase for layer 7 load balancer with connection
   pool and keep alive on
 •decrease for faster time-outs
Agenda
•The optimisation / tuning process

•Tomcat tuning options
 •logging
 •connectors
 •content cache
 •JVM

•Scaling Tomcat

•Hints and tips
Content cache tuning
•Dynamic content is not cached

•Static content is cached

•Configured using the <Context .../> element

•cacheMaxSize

 •10240

•cacheTTL

 •5000

•NIO/APR can use SEND_FILE
Agenda
•The optimisation / tuning process

•Tomcat tuning options
 •logging
 •connectors
 •content cache
 •JVM

•Scaling Tomcat

•Hints and tips
JVM tuning
•Two key areas

 •Memory
 •Garbage collection

•They are related

•Remember to follow the tuning process
JVM tuning: memory
• -Xms/-Xmx
 •Used to define size of Java heap
 •Aim to set as low as possible
 •Setting too high wastes memory and can cause long
   garbage collection pauses

•-XX:NewSize -XX:NewRatio
 •Set to 25% to 33% of total Java heap
 •Setting too high or too low leads to inefficient
   garbage collection
JVM tuning: ideal garbage collection
•Short lived objects never reach the Old Generation

•Short lived objects cleaned up by short minor garbage
 collections

•Long lived objects promoted to Old Generation

•Long lived objects cleaned up by (rare) full garbage
 collection
JVM tuning: garbage collection
•GC pauses the application

 •Regardless of GC algorithm

•Pause can range from milliseconds to seconds

•The pause will impact your response time

 •How much does this matter?

•-XX:MaxGCPauseMillis -XX:MaxGCMinorPauseMillis

 •Set GC pause time goals
 •More frequent GC, shorter pauses
JVM tuning
•There are many more options

•Useful reference
 http://blogs.sun.com/watt/resource/jvm-options-list.html
Agenda
•The optimisation / tuning process

•Tomcat tuning options
 •logging
 •connectors
 •content cache
 •JVM

•Scaling Tomcat

•Hints and tips
Scaling Tomcat
•Load balancing

 •Routing requests to multiple Tomcat instances

•Fail over

 •Sharing state between Tomcat instances   using clustering
Scaling Tomcat
•Simplest configuration

 •1 * httpd
 •2 * Tomcat instances
 •mod_proxy_http

•Considerations

 •state management
 •fail over
Scaling Tomcat
•Stateless

 •Requests routed to Tomcat instances based purely on
  load balancing algorithm
 •HTTP sessions will not work

•Adding HTTP session support

 •Tomcat instance maintains HTTP session state
 •'Sticky sessions'
 •All requests for a session routed to same Tomcat
  instance
Scaling Tomcat
•Fail over

 •Add session replication - clustering
 •Asynchronous by default so usually used with sticky
  sessions
 •Single line configuration for defaults
 •Will need additional configuration for production use
Agenda
•The optimisation / tuning process

•Tomcat tuning options
 •logging
 •connectors
 •content cache
 •JVM

•Scaling Tomcat

•Hints and tips
Hints and tips
•Load balancing / clustering

 •use a minimum of 3 Tomcat instances
 •use load balancing and clustering in your
  development environment

•Redeployment can expose memory leaks

 •include this in your testing

•Remember to follow the process
Questions?



Mark Thomas
mark.thomas@springsource.com

http://www.springsource.com/

More Related Content

What's hot

Apache Tomcat + Java EE = Apache TomEE
Apache Tomcat + Java EE = Apache TomEEApache Tomcat + Java EE = Apache TomEE
Apache Tomcat + Java EE = Apache TomEE
Jacek Laskowski
 
Tomcat New Evolution
Tomcat New EvolutionTomcat New Evolution
Tomcat New Evolution
Allan Huang
 

What's hot (20)

Auxiliary : Tomcat
Auxiliary : TomcatAuxiliary : Tomcat
Auxiliary : Tomcat
 
Web container and Apache Tomcat
Web container and Apache TomcatWeb container and Apache Tomcat
Web container and Apache Tomcat
 
Apache TomEE - Tomcat with a kick
Apache TomEE  - Tomcat with a kickApache TomEE  - Tomcat with a kick
Apache TomEE - Tomcat with a kick
 
Apache tomcat
Apache tomcatApache tomcat
Apache tomcat
 
Apache Performance Tuning: Scaling Out
Apache Performance Tuning: Scaling OutApache Performance Tuning: Scaling Out
Apache Performance Tuning: Scaling Out
 
Introduction to Apache Tomcat 7 Presentation
Introduction to Apache Tomcat 7 PresentationIntroduction to Apache Tomcat 7 Presentation
Introduction to Apache Tomcat 7 Presentation
 
Introduction of Tomcat
Introduction of TomcatIntroduction of Tomcat
Introduction of Tomcat
 
Tomcat
TomcatTomcat
Tomcat
 
Tomcat and apache httpd training
Tomcat and apache httpd trainingTomcat and apache httpd training
Tomcat and apache httpd training
 
Tomcat configuration
Tomcat configurationTomcat configuration
Tomcat configuration
 
25 Apache Performance Tips
25 Apache Performance Tips25 Apache Performance Tips
25 Apache Performance Tips
 
Apache Tomcat + Java EE = Apache TomEE
Apache Tomcat + Java EE = Apache TomEEApache Tomcat + Java EE = Apache TomEE
Apache Tomcat + Java EE = Apache TomEE
 
Fastest Servlets in the West
Fastest Servlets in the WestFastest Servlets in the West
Fastest Servlets in the West
 
Tomcat New Evolution
Tomcat New EvolutionTomcat New Evolution
Tomcat New Evolution
 
Apache Tomcat 7 by Filip Hanik
Apache Tomcat 7 by Filip HanikApache Tomcat 7 by Filip Hanik
Apache Tomcat 7 by Filip Hanik
 
Apache Performance Tuning: Scaling Up
Apache Performance Tuning: Scaling UpApache Performance Tuning: Scaling Up
Apache Performance Tuning: Scaling Up
 
(ATS4-PLAT01) Core Architecture Changes in AEP 9.0 and their Impact on Admini...
(ATS4-PLAT01) Core Architecture Changes in AEP 9.0 and their Impact on Admini...(ATS4-PLAT01) Core Architecture Changes in AEP 9.0 and their Impact on Admini...
(ATS4-PLAT01) Core Architecture Changes in AEP 9.0 and their Impact on Admini...
 
Java troubleshooting thread dump
Java troubleshooting thread dumpJava troubleshooting thread dump
Java troubleshooting thread dump
 
weblogic perfomence tuning
weblogic perfomence tuningweblogic perfomence tuning
weblogic perfomence tuning
 
Aem maintenance
Aem maintenanceAem maintenance
Aem maintenance
 

Viewers also liked

Tomcatx troubleshooting-production
Tomcatx troubleshooting-productionTomcatx troubleshooting-production
Tomcatx troubleshooting-production
Vladimir Khokhryakov
 
Advanced liferay architecture clustering and high availability
Advanced liferay architecture clustering and high availabilityAdvanced liferay architecture clustering and high availability
Advanced liferay architecture clustering and high availability
Bordin Kijsirijareonchai
 

Viewers also liked (14)

WebSphere App Server vs JBoss vs WebLogic vs Tomcat (InterConnect 2016)
WebSphere App Server vs JBoss vs WebLogic vs Tomcat (InterConnect 2016)WebSphere App Server vs JBoss vs WebLogic vs Tomcat (InterConnect 2016)
WebSphere App Server vs JBoss vs WebLogic vs Tomcat (InterConnect 2016)
 
Tomcatx troubleshooting-production
Tomcatx troubleshooting-productionTomcatx troubleshooting-production
Tomcatx troubleshooting-production
 
JavaCro'15 - Spring @Async - Dragan Juričić
JavaCro'15 - Spring @Async - Dragan JuričićJavaCro'15 - Spring @Async - Dragan Juričić
JavaCro'15 - Spring @Async - Dragan Juričić
 
JavaCro'15 - Slick database library - Ivan Senji
JavaCro'15 - Slick database library - Ivan SenjiJavaCro'15 - Slick database library - Ivan Senji
JavaCro'15 - Slick database library - Ivan Senji
 
Application specialist in Riga
Application specialist in RigaApplication specialist in Riga
Application specialist in Riga
 
IMS Learning Tools Interoperability (Smart ICT Korea)
IMS Learning Tools Interoperability (Smart ICT Korea)IMS Learning Tools Interoperability (Smart ICT Korea)
IMS Learning Tools Interoperability (Smart ICT Korea)
 
Thousands of Threads and Blocking I/O
Thousands of Threads and Blocking I/OThousands of Threads and Blocking I/O
Thousands of Threads and Blocking I/O
 
Lti
LtiLti
Lti
 
Web Performance Part 3 "Server-side tips"
Web Performance Part 3  "Server-side tips"Web Performance Part 3  "Server-side tips"
Web Performance Part 3 "Server-side tips"
 
Test Driven Development (TDD) & Continuous Integration (CI)
Test Driven Development (TDD) & Continuous Integration (CI)Test Driven Development (TDD) & Continuous Integration (CI)
Test Driven Development (TDD) & Continuous Integration (CI)
 
Introduction to TDD (Test Driven development) - Ahmed Shreef
Introduction to TDD (Test Driven development) - Ahmed ShreefIntroduction to TDD (Test Driven development) - Ahmed Shreef
Introduction to TDD (Test Driven development) - Ahmed Shreef
 
Apache TomEE, Java EE 6 Web Profile {and more} on Tomcat
Apache TomEE, Java EE 6 Web Profile {and more} on TomcatApache TomEE, Java EE 6 Web Profile {and more} on Tomcat
Apache TomEE, Java EE 6 Web Profile {and more} on Tomcat
 
Test Driven Development (TDD) with FlexUnit 4 - 360|Flex San Jose preso
Test Driven Development (TDD) with FlexUnit 4 - 360|Flex San Jose presoTest Driven Development (TDD) with FlexUnit 4 - 360|Flex San Jose preso
Test Driven Development (TDD) with FlexUnit 4 - 360|Flex San Jose preso
 
Advanced liferay architecture clustering and high availability
Advanced liferay architecture clustering and high availabilityAdvanced liferay architecture clustering and high availability
Advanced liferay architecture clustering and high availability
 

Similar to Tomcat Optimisation & Performance Tuning

Building & Testing Scalable Rails Applications
Building & Testing Scalable Rails ApplicationsBuilding & Testing Scalable Rails Applications
Building & Testing Scalable Rails Applications
evilmike
 
Performance and Scalability Tuning
Performance and Scalability TuningPerformance and Scalability Tuning
Performance and Scalability Tuning
Andres March
 

Similar to Tomcat Optimisation & Performance Tuning (20)

IBM Maximo Performance Tuning
IBM Maximo Performance TuningIBM Maximo Performance Tuning
IBM Maximo Performance Tuning
 
be the captain of your connections deployment
be the captain of your connections deploymentbe the captain of your connections deployment
be the captain of your connections deployment
 
JavaOne2016 - Microservices: Terabytes in Microseconds [CON4516]
JavaOne2016 - Microservices: Terabytes in Microseconds [CON4516]JavaOne2016 - Microservices: Terabytes in Microseconds [CON4516]
JavaOne2016 - Microservices: Terabytes in Microseconds [CON4516]
 
JavaOne2016 - Microservices: Terabytes in Microseconds [CON4516]
JavaOne2016 - Microservices: Terabytes in Microseconds [CON4516]JavaOne2016 - Microservices: Terabytes in Microseconds [CON4516]
JavaOne2016 - Microservices: Terabytes in Microseconds [CON4516]
 
Migrate from Oracle to Aurora PostgreSQL: Best Practices, Design Patterns, & ...
Migrate from Oracle to Aurora PostgreSQL: Best Practices, Design Patterns, & ...Migrate from Oracle to Aurora PostgreSQL: Best Practices, Design Patterns, & ...
Migrate from Oracle to Aurora PostgreSQL: Best Practices, Design Patterns, & ...
 
(ATS4-PLAT08) Server Pool Management
(ATS4-PLAT08) Server Pool Management(ATS4-PLAT08) Server Pool Management
(ATS4-PLAT08) Server Pool Management
 
Strata London 2019 Scaling Impala
Strata London 2019 Scaling ImpalaStrata London 2019 Scaling Impala
Strata London 2019 Scaling Impala
 
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
 
Building & Testing Scalable Rails Applications
Building & Testing Scalable Rails ApplicationsBuilding & Testing Scalable Rails Applications
Building & Testing Scalable Rails Applications
 
Caching your rails application
Caching your rails applicationCaching your rails application
Caching your rails application
 
Strata London 2019 Scaling Impala.pptx
Strata London 2019 Scaling Impala.pptxStrata London 2019 Scaling Impala.pptx
Strata London 2019 Scaling Impala.pptx
 
Configuring Apache Servers for Better Web Perormance
Configuring Apache Servers for Better Web PerormanceConfiguring Apache Servers for Better Web Perormance
Configuring Apache Servers for Better Web Perormance
 
Drupal performance
Drupal performanceDrupal performance
Drupal performance
 
Oracle WebLogic Diagnostics & Perfomance tuning
Oracle WebLogic Diagnostics & Perfomance tuningOracle WebLogic Diagnostics & Perfomance tuning
Oracle WebLogic Diagnostics & Perfomance tuning
 
AWS re:Invent 2016: JustGiving: Serverless Data Pipelines, Event-Driven ETL, ...
AWS re:Invent 2016: JustGiving: Serverless Data Pipelines, Event-Driven ETL, ...AWS re:Invent 2016: JustGiving: Serverless Data Pipelines, Event-Driven ETL, ...
AWS re:Invent 2016: JustGiving: Serverless Data Pipelines, Event-Driven ETL, ...
 
Coherence sig-nfr-web-tier-scaling-using-coherence-web
Coherence sig-nfr-web-tier-scaling-using-coherence-webCoherence sig-nfr-web-tier-scaling-using-coherence-web
Coherence sig-nfr-web-tier-scaling-using-coherence-web
 
Best And Worst Practices Deploying IBM Connections
Best And Worst Practices Deploying IBM ConnectionsBest And Worst Practices Deploying IBM Connections
Best And Worst Practices Deploying IBM Connections
 
WebLogic Stability; Detect and Analyse Stuck Threads
WebLogic Stability; Detect and Analyse Stuck ThreadsWebLogic Stability; Detect and Analyse Stuck Threads
WebLogic Stability; Detect and Analyse Stuck Threads
 
Performance and Scalability Tuning
Performance and Scalability TuningPerformance and Scalability Tuning
Performance and Scalability Tuning
 
Introduction to memcached
Introduction to memcachedIntroduction to memcached
Introduction to memcached
 

More from lovingprince58

More from lovingprince58 (12)

No sql数据库笔谈
No sql数据库笔谈No sql数据库笔谈
No sql数据库笔谈
 
Design Patterns For Distributed NO-reational databases
Design Patterns For Distributed NO-reational databasesDesign Patterns For Distributed NO-reational databases
Design Patterns For Distributed NO-reational databases
 
分布式Key-value漫谈
分布式Key-value漫谈分布式Key-value漫谈
分布式Key-value漫谈
 
Linux性能监控cpu内存io网络
Linux性能监控cpu内存io网络Linux性能监控cpu内存io网络
Linux性能监控cpu内存io网络
 
[Python.cookbook(第2版)中文版].(美)马特利,(美)阿舍尔.扫描版
[Python.cookbook(第2版)中文版].(美)马特利,(美)阿舍尔.扫描版[Python.cookbook(第2版)中文版].(美)马特利,(美)阿舍尔.扫描版
[Python.cookbook(第2版)中文版].(美)马特利,(美)阿舍尔.扫描版
 
Taobao 海量图片存储与CDN系统02
Taobao 海量图片存储与CDN系统02Taobao 海量图片存储与CDN系统02
Taobao 海量图片存储与CDN系统02
 
淘宝软件基础设施构建实践
淘宝软件基础设施构建实践淘宝软件基础设施构建实践
淘宝软件基础设施构建实践
 
Google big table 中文版
Google big table 中文版Google big table 中文版
Google big table 中文版
 
[Python参考手册(第4版)].(美)比兹利.扫描版
[Python参考手册(第4版)].(美)比兹利.扫描版[Python参考手册(第4版)].(美)比兹利.扫描版
[Python参考手册(第4版)].(美)比兹利.扫描版
 
Jvm内存问题最佳实践
Jvm内存问题最佳实践Jvm内存问题最佳实践
Jvm内存问题最佳实践
 
Java内存管理
Java内存管理Java内存管理
Java内存管理
 
Jetty服务器架构及调优.v2 2011-5
Jetty服务器架构及调优.v2 2011-5Jetty服务器架构及调优.v2 2011-5
Jetty服务器架构及调优.v2 2011-5
 

Recently uploaded

the Husband rolesBrown Aesthetic Cute Group Project Presentation
the Husband rolesBrown Aesthetic Cute Group Project Presentationthe Husband rolesBrown Aesthetic Cute Group Project Presentation
the Husband rolesBrown Aesthetic Cute Group Project Presentation
brynpueblos04
 
KLINIK BATA Jual obat penggugur kandungan 087776558899 ABORSI JANIN KEHAMILAN...
KLINIK BATA Jual obat penggugur kandungan 087776558899 ABORSI JANIN KEHAMILAN...KLINIK BATA Jual obat penggugur kandungan 087776558899 ABORSI JANIN KEHAMILAN...
KLINIK BATA Jual obat penggugur kandungan 087776558899 ABORSI JANIN KEHAMILAN...
Cara Menggugurkan Kandungan 087776558899
 
call Now 9811711561 Cash Payment乂 Call Girls in Dwarka Mor
call Now 9811711561 Cash Payment乂 Call Girls in Dwarka Morcall Now 9811711561 Cash Payment乂 Call Girls in Dwarka Mor
call Now 9811711561 Cash Payment乂 Call Girls in Dwarka Mor
vikas rana
 

Recently uploaded (14)

$ Love Spells^ 💎 (310) 882-6330 in West Virginia, WV | Psychic Reading Best B...
$ Love Spells^ 💎 (310) 882-6330 in West Virginia, WV | Psychic Reading Best B...$ Love Spells^ 💎 (310) 882-6330 in West Virginia, WV | Psychic Reading Best B...
$ Love Spells^ 💎 (310) 882-6330 in West Virginia, WV | Psychic Reading Best B...
 
Pokemon Go... Unraveling the Conspiracy Theory
Pokemon Go... Unraveling the Conspiracy TheoryPokemon Go... Unraveling the Conspiracy Theory
Pokemon Go... Unraveling the Conspiracy Theory
 
the Husband rolesBrown Aesthetic Cute Group Project Presentation
the Husband rolesBrown Aesthetic Cute Group Project Presentationthe Husband rolesBrown Aesthetic Cute Group Project Presentation
the Husband rolesBrown Aesthetic Cute Group Project Presentation
 
KLINIK BATA Jual obat penggugur kandungan 087776558899 ABORSI JANIN KEHAMILAN...
KLINIK BATA Jual obat penggugur kandungan 087776558899 ABORSI JANIN KEHAMILAN...KLINIK BATA Jual obat penggugur kandungan 087776558899 ABORSI JANIN KEHAMILAN...
KLINIK BATA Jual obat penggugur kandungan 087776558899 ABORSI JANIN KEHAMILAN...
 
(Anamika) VIP Call Girls Navi Mumbai Call Now 8250077686 Navi Mumbai Escorts ...
(Anamika) VIP Call Girls Navi Mumbai Call Now 8250077686 Navi Mumbai Escorts ...(Anamika) VIP Call Girls Navi Mumbai Call Now 8250077686 Navi Mumbai Escorts ...
(Anamika) VIP Call Girls Navi Mumbai Call Now 8250077686 Navi Mumbai Escorts ...
 
2k Shots ≽ 9205541914 ≼ Call Girls In Palam (Delhi)
2k Shots ≽ 9205541914 ≼ Call Girls In Palam (Delhi)2k Shots ≽ 9205541914 ≼ Call Girls In Palam (Delhi)
2k Shots ≽ 9205541914 ≼ Call Girls In Palam (Delhi)
 
2k Shots ≽ 9205541914 ≼ Call Girls In Jasola (Delhi)
2k Shots ≽ 9205541914 ≼ Call Girls In Jasola (Delhi)2k Shots ≽ 9205541914 ≼ Call Girls In Jasola (Delhi)
2k Shots ≽ 9205541914 ≼ Call Girls In Jasola (Delhi)
 
Top Rated Pune Call Girls Tingre Nagar ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Tingre Nagar ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Tingre Nagar ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Tingre Nagar ⟟ 6297143586 ⟟ Call Me For Genuine Se...
 
call Now 9811711561 Cash Payment乂 Call Girls in Dwarka Mor
call Now 9811711561 Cash Payment乂 Call Girls in Dwarka Morcall Now 9811711561 Cash Payment乂 Call Girls in Dwarka Mor
call Now 9811711561 Cash Payment乂 Call Girls in Dwarka Mor
 
LC_YouSaidYes_NewBelieverBookletDone.pdf
LC_YouSaidYes_NewBelieverBookletDone.pdfLC_YouSaidYes_NewBelieverBookletDone.pdf
LC_YouSaidYes_NewBelieverBookletDone.pdf
 
2k Shots ≽ 9205541914 ≼ Call Girls In Dashrath Puri (Delhi)
2k Shots ≽ 9205541914 ≼ Call Girls In Dashrath Puri (Delhi)2k Shots ≽ 9205541914 ≼ Call Girls In Dashrath Puri (Delhi)
2k Shots ≽ 9205541914 ≼ Call Girls In Dashrath Puri (Delhi)
 
2k Shots ≽ 9205541914 ≼ Call Girls In Mukherjee Nagar (Delhi)
2k Shots ≽ 9205541914 ≼ Call Girls In Mukherjee Nagar (Delhi)2k Shots ≽ 9205541914 ≼ Call Girls In Mukherjee Nagar (Delhi)
2k Shots ≽ 9205541914 ≼ Call Girls In Mukherjee Nagar (Delhi)
 
WOMEN EMPOWERMENT women empowerment.pptx
WOMEN EMPOWERMENT women empowerment.pptxWOMEN EMPOWERMENT women empowerment.pptx
WOMEN EMPOWERMENT women empowerment.pptx
 
(Aarini) Russian Call Girls Surat Call Now 8250077686 Surat Escorts 24x7
(Aarini) Russian Call Girls Surat Call Now 8250077686 Surat Escorts 24x7(Aarini) Russian Call Girls Surat Call Now 8250077686 Surat Escorts 24x7
(Aarini) Russian Call Girls Surat Call Now 8250077686 Surat Escorts 24x7
 

Tomcat Optimisation & Performance Tuning

  • 1. Mark Thomas Tomcat Optimisation Senior Consultant & Performance Tuning SpringSource
  • 2. Who am I? •Apache Tomcat committer for over 5 years •Resolved 1,500+ Tomcat bugs •Apache Tomcat PMC member •Member of the Apache Software Foundation •Member of the ASF security committee •Created the Tomcat security pages •Senior Software Engineer and Consultant at SpringSource
  • 3. Agenda •The optimisation / tuning process •Tomcat tuning options •logging •connectors •content cache •JVM •Scaling Tomcat •Hints and tips
  • 4. Agenda •The optimisation / tuning process •Tomcat tuning options •logging •connectors •content cache •JVM •Scaling Tomcat •Hints and tips
  • 5. The process •Understand the system architecture •Stabilise the system •Set the performance target(s) •Measure current performance •Identify the current bottleneck •Fix the root cause of the bottleneck •Repeat until you meet the target
  • 6. Common errors •Optimising code that doesn't need it •Insufficient testing •realistic data volumes •realistic user load •Lack of clear performance targets •Guessing where the bottleneck is •Fixing the symptom rather than the cause
  • 7. Agenda •The optimisation / tuning process •Tomcat tuning options •logging •connectors •content cache •JVM •Scaling Tomcat •Hints and tips
  • 8. Tomcat tuning •Applications typically account for >80% of request processing time •Remember the tuning process •focus your efforts on the bottlenecks
  • 9. Agenda •The optimisation / tuning process •Tomcat tuning options •logging •connectors •content cache •JVM •Scaling Tomcat •Hints and tips
  • 10. Production logging •Default configuration is generic •Some settings not ideal for production •catch-all logger logs to file and stdout •no overflow protection •logging is synchronised
  • 11. Production logging •Remove duplicate logging (logging.properties) .handlers = 1catalina.org.apache.juli.FileHandler, java.util.logging.ConsoleHandler •becomes .handlers = 1catalina.org.apache.juli.FileHandler •to add rotation 1catalina.java.util.logging.FileHandler.pattern = ${catalina.base}/logs/catalina.%g.log 1catalina.java.util.logging.FileHandler.limit = 20000000 1catalina.java.util.logging.FileHandler.count = 5
  • 12. Production logging •Synchronous logging: •can become a bottleneck •don't want disk IO to become the limiting factor •Asynchronous logging: •log queue uses memory •limit queue size to avoid out of memory errors •fall back to synchronised logging and/or drop some log messages
  • 13. Agenda •The optimisation / tuning process •Tomcat tuning options •logging •connectors •content cache •JVM •Scaling Tomcat •Hints and tips
  • 14. Connector tuning •Need to understand •your application usage patterns •TCP connections •HTTP transactions •HTTP Keep-Alive •SSL
  • 15. Connector tuning •Additional considerations for load balancing •Layer 4 or Layer 7 •Connection pools
  • 16. Which connector? •Java Blocking IO •Oldest – most stable •JSSE based SSL •Native (APR) •Non-blocking •Uses OpenSSL •Java Non-blocking IO •JSSE based SSL
  • 17. Which connector? Requirement Preference order Stability BIO APR NIO SSL APR NIO BIO Low concurrency BIO APR NIO High concurrency BIO APR NIO No Keep-Alive High concurrency APR NIO BIO Keep-Alive
  • 18. Which connector? •Why would you use the NIO connector? •The Native (APR) connector is unstable on Solaris •NIO is a pure Java solution •It is easy to switch between NIO and BIO with SSL
  • 19. Connector tuning •maxThreads •typical values 200 – 800 •maximum number of concurrent requests •for BIO, maximum number of open/active connections •400 is a good starting value •heavy CPU usage → decrease •light CPU usage → increase
  • 20. Connector tuning •maxKeepAliveRequests •typical values 1, 100 •maximum number of HTTP requests per TCP connection •set to 1 to disable keep alive •disable for BIO with very high concurrency, layer 4 load balancer, no SSL •enable for SSL, APR/NIO, layer 7 load balancer •Note BIO connector automatically disables keep alive when concurrent connections are high
  • 21. Connector tuning •connectionTimeout •typical value 3000 •default of 20000 is too high for production use •also used for keep alive time-out •increase for slow clients •increase for layer 7 load balancer with connection pool and keep alive on •decrease for faster time-outs
  • 22. Agenda •The optimisation / tuning process •Tomcat tuning options •logging •connectors •content cache •JVM •Scaling Tomcat •Hints and tips
  • 23. Content cache tuning •Dynamic content is not cached •Static content is cached •Configured using the <Context .../> element •cacheMaxSize •10240 •cacheTTL •5000 •NIO/APR can use SEND_FILE
  • 24. Agenda •The optimisation / tuning process •Tomcat tuning options •logging •connectors •content cache •JVM •Scaling Tomcat •Hints and tips
  • 25. JVM tuning •Two key areas •Memory •Garbage collection •They are related •Remember to follow the tuning process
  • 26. JVM tuning: memory • -Xms/-Xmx •Used to define size of Java heap •Aim to set as low as possible •Setting too high wastes memory and can cause long garbage collection pauses •-XX:NewSize -XX:NewRatio •Set to 25% to 33% of total Java heap •Setting too high or too low leads to inefficient garbage collection
  • 27. JVM tuning: ideal garbage collection •Short lived objects never reach the Old Generation •Short lived objects cleaned up by short minor garbage collections •Long lived objects promoted to Old Generation •Long lived objects cleaned up by (rare) full garbage collection
  • 28. JVM tuning: garbage collection •GC pauses the application •Regardless of GC algorithm •Pause can range from milliseconds to seconds •The pause will impact your response time •How much does this matter? •-XX:MaxGCPauseMillis -XX:MaxGCMinorPauseMillis •Set GC pause time goals •More frequent GC, shorter pauses
  • 29. JVM tuning •There are many more options •Useful reference http://blogs.sun.com/watt/resource/jvm-options-list.html
  • 30. Agenda •The optimisation / tuning process •Tomcat tuning options •logging •connectors •content cache •JVM •Scaling Tomcat •Hints and tips
  • 31. Scaling Tomcat •Load balancing •Routing requests to multiple Tomcat instances •Fail over •Sharing state between Tomcat instances using clustering
  • 32. Scaling Tomcat •Simplest configuration •1 * httpd •2 * Tomcat instances •mod_proxy_http •Considerations •state management •fail over
  • 33. Scaling Tomcat •Stateless •Requests routed to Tomcat instances based purely on load balancing algorithm •HTTP sessions will not work •Adding HTTP session support •Tomcat instance maintains HTTP session state •'Sticky sessions' •All requests for a session routed to same Tomcat instance
  • 34. Scaling Tomcat •Fail over •Add session replication - clustering •Asynchronous by default so usually used with sticky sessions •Single line configuration for defaults •Will need additional configuration for production use
  • 35. Agenda •The optimisation / tuning process •Tomcat tuning options •logging •connectors •content cache •JVM •Scaling Tomcat •Hints and tips
  • 36. Hints and tips •Load balancing / clustering •use a minimum of 3 Tomcat instances •use load balancing and clustering in your development environment •Redeployment can expose memory leaks •include this in your testing •Remember to follow the process