6th Step –tomcat Native Library Tomcat's native library is based on the Apache Portable runtime (Apache portable runtime abbreviation APR), providing programmers with superior scalability and performance, helping to fuse native server technology to deliver optimal performance in product operations. For friends who want to know the installation instructions, refer to Tomcat Native library– (APR) installation. 7th Step – Other options These options are:
- Open the browser's cache so that reading static content stored in the WebApps folder will be faster, greatly boosting overall performance.
- The tomcat server should restart automatically whenever it is powered on.
- In general, HTTPS requests are slower than HTTP requests. If you want better security, even slower we still have to choose HTTPS.
That's all. In this article, I have taught you some ways to improve the performance of Tomcat servers. If you think this article is useful, or if you have a different view on how to improve the performance of your Tomcat server, please don't forget to leave a valuable comment. I wish you a happy programming today! Optimizing Tomcat ParametersHere, as an example of TOMCAT7 parameter configuration, the Conf/server.xml file needs to be modified, mainly to optimize the connection configuration and close the client DNS query.
- <Connector port="8080"
- protocol="Org.apache.coyote.http11.Http11NioProtocol"
- connectiontimeout="20000"
- redirectport="8443"
- maxthreads="
- minsparethreads="
- acceptcount="
- disableuploadtimeout="true"
- enablelookups="false"
- uriencoding="UTF-8" />
5. Use Apr LibraryThe bio model used by Tomcat by default has a significant degradation in performance under hundreds of concurrency. Tomcat comes with a model of NIO, and you can also invoke the APR library to achieve OS level control. The NIO model is built-in and is easy to invoke, requiring only the protocol in the above configuration file to be modified to Org.apache.coyote.http11.Http11NioProtocol, and the restart will take effect. The above configuration I have changed, the default is http/1.1. Apr requires the installation of third-party libraries, which can significantly improve performance at high concurrency. Specific installation methods can refer to http://www.cnblogs.com/huangjingzhou/articles/2097241.html. Reboot will take effect when the installation is complete. If you use the default protocal is APR, but it is better to change the protocol to Org.apache.coyote.http11.Http11AprProtocol, will be more explicit . In the official Find a table detailing the differences in these three ways:
- Java Blocking Connector java Nio Blocking Connector apr/native Connector
- BIO NIO APR
- Classname Ajpprotocol Ajpnioprotocol Ajpaprprotocol
- Tomcat Version 3.x onwards 7.x onwards 5.5.x onwards
- Support Polling NO Yes Yes
- Polling Size N/a maxconnections maxconnections
- Read Request Headers Blocking Sim Blocking Blocking
- Read Request Body Blocking Sim Blocking Blocking
- Write Response Blocking Sim Blocking Blocking
- Wait for next Request Blocking Non Blocking Non Blocking
- Max Connections maxconnections maxconnections maxconnections
6. Optimize your networkJoel has also made it clear that optimizing NIC drivers can improve performance, which is especially important when working in a clustered environment. Since we have a Linux server, optimizing kernel parameters is also a very important task. Give a reference to the optimization parameters:
- 1. Modify the/etc/sysctl.cnf file and append the following at the end:
- Net.core.netdev_max_backlog = 32768
- Net.core.somaxconn = 32768
- Net.core.wmem_default = 8388608
- Net.core.rmem_default = 8388608
- Net.core.rmem_max = 16777216
- Net.core.wmem_max = 16777216
- Net.ipv4.ip_local_port_range = 1024x768 65000
- Net.ipv4.route.gc_timeout =
- Net.ipv4.tcp_fin_timeout =
- Net.ipv4.tcp_keepalive_time =
- Net.ipv4.tcp_timestamps = 0
- Net.ipv4.tcp_synack_retries = 2
- Net.ipv4.tcp_syn_retries = 2
- Net.ipv4.tcp_tw_recycle = 1
- Net.ipv4.tcp_tw_reuse = 1
- Net.ipv4.tcp_mem = 94500000 915000000 927000000
- Net.ipv4.tcp_max_orphans = 3276800
- Net.ipv4.tcp_max_syn_backlog = 65536
- 2. Save exit, execute sysctl-p effective
7. Let the test speakThe most taboo is to optimize the system is not testing, sometimes inappropriate optimization will make performance lower. All of the above optimization methods have to be tested locally after the performance test and then constantly adjust the parameters, so that the ultimate optimization results can be achieved. Added test results for bio, Nio, Apr modes: For these modes, I used the AB command to simulate 1000 concurrent test 10000 words, the test results are quite unexpected, in order to confirm the results, I have repeatedly tested more than 10 times, and on two servers have been tested again. The results showed that the difference between bio and NiO was very weak, no wonder it was bio by default. However, with APR, the speed of connection establishment will be 50%~100%. Calling the operating system layer directly is very fast, it is highly recommended Apr way! |