Tomcat6.0.37 (64-bit) memory tuning in Windows and Linux

Source: Internet
Author: User
Tags xms visualvm

I. Common Java memory overflow includes the following three types:

 

1.Java. Lang. outofmemoryerror: Java heap Space---- JVM heap (HEAP) Overflow
The JVM automatically sets the JVM heap value at startup. The initial space (-XMS) is 1/64 of the physical memory, and the maximum space (-xmx) cannot exceed the physical memory.

You can use options such as-xmn-XMS-xmx provided by JVM to set the configuration. The heap size is the sum of young generation and tenured generaion.

In JVM, if 98% is used for GC and the available heap size is less than 2%, this exception is thrown.

Solution: manually set the JVM heap size.

 

2.Java. Lang. outofmemoryerror: permgen Space---- Permgen space overflow.
Permgen space stands for permanent generation space, which is the permanent storage area of the memory.

Why is the memory overflow? This is because the memory is mainly used by JVM to store class and meta information. When the class is loaded, it is placed in the permgen space area, it is different from the heap region where the instance is stored, and Sun's GC will notProgramPermgen space is cleaned up during runtime. Therefore, if your app loads many classes, permgen space overflow may occur.

Solution: manually set the maxpermsize

 

3.Java. Lang. stackoverflowerror---- Stack Overflow
Stack Overflow. The JVM is still a stack-type virtual machine, which is the same as C and Pascal. The call process of the function is reflected in the stack and rollback.
There are too many "layers" for calling constructors, so that the stack zone overflows.
Generally, the stack zone is much smaller than the heap zone, because the function call process is usually no more than thousands of layers, even if each function call requires 1 K space (which is equivalent to declaring 256 int-type variables in a C function), the stack zone only needs 1 MB space. The stack size is usually 1-2 MB.
Generally, recursion should not involve too many recursive layers, so it is easy to overflow.

Solution: modify the program.


Ii. tomcat in Linux (64-bit)

Edit

# sudo VI/opt/tomcat/bin/Catalina. sh
Add a comment in the first line
#! /Bin/sh
java_opts = '-server-d64-xms2g-xmx16g-XX: permsize = 1G-XX: maxpermsize = 4G-XX: -usegcoverheadlimit '
3. tomcat in Windows (64-bit)

EditTomcat/bin/Catalina. BAT file

Find the following content and add the content in the bold Section.

Rem ----- execute the requested command ---------------------------------------
Set java_opts =-server-d64-xms1g-xmx8g-XX: permsize = 512 M-XX: maxnewsize = 512 M-XX: maxpermsize = 1g
Echo using catalina_base: "% catalina_base %"


Iv. JVM parameter description

 

-Server: must be the first parameter. It can be used in multiple CPUs.
-XMS: the initial size of Java heap. The default value is 1/64 of the physical memory.
-Xmx: maximum value of Java heap. We recommend that you set it to half of the physical memory. The physical memory cannot exceed.


-XX: permsize: Set the initial size of the permanent memory storage area. The default value is 64 MB. (I used visualvm.exe to view)

-XX: maxpermsize: sets the maximum size of the permanent memory storage zone. The default value is 64 MB. (I used visualvm.exe to view)

-XX: Invalid vorratio = 2: the size of the survivor pool. The default value is 2. If garbage collection becomes a bottleneck, you can customize the pool settings.

 

-XX: newsize: initial size of the new pool. The default value is 2 MB.

-XX: maxnewsize: maximum size of the newly generated pool.The default value is 32 MB.

If the JVM heap size is greater than 1 GB, the value-XX: newsize = 640 M-XX: maxnewsize = 640 M-XX: Large vorratio = 16 should be used, or allocate 50% to 60% of the total heap size to the newly generated pool. Increase the new object area to reduce the number of full GC operations.


+ XX: aggressiveheap makes XMS meaningless. This parameter allows the JVM to ignore the xmx parameter, frantically eat a GB of physical memory, and then eat a GB of swap.
-XSS: the stack size of each thread. "-XSS 15120" means that every thread added to JBoss consumes 15 MB of memory, and the best value is 128 kb, the default value is 512 KB.


-Verbose: GC real-time garbage collection information
-Xloggc: GC. Log specifies the garbage collection Log File
-Xmn: the heap size of young generation, which is usually set to one of the 3 and 4 points of xmx.
-XX: + useparnewgc: shorten the minor collection time
-XX: + useconcmarksweepgc: shorten the major collection time. This option is more suitable when the heap size is large and the major collection time is long.

-XX: userparnewgc can be used to set parallel Collection [multiple CPUs]
-XX: parallelgcthreads can be used to increase the degree of parallelism [multiple CPUs]
-XX: After useparallelgc is set, you can clear the Collector in parallel [multiple CPUs]

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.