Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

side effect for increasing maxpermsize and max heap size

Tags:

java

jvm

Can anybody explain the side effects for increasing the maxpermsize and max heap size?

I know that sometimes, we increase -Xmx when we run into the outofmemory issue. But I am just wondering if there is any side effect that I need to keep in mind when we increase the -Xmx. And how does increasing maxpermsize affect the runtime?

Thanks.

like image 436
user826323 Avatar asked Aug 01 '11 17:08

user826323


People also ask

Does heap size affect performance?

As you increase the maximum heap size relative to the amount of data that your application actually needs (the live set size) it increases throughput because the Parallel GC has to run less frequently and thus can work more efficiently.

Is it good to set the max and min JVM heap size the same?

Setting the minimum and maximum heap size to the same value is typically not a good idea because garbage collection is delayed until the heap is full. Therefore, the first time that the GC runs, the process can take longer. Also, the heap is more likely to be fragmented and require a heap compaction.

Does increasing heap size improve performance?

You can improve performance by increasing your heap size or using a different garbage collector. In general, for long-running server applications, use the J2SE throughput collector on machines with multiple processors (-XX:+AggressiveHeap) and as large a heap as you can fit in the free memory of your machine.

How much heap size we can increase?

The theoretical limit is 2^64 bytes, which is 16 exabytes (1 exabyte = 1024 petabytes, 1 petabyte = 1024 terabytes). However, most OS's can't handle that. For instance, Linux can only support 64 terabytes of data.


1 Answers

Short answer

Doubling java heap size, doubles the waiting time for Garbage Collection pauses, that with current JVM technologies become of multiple seconds when the heap is in the Gb order. It seems that the newly released Java 7 is going to change that.

Long answer

The MaxPermSize is the maximum size for the permanent generation heap, a heap that holds the byte code of classes and is kept separated from the object heap containing the actual instances. One thing to keep in mind in case of web applications, is that in each hot re-deployment this memory usage is going to increase with multiple copies of the same classes. Unless -XX:+CMSClassUnloadingEnabled is specified.

Max Heap Size (-Xmx) and MaxPermSize have to be set taking into consideration how much memory is needed by the application classes and instances, the total memory of the server and the memory needed by other applications.

Another important point is that expanding the memory from the Min Heap Size (-Xms) is a costly operation. Especially in case of financial applications this could mean delays. With similar real-time requirements, it could be a good idea to set -Xms and -Xmx to the same value.

The following talk may be of interest http://www.infoq.com/presentations/Java-without-the-GC-Pauses

From the talk you can evince that the side effect of increasing the heap more than a certain limit 2Gb, 10Gb, 100Gb, means longer pause time for Garbage Collection that could stop everything for seconds or a minute in case of very large heaps.

For that reason with current JVM technology, you want to set the heap large enough to run your application, but not too large. A way to find the right size, could be set it to the largest possible value, then cut in half and keeping on cutting in half until you find problems, when you do, double the last found value and keep it as the chosen heap size for production.

This advice of course applies for large heaps, in the Gb order, if your application runs fine with 256Mb of memory, I would just keep that value without further investigation.

And finally for reference here are some example settings:

-Xms512m -Xmx512m -XX:MaxPermSize=256m -XX:+CMSClassUnloadingEnabled 
like image 109
stivlo Avatar answered Oct 16 '22 17:10

stivlo