Java dynamically increases xmx at runtime

I have a jvm server on my machine, now I want to have 2 apservers of my sitting on one computer, however I want the standby mode to have very low memory allocated by xmx, because its passive, one of main server (active) goes down. I want to allocate more memory for my passive server, which no longer restarts it (I have too many xmx - note that they will consume memory at startup, and I cannot allow outOfMemory).

So, I want passively - low xmx as soon as active decreases, I want my passive to get much more xmx.

Is there any way for me to achieve this. Thanks

+7
java performance
source share
4 answers

It would be nice, but as far as I know, this is not an option with Sun JVM support.

The Xmx option should indicate the maximum memory, so it prevents the JVM from using all of the device’s free memory. If you want to set it higher, it will not require the JVM to allocate all this memory. Why not just set it to a very large number and let the JVM into it for a long time?

To prevent your JVM from starting with too little memory (creating a large number of pauses when increasing the memory size to the required size), configure Xms to the size that you want to allocate for the JVM at startup.

+5
source share

The short answer is that if your particular JVM does not allow you to change these values ​​after initialization, you cannot (I believe this applies to HotSpot).

However, you can achieve your goals without changing Xmx on the fly. For example, you can use the small parameter -Xms , but keep -Xmx relatively high. If the passive server does not use a lot of memory / generation garbage when saving the backup, then the memory will remain next to the Xms value. However, as soon as the backup server switches to this, it will be allowed to expand the allocated memory to the Xmx value as necessary.

See java (windows) or java (* nix) (if -Xms and -Xmx have the same common value on all platforms).

+3
source share

You do not need to configure Xmx in the backup instance if it is not doing anything (or anything else), because it must stay close to the value that you set with Xms until it does the real job.

The Xmx switch determines the maximum amount of heap that a Java instance can use. Xms controls the starting amount.

If you install Xms small on the backup instance and Xmx according to what you need, and then switch to the backup instance (by killing the regular instance), it should work fine.

It may be necessary to actually stop / kill a regular Java process, depending on your available memory, so that the standby process allocates the whole heap that it needs as it moves from the initial heap size to the maximum.

+2
source share

For the JVM to fill the whole bunch, you would need to create enough objects that would survive in the collection of the younger generation. This would be unlikely on an easily bootable backup server.

To improve your chances of catching all the trash in the younger generation, customize your heap of the younger generation accordingly: large sizes, more generations before objects grow. This is a compromise between the fact that your backup server can be tied to the younger generation and the collection profile that you need on your primary server.

Update: The new G1 builder uses different configuration options. PLease see http://www.oracle.com/technetwork/tutorials/tutorials-1876574.html to learn more. The option best suited to your case will be

-XX: InitatingHeapOccupancyPercent = 45 . The percentage of (full) heap load to start a parallel GC loop. It is used by G1 to start a parallel GC cycle based on filling the entire heap, not just one generation. A value of 0 means "do constant GC cycles." The default value is 45 (i.e. 45% full or busy).

IOW, the equivalent of the younger generation's collection will begin when the current heap (initially the minimum heap size) is used up by 45%. Your light load server should never leave a minimum heap size (unless it creates relatively long-lived objects, in which case see -XX: MaxTenuringThreshold).

0
source share

All Articles