05 tomcat mark thomas
TRANSCRIPT
-
8/7/2019 05 Tomcat Mark Thomas
1/37
Tomcat Optimisation& Performance Tuning
Mark Thomas
Senior ConsultantSpringSource
-
8/7/2019 05 Tomcat Mark Thomas
2/37
Who am I?
Apache Tomcat committer for over 5 years
,
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
-
8/7/2019 05 Tomcat Mark Thomas
3/37
Agenda
The optimisation / tuning process
logging
connectorscontent cache
Scaling Tomcat
Hints and tips
-
8/7/2019 05 Tomcat Mark Thomas
4/37
Agenda
The optimisation / tuning process
logging
connectors
content cache
Scaling Tomcat
Hints and tips
-
8/7/2019 05 Tomcat Mark Thomas
5/37
The process
Understand the system architecture
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
-
8/7/2019 05 Tomcat Mark Thomas
6/37
Common errors
Optimising code that doesn't need it
realistic data volumes
realistic user load
Lack of clear performance targets
uess ng w ere e o enec s
Fixing the symptom rather than the cause
-
8/7/2019 05 Tomcat Mark Thomas
7/37
Agenda
The optimisation / tuning process
logging
connectors
content cache
Scaling Tomcat
Hints and tips
-
8/7/2019 05 Tomcat Mark Thomas
8/37
Tomcat tuning
Applications typically account for >80% of request
processing time
Remember the tuning process
focus your efforts on the bottlenecks
-
8/7/2019 05 Tomcat Mark Thomas
9/37
Agenda
The optimisation / tuning process
logging
connectors
content cache
Scaling Tomcat
Hints and tips
-
8/7/2019 05 Tomcat Mark Thomas
10/37
Production logging
Default configuration is generic
catch-all logger logs to file and stdout
no overflow protection
logging is synchronised
-
8/7/2019 05 Tomcat Mark Thomas
11/37
Production logging
Remove duplicate logging (logging.properties)
.handlers = 1catalina.or .a ache. uli.FileHandler
becomes
to add rotation
java.util.logging.ConsoleHandler
.handlers = 1catalina.org.apache.juli.FileHandler
. . . . .
${catalina.base}/logs/catalina.%g.log1catalina.java.util.logging.FileHandler.limit = 200000001catalina.java.util.logging.FileHandler.count = 5
-
8/7/2019 05 Tomcat Mark Thomas
12/37
Production logging
Synchronous logging:
don't want disk IO to become the limiting factor
Asynchronous logging:
log queue uses memory
fall back to synchronised logging and/or drop some log messages
-
8/7/2019 05 Tomcat Mark Thomas
13/37
Agenda
The optimisation / tuning process
logging
connectors
content cache
Scaling Tomcat
Hints and tips
-
8/7/2019 05 Tomcat Mark Thomas
14/37
Connector tuning
Need to understand
TCP connections
HTTP transactionsHTTP Keep-Alive
-
8/7/2019 05 Tomcat Mark Thomas
15/37
Connector tuning
Additional considerations for load balancing
Connection pools
-
8/7/2019 05 Tomcat Mark Thomas
16/37
Which connector?
Java Blocking IO
JSSE based SSL
Native (APR)
Non-blocking
Java Non-blocking IO
JSSE based SSL
-
8/7/2019 05 Tomcat Mark Thomas
17/37
Which connector?
Requirement Preference order
Stability BIO APR NIO
SSL APR NIO BIO
Low concurrency BIO APR NIO
High concurrency-
BIO APR NIO
High concurrencyKeep-Alive
APR NIO BIO
-
8/7/2019 05 Tomcat Mark Thomas
18/37
Which connector?
Why would you use the NIO connector?
NIO is a pure Java solution
It is easy to switch between NIO and BIO with SSL
-
8/7/2019 05 Tomcat Mark Thomas
19/37
Connector tuning
maxThreads
maximum number of concurrent requests
for BIO, maximum number of open/activeconnections
400 is a good starting value
heavy CPU usage decreaselight CPU usage increase
-
8/7/2019 05 Tomcat Mark Thomas
20/37
Connector tuning
maxKeepAliveRequests
,
maximum number of HTTP requests per TCPconnection
set to 1 to disable keep alivedisable for BIO with very high concurrency, layer 4
,
enable for SSL, APR/NIO, layer 7 load balancer
Note BIO connector automatically disables keep alivewhen concurrent connections are high
-
8/7/2019 05 Tomcat Mark Thomas
21/37
-
8/7/2019 05 Tomcat Mark Thomas
22/37
Agenda
The optimisation / tuning process
logging
connectors
content cache
Scaling Tomcat
Hints and tips
-
8/7/2019 05 Tomcat Mark Thomas
23/37
Content cache tuning
Dynamic content is not cached
Configured using the element
cacheMaxSize10240
cacheTTL
5000
NIO/APR can use SEND_FILE
-
8/7/2019 05 Tomcat Mark Thomas
24/37
Agenda
The optimisation / tuning process
logging
connectors
content cache
Scaling Tomcat
Hints and tips
-
8/7/2019 05 Tomcat Mark Thomas
25/37
JVM tuning
Two key areas
Garbage collection
They are related
Remember to follow the tuning process
-
8/7/2019 05 Tomcat Mark Thomas
26/37
JVM tuning: memory
-Xms/-Xmx
Aim to set as low as possible
Setting too high wastes memory and can cause longgarbage collection pauses
-XX:NewSize -XX:NewRatio
Set to 25% to 33% of total Java heapSetting too high or too low leads to inefficientgarbage collection
-
8/7/2019 05 Tomcat Mark Thomas
27/37
JVM tuning: ideal garbage collection
Short lived objects never reach the Old Generation
collections
Long lived objects promoted to Old Generation
Long lived objects cleaned up by (rare) full garbagecollection
-
8/7/2019 05 Tomcat Mark Thomas
28/37
JVM tuning: garbage collection
GC pauses the application
Pause can range from milliseconds to seconds
The pause will impact your response time
How much does this matter?
- : ax ause s - : ax nor ause s
Set GC pause time goals
More frequent GC, shorter pauses
-
8/7/2019 05 Tomcat Mark Thomas
29/37
JVM tuning
There are many more options
http://blogs.sun.com/watt/resource/jvm-options-list.html
-
8/7/2019 05 Tomcat Mark Thomas
30/37
Agenda
The optimisation / tuning process
logging
connectors
content cache
Scaling Tomcat
Hints and tips
-
8/7/2019 05 Tomcat Mark Thomas
31/37
Scaling Tomcat
Load balancing
Fail over
Sharing state between Tomcat instances using clustering
-
8/7/2019 05 Tomcat Mark Thomas
32/37
Scaling Tomcat
Simplest configuration
2 * Tomcat instances
mod_proxy_http
Considerations
fail over
-
8/7/2019 05 Tomcat Mark Thomas
33/37
Scaling Tomcat
Stateless
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 Tomcatinstance
-
8/7/2019 05 Tomcat Mark Thomas
34/37
Scaling Tomcat
Fail over
-
Asynchronous by default so usually used with stickysessions
Single line configuration for defaults
Will need additional configuration for production use
-
8/7/2019 05 Tomcat Mark Thomas
35/37
Agenda
The optimisation / tuning process
logging
connectors
content cache
Scaling Tomcat
Hints and tips
-
8/7/2019 05 Tomcat Mark Thomas
36/37
Hints and tips
Load balancing / clustering
use load balancing and clustering in yourdevelopment environment
Redeployment can expose memory leaks
include this in your testing
Remember to follow the process
-
8/7/2019 05 Tomcat Mark Thomas
37/37
Questions?
Mark [email protected]
. .