Question

I'm not interested for a specific application or environment. Although I'm facing this problem with my application deployment now, I'm interested in a more general solution.

Are there some rules on how big to set the heap size on a java server? (Especially now, I'm working with Tomcat 7). With -Xms and -Xmx you can specify the minimum respectively maximum values for heap size. Based on the applications that are deployed on server, how to know what maximum and minimum heap size to set. Is there a generic way to find it, or is it more empirical, related to the deployed application(s) ? - by 'related to the deployed appliccation(s)' I mean that you must know what your application is doing, database work, user interface work, or any other memory consumer things.

Was it helpful?

Solution

This is empirical - observe your application and see how it behaves.

And there is more to it - for a starter, read about memory pools and how to size them. If you get into it, look at http://www.javaperformancetuning.com/ - there's a lot of materials about tuning memory issues, and more.

Now, in the usual case, you should not bother with -Xms. Set -Xmx to whatever value your application needs (observe, to find out). JVM increases the size of memory pools when it needs to, and decreases them accordingly. Just make sure, you don't get OutOfMemoryErrors. And then, look into your application for memory bottlenecks (like, for example full GC's, or long stop-the-world phase), and size the pools and/or configure the GC if you need to.

OTHER TIPS

I have done java web app in several companies and for all of them it was completely empirical. It was mostly depending on the machine, not on the application. For example, if you have a machine with 4GB with only a tomcat server, then you allow it to take 3GB. If the server is low on memory, you try to fix it or you buy more memory... I think it's cheaper than paying someone to calculate the memory needed...

I think it is also like that in big companies, there's no secret...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top