上个月我们公司的Liferay专家请我帮她合理分配perm和heap size从而能让liferay服务器可以达到最高的性能:我从我的经验出发,给了我认为最理想的内存划分。

直接贴上原始邮件内容了:

 

 

Factors into consideration:

 

(1)    Is the server only run Liferay? Or besides it ,it also need to run other services.

 

Perm Space:

(2)    The perm size will not be set too large ,because no GC will clear perm space.

(3)    The perm size will not be set too small ,because if classloader load a lot of classes(For example ,a lot of entry in classpath) ,it will “Perm Gem space overflow” error.

 

Heap Space( GC<Gabbage Collection> will work on Heap space):

(4)    Heap Size should not be set to too small, if too small ,a lot of GC will happen ,which reduce the server performance.

(5)    The - xms should not  be set too large ,otherwise , the GC thread will update the heap’s  Young to Old frequently.

(6)    It’s better that –xms  is equal to –xmx (High Concurrent Application), otherwise ,-xms should be 1/2 to 1/3 of the -xmx, and –xmn is 1/3 of the -xmx

 

Stack:

(7)    If we don’t have a lot of recursion invocation ,this number shouldn’t be set to too large.

 

GC:

(8)    If Heap Size is too large ,it will cost a lot of time to do GC ,but since it is low –priority process, so it won’t affect too much.

 

 

The Result:

 

 

If the server’s memory is M ( It should be physical memory (vi /proc/meminfo)  minus the necessary daemon process’s occupation)

 

If our application is (1) dedicated application (2) less concurrency access (3) don’t need a lot of temp memory (4) web framework ,don’t have sophisticated recursion

 

My  suggestion:

 

Heap:

-xmx   2/3M (Large can reduce the frequency of GC, but increase the GC time )

-xms   1/3M( Since we are not the high-concurrence application ,unlike e-commerce website, only a few person use our portal website ,so  set xms to ½ of –xmx is enough)

-xmn  256M(  we should set it as small as possible if we don’t need too many temp memory)

 

 

Perm:

-xxPermSize  128M (the minimum of the perm size , 256M is enough for our  liferay server ,because it is not need so many classes to load by classloader)

We can use jmap to collect the perm size that our running process actually occupied (Suppose our liferay running instance is 7317):

[cwang58@cwang58-linux eclipse]$ jmap 7317

Attaching to process ID 7317, please wait...

Debugger attached successfully.

Server compiler detected.

JVM version is 20.4-b02

0x00215000      109K    /lib/ld-2.3.4.so

0x00234000      1511K   /lib/tls/libc-2.3.4.so

0x00366000      209K    /lib/tls/libm-2.3.4.so

0x0038b000      16K     /lib/libdl-2.3.4.so

0x00511000      105K    /lib/tls/libpthread-2.3.4.so

0x00aa5000      79K     /lib/libresolv-2.3.4.so

0x00dc1000      49K     /lib/tls/librt-2.3.4.so

0x0478d000      99K     /lib/libnsl-2.3.4.so

0x08048000      46K     /app/jdk1.6.0_29/bin/java

0x6066f000      22K     /lib/libnss_dns-2.3.4.so

0x60f06000      26K     /app/jdk1.6.0_29/jre/lib/i386/headless/libmawt.so

0x60f0c000      612K    /app/jdk1.6.0_29/jre/lib/i386/libawt.so

0x62fe8000      94K     /app/jdk1.6.0_29/jre/lib/i386/libnet.so

0x63441000      34K     /app/jdk1.6.0_29/jre/lib/i386/libmanagement.so

0x63773000      18K     /app/jdk1.6.0_29/jre/lib/i386/libdt_socket.so

0xb70d0000      75K     /app/jdk1.6.0_29/jre/lib/i386/libzip.so

0xb70e1000      46K     /lib/libnss_files-2.3.4.so

0xb72fd000      12K     /app/jdk1.6.0_29/jre/lib/i386/libnpt.so

0xb7301000      272K    /app/jdk1.6.0_29/jre/lib/i386/libjdwp.so

0xb733e000      184K    /app/jdk1.6.0_29/jre/lib/i386/libjava.so

0xb7363000      55K     /app/jdk1.6.0_29/jre/lib/i386/libverify.so

0xb73c0000      10022K  /app/jdk1.6.0_29/jre/lib/i386/server/libjvm.so

0xb7fe5000      37K     /app/jdk1.6.0_29/jre/lib/i386/jli/libjli.so

 

Not so much.

 

 

-xxMaxPermSize 256M ( the maximum perm size ,in occasion ,it should be double of the minimum perm size )

 

Stack:

-Xss 256k(because we are web application ,don’t need sophisticate calculation)

 

 

One Solution:

If our memory is 4G ( suppose 1G is occupied by OS and daemon processes)

 

One of the best practice is :

 

-xmx 2048M

-xms 1024M

-xmn 256M

-xxPermSize 128M

-xxMaxPermSize 256M

-Xss 256k