[Tomcat] Chapter 10: Talking about several schemes of Tomcat tuning

Four indicators to measure performance: response time, throughput, CPU load, memory usage , these indicators are not separate, but together, they are a four-sided relationship, and each indicator is based on other indicators. Up. They influence each other and are interconnected.

The ideal is full, the reality is skinny, and the optimization is focused on accumulating less into more. A little bit of optimization in each aspect will have an impact on the overall situation. Performance optimization is actually such a topic.

1. Tools used in Tomcat performance optimization

The jmeter tool is written in pure java. It is also a distributed tool that can be used for single-machine testing or distributed multi-machine stress testing. How to do distributed stress testing can be found on Baidu.

2. Server.xml optimization in Tomcat

  • NIO

    Xiao Ming applied for a membership card in a big barber shop near his home. The business was so good that he had to wait in line every time he went to cut his hair. The process of cutting hair itself was a long process and a long connection. If using the BIO method, a barber can only serve one person at the same time

    If NIO is used, the process can be disassembled, and the haircut can be divided into shampoo, haircut, and blowing. Nowadays, barber shops employ many young men. No matter how many people there are, the process of shampooing can not be blocked. After washing, you may need to wait for the hairdresser to cut the hair. Blow dry.

    The process of Xiaoming's hair cutting above is a typical NIO. The biggest squeeze of the barber, the hairdresser's time segments are used. This is the reason why BIO was abolished after Tomcat 8.5 has version 9.

  • Thread Pool

    The advantage of the thread pool lies in the unified management. If the thread pool is used, if the idle time of the thread reaches for example (60 seconds), it will be automatically recycled. If the thread pool is not used, the gc thrown by the thread pool is recycled. (Jvm recycling mechanism), this is difficult to control, so the biggest advantage of using thread pool is to ensure the stability of the system. Many times when we do projects, stability comes first.

3. Web.xml optimization in Tomcat

JSP is actually a process of jsp -> java -> class. Tomcat will perform these operations on the JSPs you visit during the running process. In fact, we can compile them in advance to save performance.

4. Optimization of Tomcat in SpringBoot

TomcatContextCustomizer and TomcatConnectorCustomizer are used in SpringBoot to implement Tomcat, you can look at the source code in this area

Guess you like

Origin blog.csdn.net/weixin_43935927/article/details/108741585