My current tomcat configuration is shown below
and my configuration variables for tomcat are mentioned below -
export CATALINA_OPTS="$CATALINA_OPTS -Xms512m"
export CATALINA_OPTS="$CATALINA_OPTS -Xmx12288m"
export CATALINA_OPTS="$CATALINA_OPTS -Xmn8192m"
export CATALINA_OPTS="$CATALINA_OPTS -XX:NewRatio=1"
export CATALINA_OPTS="$CATALINA_OPTS -XX:SurvivorRatio=4"
export CATALINA_OPTS="$CATALINA_OPTS -XX:+ScavengeBeforeFullGC -XX:+CMSScavengeBeforeRemark"
export CATALINA_OPTS="$CATALINA_OPTS -Xloggc:/opt/tomcat/logs/gc_$(date +%d-%m-%y-%H-%M).log -verbose:gc -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+PrintGCTimeStamps"
The allocation from the above config is well represented in the image above. Young Generation HeapSize
is around 8GBs and Old Generation Heap size
if 4GB. All look good. But I have inspected the gc logs
and found out that garbage collection triggers when the eden space is around 1GB full
2019-02-27T06:26:48.881+0000: 1027.464: [GC (Allocation Failure) [PSYoungGen: 1247052K->30885K(1296896K)] 1283550K->67399K(1360896K), 0.0245425 secs] [Times: user=0.09 sys=0.03, real
=0.02 secs]
2019-02-27T06:28:08.578+0000: 1107.161: [GC (Allocation Failure) [PSYoungGen: 1183909K->31338K(1438720K)] 1220423K->67860K(1502720K), 0.0354672 secs] [Times: user=0.12 sys=0.03, real
=0.03 secs]
2019-02-27T06:29:32.316+0000: 1190.899: [GC (Allocation Failure) [PSYoungGen: 1378672K->31886K(1312768K)] 1415194K->68416K(1376768K), 0.0237727 secs] [Times: user=0.10 sys=0.00, real
=0.03 secs]
2019-02-27T06:30:17.752+0000: 1236.335: [GC (Allocation Failure) [PSYoungGen: 1312398K->31671K(1286144K)] 1348928K->68209K(1350144K), 0.0240825 secs] [Times: user=0.12 sys=0.01, real
=0.02 secs]
2019-02-27T06:31:01.988+0000: 1280.571: [GC (Allocation Failure) [PSYoungGen: 1248695K->31838K(1188864K)] 1285233K->68385K(1252864K), 0.0288038 secs] [Times: user=0.15 sys=0.00, real
=0.03 secs]
2019-02-27T06:31:44.973+0000: 1323.555: [GC (Allocation Failure) [PSYoungGen: 1188446K->31749K(1166848K)] 1224993K->68295K(1230848K), 0.0231320 secs] [Times: user=0.13 sys=0.00, real
=0.02 secs]
2019-02-27T06:32:26.203+0000: 1364.786: [GC (Allocation Failure) [PSYoungGen: 1131013K->32025K(1077248K)] 1167559K->68579K(1141248K), 0.0351297 secs] [Times: user=0.14 sys=0.00, real
=0.03 secs]
I am confused as to why the eden space
is not taking full 7GB of space before performing a Young GC
. One can see from the logs that gc
is getting triggered every 2 minutes and each gc call is pausing the system for 30 milli-seconds
. Is it possible to fully utilize the allocated heap space.
On production systems, my recommendation is to use identical -Xms
and -Xmx
values, because at startup you want to be sure that the maximum allowed memory is available. You don't want the allocation of the last 2G of memory to fail Sunday night at 3am. This goes along with Holger's comment: You're specifying that you don't want the JVM to allocate all memory - and it obeys that wish.
Another aspect: GC is abstracted away, and rarely is there a reason to care about its details. From an application standpoint you have no clue when it actually appears - it might be during low-load times, every 2 minutes, or when memory is almost full.
With certain GC algorithms and applications it's advisable to identify the smallest amount of memory an application needs, add just a little bit overhead, and configure it, as more frequent short GC runs are better than less frequent long runs. If this still holds in the GC that you're using, and for your application, remains to be found out.
An application should be granted memory based on its needs, rather than based on the memory that happens to be available.
-Xms
. On development systems: Why bother?