4

I have Tomcat with configured XMS=XMX (4G both).

But - what if I'll set XMS for example 1G?

As I understood - JVM will start Tomcat with provided 1G memory. Then, if application needs more - JVM will rise it up to 4G in some period. To rise it - Java must run some actions (resize, rellocate pages in memory?) - and it's take some time and CPU resourses, correct?

What happened after Tomcat's application doesn't need so much memory? Java will again run actions to decrease used memory?

Thanks.

P.S. Why I'm asking - with XMS=1G and XMX=4G Apache Jmeter give results which is much less (Throughput and Average), than if I started Tomcat with XMX and XMS both 4G.

setevoy
  • 4,374
  • 11
  • 50
  • 87
  • possible duplicate of [What are the Xms and Xmx parameters when starting JVMs?](http://stackoverflow.com/questions/14763079/what-are-the-xms-and-xmx-parameters-when-starting-jvms) – dotancohen Dec 24 '14 at 09:51

2 Answers2

2

Yes, the JVM has to allocate more memory and re-arrange all of the heap spaces (Eden, from, to, old, and PermGen) to fit into the new memory. If you are planning to have your webapp use a certain amount of heap space, then you are better off performance-wise pre-allocating the entire heap.

The JVM will never release memory it has take from the OS once it has done so. So, if you need 4GiB heap and the JVM eventually takes it, your heap will stay at 4GiB until the JVM is terminated.

Christopher Schultz
  • 20,221
  • 9
  • 60
  • 77
  • I've heard rumors that the new G1 ("garbage-first") garbage-collector can return memory to the OS, but I haven't been able to find that documented anywhere. The work required to re-size the heap is so great that I think down-sizing the whole heap would be avoided in general. If you don't want your JVM process to take more than X amount of memory, simply don't allow it in the first place ;) – Christopher Schultz Dec 19 '13 at 16:48
1

When Setting Xms and Xmx to equal values The JVM won't have to resize the heap and avoids the time that the JVM will spend on that . This will give indeed better results in your case, since using Jmeter, you are stressing the server that will need to increase the heap. Once you finsih with Jmeter , your Tomcat will reduce the heap after some Garbage collector activities which will destroy uneeded objects.

Ali HAMDI
  • 365
  • 1
  • 11