Tomcat solution
1. Improve JVM stack memory JVM heap memory
Tomcat sometimes "memory overflow", this kind of problem appears in the actual production environment, the reason for this kind of problem is that tomcat uses less memory for the process. This problem can be solved by configuring the tomcat configuration file (tomcat/bin/catalina.bat under window or tomcat/bin/catalina.sh under Linux). This solution is achieved by increasing the stack memory of the JVM. This solution allows tomcat to pay more attention to processing web requests and require them to be completed as soon as possible.
JAVA_OPTS="-Djava.awt.headless=true -Dfile.encoding=UTF-8
-server -Xms1024m -Xmx1024m
-XX:NewSize=512m -XX:MaxNewSize=512m -XX:PermSize=512m
-XX:MaxPermSize=512m -XX:+DisableExplicitGC"
2. Solve JRE memory leak
Another major cause of poor performance is memory leaks. You can use the latest tomcat server for better performance and scalability. The new tomcat includes a listener to handle memory leaks in JRE and PermGen. The listener used is
〈Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
3. Thread pool settings
The thread pool specifies the number of Web request loads, which can be set by adjusting the connector attribute "maxThreads". maxThreads is the maximum number of concurrent requests processed by the server. If the value of maxThreads is set too low, there will not be enough threads to process all requests, and the requests will enter the waiting state, and will be processed only when one processing thread is released; if the setting is too large, Tomcat startup will cost more More time. So it depends on us setting a correct value for maxThreads.
〈Connector port="8080" address="localhost"
maxThreads="250" maxHttpHeaderSize="8192"
emptySessionPath="true" protocol="HTTP/1.1"
enableLookups="false" redirectPort="8181" acceptCount="100"
connectionTimeout="20000" disableUploadTimeout="true" />
4. compression
HTTP compression can greatly improve the speed of browsing websites. Its principle is that after the client requests the server's corresponding resources, the resource files are compressed from the server and output to the client, and the client's browser is responsible for decompression and browsing.
Versions after tomcat5.0 support compression of the output content, using the gzip compression format.
〈Connector port="80" protocol="HTTP/1.1" connectionTimeout="20000"
redirectPort="8443" executor="tomcatThreadPool" URIEncoding="utf-8"
compression="on" compressionMinSize="50" noCompressionUserAgents="gozilla, traviata"
compressableMimeType="text/html,text/xml,text/java,text/css,text/plain"
/>
As can be seen from the properties of the above node, to use the gzip compression function, you need to add the following properties to the Connector node
compression="on" Turn on the compression function
compressionMinSize="50" Enables the compressed output content size, the unit byte defaults to 2048
noCompressionUserAgents="gozilla, traviata" For the following browsers, do not enable compression
compressableMimeType="text/html,text/xml,text/java,text/css,text/plain" what resource types need to be compressed
5. Database performance tuning
Tomcat performance will degrade while waiting for database queries to be executed. Improve performance:
Using a relational database that may contain "named queries", Tomcat will load named queries by default at startup, which may improve performance.
Ensure that all database connections are closed properly. Configure the database connection pool settings correctly. The maximum idle number (maxIdle), the maximum number of connections (maxActive), and the maximum connection waiting time (maxWait) attribute values of the Resource element.
6. Tomcat native library
Tomcat's native library is based on the Apache Portable Runtime (Apache Portable Runtime for short APR), which provides programmers with super scalability and performance, and helps integrate native server technology to show the best performance in product operations.
1. Improve JVM stack memory JVM heap memory
Tomcat sometimes "memory overflows", this kind of problem appears in the actual production environment, the reason for this kind of problem is that tomcat uses less memory for the process. This problem can be solved by configuring the tomcat configuration file (tomcat/bin/catalina.bat under window or tomcat/bin/catalina.sh under Linux). This solution is achieved by increasing the stack memory of the JVM. This solution allows tomcat to pay more attention to processing web requests and require them to be completed as soon as possible.
JAVA_OPTS="-Djava.awt.headless=true -Dfile.encoding=UTF-8
-server -Xms1024m -Xmx1024m
-XX:NewSize=512m -XX:MaxNewSize=512m -XX:PermSize=512m
-XX:MaxPermSize=512m -XX:+DisableExplicitGC"
2. Solve JRE memory leak
Another major cause of poor performance is memory leaks. You can use the latest tomcat server for better performance and scalability. The new tomcat includes a listener to handle memory leaks in JRE and PermGen. The listener used is
〈Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
3. Thread pool settings
The thread pool specifies the number of Web request loads, which can be set by adjusting the connector attribute "maxThreads". maxThreads is the maximum number of concurrent requests processed by the server. If the value of maxThreads is set too low, there will not be enough threads to process all requests, and the requests will enter the waiting state, and will be processed only when one processing thread is released; if the setting is too large, Tomcat startup will cost more More time. So it depends on us setting a correct value for maxThreads.
〈Connector port="8080" address="localhost"
maxThreads="250" maxHttpHeaderSize="8192"
emptySessionPath="true" protocol="HTTP/1.1"
enableLookups="false" redirectPort="8181" acceptCount="100"
connectionTimeout="20000" disableUploadTimeout="true" />
4. compression
HTTP compression can greatly improve the speed of browsing websites. Its principle is that after the client requests the server's corresponding resources, the resource files are compressed from the server and output to the client, and the client's browser is responsible for decompression and browsing.
Versions after tomcat5.0 support compression of the output content, using the gzip compression format.
〈Connector port="80" protocol="HTTP/1.1" connectionTimeout="20000"
redirectPort="8443" executor="tomcatThreadPool" URIEncoding="utf-8"
compression="on" compressionMinSize="50" noCompressionUserAgents="gozilla, traviata"
compressableMimeType="text/html,text/xml,text/java,text/css,text/plain"
/>
As can be seen from the properties of the above node, to use the gzip compression function, you need to add the following properties to the Connector node
compression="on" Turn on the compression function
compressionMinSize="50" Enables the compressed output content size, the unit byte defaults to 2048
noCompressionUserAgents="gozilla, traviata" For the following browsers, do not enable compression
compressableMimeType="text/html,text/xml,text/java,text/css,text/plain" what resource types need to be compressed
5. Database performance tuning
Tomcat performance will degrade while waiting for database queries to be executed. Improve performance:
Using a relational database that may contain "named queries", Tomcat will load named queries by default at startup, which may improve performance.
Ensure that all database connections are closed properly. Configure the database connection pool settings correctly. The maximum idle number (maxIdle), the maximum number of connections (maxActive), and the maximum connection waiting time (maxWait) attribute values of the Resource element.
6. Tomcat native library
Tomcat's native library is based on the Apache Portable Runtime (Apache Portable Runtime for short APR), which provides programmers with super scalability and performance, and helps integrate native server technology to show the best performance in product operations.
上一篇:Apache solution