Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java - best way to determine -Xmx and -Xms required for any webapp & standalone app

I'd like to know how to determine the heap size required for a standalone app as well as a webapp running on a tomcat server.

How to determine the same after deployment on the server.

Thanks.

like image 999
itsraja Avatar asked Apr 21 '11 09:04

itsraja


People also ask

Where is the main () method of a Java web application?

There is no "main" method (as in application entry point) in web applications, since each servlet is an independent entry point.

Is Java good for web applications?

Java is perfect for developing large web applications too because of its ability to communicate with a large number of systems. Services like peer-web services, database connectivity, and back-end services can also be accessed via Java web development. There are many platforms in Java for web development.

Which edition of Java is used for developing web application?

The Java technologies you'll use to create web applications are a part of the Java EE platform, in addition to many of the Java Platform, Standard Edition (Java SE) classes and packages.


3 Answers

You can start with profiling the memory usage. The JDK (6 upwards) has its Visual VM for example. A tool I personally prefer is the Eclipse Memory Analyzer, originally from SAP, now open. You can analyze heap dumps or hook it up to a java process of your choice.

To programmatically create heap dumps you can use this

like image 67
kostja Avatar answered Sep 22 '22 13:09

kostja


Rule suggested by IBM for Sizing the Java heap , it is for IBM SDK but i dont think there would be much difference in these settings for other SDK's.

Size your Java heap so that your application runs with a minimum heap usage of 40%, and a maximum heap usage of 70%.

like image 44
Vipin Avatar answered Sep 26 '22 13:09

Vipin


we use the -Xloggc:gc-log.txtand -XX:+PrintGCdetails option on the VM and let it run for a while (days) with hig Xmx settings and then you can use GCViewer to render a diagram from the log and get an idea of when how much RAM was consumed, i.e. whether there were peaks, limits reached, loads of GCs slowing down the App, etc.

like image 28
BertNase Avatar answered Sep 25 '22 13:09

BertNase