Tomcat Memory Sizing

Source: Internet
Author: User
Tags app service xms

Tomcat itself cannot run directly on the computer, it needs to rely on a hardware-based operating system and a Java virtual machine. When the Java program starts, the JVM allocates an initial memory and maximum memory to the application. This initial memory and maximum internal presence will affect the performance of the program in some degree. For example, when the application uses the maximum memory, the JVM is going to do garbage collection first, freeing up some of the memory that is occupied. So if you want to adjust the initial memory and maximum memory on tomcat boot, you need to declare to the JVM that the generic Java program can run through-XMS-XMX to adjust the application's initial memory and maximum memory: 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. There are several ways to choose from:

The first method:

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.

The second method: set the variable name in the environment variable: java_opts variable value:-xms512m-xmx512m

The third method: the first two methods for the bin directory under the Catalina.bat (such as the direct decompression of Tomcat, etc.), but some installed version of Tomcat is not catalina.bat, this time can use the following methods, of course, this method is the most common method: Open Tomcath Ome//bin//tomcat5w.exe, click on the Java tab, and you'll find two of them: Initial memory pool and maximum memory pool. Initial memory Pool This is the amount of RAM initialized to set. Maximum memory Pool This is the maximum size of the RAM set, press OK and then reboot Tomcat you will find that the memory available to the JVM in Tomcat has changed

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.

A place to pay attention to: it is recommended that the highest value of memory and the lowest value of the difference is reduced, otherwise it will waste a lot of memory, the lowest value, the highest value can be arbitrarily set, but according to the actual physical memory, if the memory settings are too large, such as setting the 512M maximum memory, but if there is no 512M of available Tomcat cannot be started, and there may be memory being reclaimed by the system, terminating the process.

Transfer from http://blog.csdn.net/coolwzjcool/article/details/2544448

Tomcat Memory Sizing

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.