From: Chapter 3 of Java Performance
Initial Heap Space Size Configuration
This section describes how to use live data size calculations to determine an initial Java heap size. figure 7-3 shows the fields that identify an application's live data size. it is wise to compute an average of the Java heap
Occupancy and garbage collection duration of several full garbage collections for your live data size calculation. The more data you collect, the better the estimate for a Java heap size starting point.
Using the live data size information, an informed demo-can be made on an initial Java heap size to use along with an estimate of the worst case latency due to full garbage collections.
As a general rule, the initial and maximum Java heap size command line options,-Xms and-Xmx, shocould be set to a value between three and four times larger than the live data size of the old generation space. in the full garbage
Collection data shown in Figure 7-3, the old generation space occupancy after the full garbage collection is 295111 K, or about 295 megabytes. hence, the live data size is about 295 megabytes. therefore, the suggested initial and maximum Java heap size to specify
For this application shoshould be a value between 885 and 1180 megabytes, that is,
-Xms1180m-Xmx1180m for four times the live data size. in Figure 7-3, the Java heap size in use is 1048570 K, about 1048 megabytes. this Java heap size is at the upper end of the recommendation.
Also as a general rule, the initial and maximum permanent generation size,-XX: permsize and-XX: maxpermsize, shocould be 1.2X to 1.5x larger than the live data size of the permanent generation space. in the example full garbage
Collection shown in Figure 7-3, the permanent generation space occupancy after the full garbage collection is 32390 K, or about 32 megabytes. hence, the suggested initial and maximum permanent generation space size to specify for this application shocould be
Between 38 megabytes and 48 megabytes, that is,-XX: permsize = 48 m-XX: maxpermsize = 48 m, for 1.5 times the permanent generation live data size. in Figure 7-3, the permanent generation space size in use is 65536 K, about 65 megabytes. although
This is abve the recommended size of 38 to 48 megabytes, 17 additional megabytes in the context of a 1 gigabyte Java heap space is not worth worrying about.
As an additional general rule, the young generation space shoshould be 1 to 1.5 times the old generation space live data size. in the example full garbage collection shown in Figure 7-3, the live data size is about 295 megabytes.
As a result, the suggested young generation size shocould be between 295 and 442 megabytes. in Figure 7-3, the young generation space size is 358400 K, about 358 megabytes. 358 megabytes is within the recommended size.
If the initial and maximum Java heap size is 3x to 4x the live data size and the young generation space is 1x to 1.5x the live data size, the size of the old generation space shocould be between 2x to 3x the live data size.
The combined Java command line applying these general sizing rules based on the garbage collection data in Figure 7-3 is:
$ java -Xms1180m -Xmx1180m -Xmn295m -XX:PermSize=48m -XX:MaxPermSize=48m
Guidelines to follow when calculating Java heap sizing are summarized in Table 7-3.