Tomcat itself cannot be run directly on the computer, it needs to rely on a hardware-based * system and a Java virtual machine. You can choose your own choice of different * system and the corresponding JDK version (as long as it complies with the Sun Release Java specification), but we recommend that you use Sun's published JDK. Make sure that the version you are using is up to date because sun and some other companies have been upgrading Java virtual machines to improve performance. Some reports show that JDK1.4 has improved performance by nearly 10% to 20% compared to JDK1.3.
You can set the memory used for the Java Virtual machine, but the virtual machine will not compensate if your choice is not correct. The size of the memory used by the virtual machine can be changed by the command line. As shown in the following table, there are two parameters to set the size of the memory used by the virtual machine.
Parameters
Describe
-xms
The size of the JVM initialization heap
-xmx
Maximum value of JVM heap
The size of these two values is generally set as needed. The size of the initialized heap performs the amount of memory requested by the virtual machine to the system at startup. Generally speaking, this parameter is not important. However, some applications in the case of heavy load will take up more memory, when this parameter is very important, if the virtual machine is set up when the memory is relatively small and in this case there are many objects to initialize, the virtual machine must repeatedly increase the memory to meet the use. For this reason, we generally set-XMS and-xmx as large, and the maximum value of the heap is limited by the physical memory used by the system. Applications that use large amounts of data generally use persistent objects, and memory usage can grow rapidly. The virtual machine prompts for memory overflow when the application needs more memory than the heap, and causes the app service to crash. Therefore, it is generally recommended that the maximum heap value be set to 80% of the maximum available memory.
Tomcat can use 128MB of memory by default, and in larger applications, this memory is not enough and needs to be scaled up.
Under Windows, under File/bin/catalina.bat,unix, in front of file/bin/catalina.sh, add the following settings:
java_opts= '-xms ' Initialize memory size "-XMX" maximum memory that can be used "'
You need to increase the value of this two parameter. For example:
java_opts= '-xms256m-xmx512m '
Indicates that the initialized memory is 256MB and the maximum memory that can be used is 512MB.
Another thing to consider is the garbage collection mechanism provided by Java. The heap size of a virtual machine determines the time and frequency at which the virtual machine spends collecting garbage. The rate at which garbage collection can be accepted is related to the application and should be adjusted by analyzing the time and frequency of actual garbage collection. If the heap size is large, then the total garbage collection will be slow, but the frequency will be reduced. If you match the size of the heap to the needs of the memory, it will be collected very quickly, but more often. The purpose of sizing the heap is to minimize garbage collection time to maximize processing of customer requests over a specific time period. In benchmarking, to ensure the best performance, the size of the heap to be large, to ensure that garbage collection does not occur throughout the baseline test process.
If your system spends a lot of time collecting garbage, reduce the heap size. A complete garbage collection should be no more than 3-5 seconds. If garbage collection becomes a bottleneck, you need to specify the size of the generation, check the detailed output of the garbage collection, and investigate the performance impact of garbage collection parameters. Generally speaking, you should use 80% of the physical memory as the heap size. When adding processors, remember to increase the memory because allocations can be done in parallel, and garbage collection is not parallel.
Tomcat 5 common optimizations and configurations
1. JDK Memory Optimization:
Tomcat defaults to the memory used by 128mb,windows, under file {Tomcat_home}/bin/catalina.bat,unix, in file {tomcat_home}/bin/ In front of the catalina.sh, add the following settings:
Java_opts= '-xms[initialize memory size]-xmx[maximum memory that can be used]
Generally speaking, you should use 80% of the physical memory as the heap size.
2, connector optimization:
In the configuration in Tomcat configuration file Server.xml, the parameters related to the number of connections are:
MaxThreads:
Tomcat uses threads to process each request that is received. This value represents the maximum number of threads that Tomcat can create. The default value is 150.
Acceptcount:
Specifies the number of requests that can be placed in the processing queue when all the threads that can be used to process the request are used, and requests that exceed this number will not be processed. The default value is 10.
Minsparethreads:
The number of threads created when Tomcat was initialized. The default value is 25.
Maxsparethreads:
Once you create a thread that exceeds this value, tomcat closes the socket thread that is no longer needed. The default value is 75.
Enablelookups:
Whether to reverse the domain name, the default value is true. To improve processing power, set to False
Connnectiontimeout:
Network connection timed out, default value 60000, in milliseconds. Set to 0 to never time out, so the setting is hidden. It can usually be set to 30000 milliseconds.
Maxkeepaliverequests:
Keep the number of requests, the default value of 100.
BufferSize:
Input stream buffer size, default value 2048 bytes.
Compression
Compressed transfer, value On/off/force, default value off.
The parameters associated with the maximum number of connections are maxthreads and Acceptcount. If you want to increase the number of concurrent connections, both parameters should be increased. The maximum number of connections allowed by Web server is also subject to the system's kernel parameter setting, usually Windows is about 2000, and Linux is about 1000.
3. How to disable and allow files in a column directory in Tomcat
In {tomcat_home}/conf/web.xml, set the listings parameter to False, as follows:
<servlet>
...
<init-param>
<param-name>listings</param-name>
<param-value>false</param-value>
</init-param>
...
</servlet>
4. How to disable and allow host or IP address access in Tomcat
...
<valve classname= "Org.apache.catalina.valves.RemoteHostValve"
allow= "*.mycompany.com,www.yourcompany.com"/>
<valve classname= "Org.apache.catalina.valves.RemoteAddrValve"
deny= "192.168.1.*"/>
...
</Host>
Configuration of the server
java_opts= '-server-xms512m-xmx768m-xx:newsize=128m-xx:maxnewsize=192m-xx:survivorratio=8 '
Java.lang.OutOfMemoryError:PermGen space and how to solve it
PermGen space is the full name of permanent Generation space, refers to the memory of the permanent storage area Outofmemoryerror:permgen space from the surface is the memory benefits, the solution must be to increase memory. Tell me why memory Benefits: This section is used to store class and meta information, and class is placed in the PermGen space area when it is loaded, unlike the heap area where instance is stored, GC (garbage Collection) PermGen space will not be cleaned during the main program's run time, so if your app will load many classes, you will likely have permgen space errors. This error is common when the Web server pre-compile the JSP. Correction Method:-xms256m-xmx256m-xx:maxnewsize=256m-xx:maxpermsize=256m 2, a outofmemory error occurred while redeploy in Tomcat. There are several reasons for this:1, Proxool is used because the Proxool contains an older version of Cglib.2, log4j, better not, just use common-.Logging3, the old version of Cglib, quickly update to the latest version. 4, update to the latest hibernate3.2 3, here is the Tomcat environment, for example, other Web servers such as Jboss,weblogic and so on is the same reason. First, Java.lang.OutOfMemoryError:PermGen space PermGen space is the full name of permanent Generation space, refers to the memory of the permanent storage area, This memory is primarily stored by the JVM with class and meta information, and class is placed in PermGen space when it is loader, unlike the heap area where the class instance (Instance) is stored, GC (garbage Collection) PermGen space will not be cleaned up during the main program run time, so if you have many classes in your application, you are likely to have PermGen space errors, which are common when the Web server pre-compile the JSP. If you have a large number of third-party jars under your web app that are larger than the JVM's default size (4M), this error message will be generated. Workaround: Manually set the MaxPermSize size modification tomcat_home/bin/catalina.sh on "echo" Using catalina_base: $CATALINA _base "" Add the following line: java_opts= "-SERVER-XX:PERMSIZE=64M-XX: Maxpermsize=128m Recommendation: Move the same third-party jar file to tomcat/shared/Lib directory, this can be achieved by reducing the memory consumption of the jar document repeatedly. Java.lang.OutOfMemoryError:Java Heap Space Heap Size setting the JVM heap is the setting of the amount of memory space that the JVM can provision during the run of the Java program. The JVM automatically sets the heap when it starts The value of size, its initial space (that is,-XMS) is 1/64 of the physical memory, and the maximum space (-XMX) is 1/4 of the physical memory. You can use options such as the-XMN-XMS-XMX provided by the JVM to set it up. The size of Heap size is the sum of young Generation and tenured generaion. Tip: This exception message is thrown in the JVM if 98% of the time is used for GC and the available heap size is less than 2%. Tip: The Heap Size does not exceed 80% of the available physical memory, generally the-XMS and-XMX options are set to the same, and the-XMN is 1/4-The xmx value. Workaround: Manually set the heap size to modify Tomcat_home/bin/catalina.sh on "echo" Using catalina_base: $CATALINA _base "" Add the following line: java_opts= "-SERVER-XMS800M-XMX800M-XX: maxnewsize=256m "Third, example, the following gives the parameters of the JAVA JVM in the 1G Memory Environment reference: Java_opts= "-server-xms800m-xmx800m-xx:permsize=64m-xx:maxnewsize=256m-xx:maxpermsize=128m-djava.awt.headless=true"
Tomcat Performance Optimizations