Tomcat performance adjustment (1)

xiaoxiao2021-03-13  191

I. Introduction

Performance Test and Analysis is a wide range of software development and more uncommonly understood, which is more complex activities. Like playing chess games, effective performance testing and analysis can only be successfully completed in a good planning strategy and has a smooth processing capability of unpredictable events. A chess master wins the game is more than just awareness of the rules of the game, but also relying on his own capabilities and constantly focusing on the analysis of your opponent's strength to make more effectively utilization and play the rules. The same excellent performance testing and analysts will face the challenges from a new application and environment. The author in this paper combines its own experience and reference documentation, making a brief introduction to Tomcat performance, and gives Tomcat performance test, analysis, and adjustment of optimization.

2. Measure the performance of the web server

Measuring the performance of the web server is a task that makes people feel that we will give some places that need attention and point you to more detailed content. It is not like some simple tasks, such as measurement of the rate of CPUs or the ratio of the measurement program occupies the CPU, including the Many variables in the performance optimization of the web server to achieve the goal. Many measurement strategies contain a seemingly simple browsing actually send a large number of requests to the server, we call the client's program to measure the response time. Is the client and server side on the same machine? Does the server run other procedures when testing? The communication of the client and server is through the LAN, 100BASET, 10BASET or the modem? Has the client repeatedly request the same page, or randomly accesses different pages? (These affect the performance of the service cache) The regularity of the client sends a request or burst? Are you running a service in the final configuration environment or running services in debugging configuration environments? The client request contains pictures or only HTML pages? Whether there is a request to pass servlets and jsp, CGI programs, server contains (Server-Side Includes, SSI is a technology that allows you to use dynamic HTML files)? All of this will be what we have to care, and almost we can't accurately list all the problems clearly.

Pressure test tool

"Workers must have a good fault, you must take care of them", and the pressure test can be implemented only by means of some tools.

The implementation principle of most Web pressure test tools is to simulate multiple users' concurrent access to the measured system by repeated a large number of page requests to achieve the purpose of generating pressure. The means of generating pressure are recorded by recording or writing a pressure script, which run in the client in the form of multiple processes or threads, so that people are manufactured by various types of stress, we can observe the status of the measured system in various stress conditions. The manifestation is to position the system bottleneck as the basis of system tuning. At present, the performance test tools of the performance test tools, the quantity is not one hundred, from a single open source free gadget such as aapache's own web performance test tool Apache Benchmark, open source JMeter to large business performance test software such as Mercury Loadrunner, etc. Any performance test tool has its advantages and disadvantages, we can choose the most appropriate tools according to the actual situation. You can find some web pressure test tools at http://www.softwareqatest.com/qatweb1.html#load

Here we use the tool to support web application service certification, you must support reception to send cookies, not only such Tomcat supports multiple authentication methods, such as basic authentication, form-based authentication, mutual authentication, and client authentication, and some tools are only Supports HTTP basic certification. Really simulating user authentication is an important part of the performance test tool, because the authentication mechanism will have an important impact on the performance characteristics of a Web site. Based on the different authentication methods you have used in our products, you need to select a test tool that uses this feature from the top of the tool list. Apache Benchmark and http_load are tools for command lines, very easy to use. Apache Benchmark can mimic separate URL requests and repeatedly executed, you can use different command line parameters to control the number of iterations, the number of users, and the like. One of its features is to periodically printed information about the process, while other tools can only give a global report.

2. Introduction to Pressure Test Tools

Third. Adjustment of external environments After the Tomcat and applications, if you are not very satisfied with the performance results of the application, you can take some performance adjustment measures. Of course, the application is no problem, we only Tell the Tomcat adjustment. Since Tomcat is dependent on JVM, we will divide Tomcat's adjustment into two caterees in detail:

External environmental adjustment

Adjust non-Tomcat components, such as Tomcat running

Operating system and Java virtual machine running Tomcat.

Self-adjustment

Modify the parameters of Tomcat itself, adjust the parameters in the Tomcat configuration file.

Below we will explain in detail the relevant content of external environment, Tomcat's own adjustment will be elaborated in Part 2.

1.Java virtual machine performance optimization

Tomcat itself cannot run directly on your computer, requiring the operating system on the hardware and a Java virtual machine. You can choose your own needs to select different operating systems and the corresponding JDK version (as long as you meet the Java specifications released by Sun), but we recommend you to use the JDK released by Sun. Make sure the version you are using is the latest, because Sun and other companies have been doing some upgrade improvements to Java virtual machines for improved performance. Some reports show that JDK1.4 increases nearly 10% to 20% compared to JDK1.3.

You can set up the memory for the Java virtual machine, but if your choice is wrong, the virtual machine will not compensate. The virtual machine can be changed by the command line to change the size of the memory. There are two parameters as shown in the following table to set the size of the virtual machine to use memory.

Parameter Description -XMS JVM initialization stack size -XMX JVM pile maximum

The size of these two values ​​is generally set as needed. The size of the initialization pile performs the size of the virtual machine to apply to the system to the system at startup. In general, this parameter is not important. However, some applications will explore more memory in large loads. At this time, this parameter is very important. If the virtual machine is started, the memory is smaller, and there are many objects in this case. Initialization, the virtual machine must repeatedly increase the memory to meet usage. For this reason, we generally set -XMS and -XMX as large, and the maximum value of the heap is limited by physical memory used by the system. General use of a large amount of data using a long-lasting object, memory usage is possible to grow rapidly. The virtual machine will prompt memory overflow when the memory needs to be more than the maximum of the reaps, and cause the application service to crash. Therefore, the maximum recommended pile is set to 80% of the maximum value of available memory.

Tomcat can be used by default to 128MB, in larger application items, this memory is not enough, it needs to be protected.

Under Windows, under the file {tomcat_home} /bin/catalina.bat ,unix, in front of the file {tomcat_home} /bin/catalina.sh, add the following settings: java_opts = '- XMS [Initialization Memory Size] -XMX [ Maximum memory use] '

This two parameter values ​​need to be maintained. E.g:

Java_opts = '- XMS256M -XMX512M'

Indicates that initialization is 256MB, and the maximum memory that can be used is 512MB.

In addition, it is necessary to consider the garbage collection mechanism provided by Java. The stack of virtual machines determines the time and frequency of the virtual machine to collect garbage. The speed and application of the collection of garbage should be adjusted by analyzing the time and frequency of the actual garbage collection. If the stack is large, the complete garbage collection will be slow, but the frequency will be reduced. If you consistentize the size and memory of the heap, it is completely collected, but it will be more frequent. The purpose of adjusting the size of the heap is to minimize the time of garbage collection to maximize the request of the customer within a specific time. In the benchmark test, in order to ensure the best performance, the size of the heap should be large, and the garbage collection does not appear in the process of the entire reference test.

If the system takes a lot of time to collect garbage, reduce the heap size. A complete garbage collection should not exceed 3-5 seconds. If garbage collects into bottlenecks, then requires the size of the generation, check the detailed output of garbage collection, and study the impact of garbage collection parameters on performance. Generally speaking, you should use 80% of physical memory as a heap size. When the processor is added, remember to increase the memory because allocation can be done in parallel, and the garbage collection is not parallel.

转载请注明原文地址:https://www.9cbs.com/read-129036.html

New Post(0)