1

We have a service in production written in Kotlin where we are using G1GC for garbage collection.

And for some reason we have way too many GC events (43k; also attached the data below) since the eden space is filling very frequently.

bash-4.2$ java --version
openjdk 17.0.7 2023-04-18 LTS
OpenJDK Runtime Environment Zulu17.42+20-SA (build 17.0.7+7-LTS)
OpenJDK 64-Bit Server VM Zulu17.42+20-SA (build 17.0.7+7-LTS, mixed mode, sharing)

Run jstat for memory analysis on pod in Kubernetes

jstat -gcutil 1 1000 100

And output is:

S0     S1     E      O      M     CCS    YGC     YGCT     FGC    FGCT     CGC    CGCT       GCT
0.00  51.06  89.92  71.15  99.22  96.71  43188   144.723     0     0.000  4342    28.840   173.564
0.00  56.16   1.54  71.99  99.22  96.71  43189   144.726     0     0.000  4344    28.847   173.573

bash-4.2$ jstat -gc 1 250 1
    S0C         S1C         S0U         S1U          EC           EU           OC           OU          MC         MU       CCSC      CCSU     YGC     YGCT     FGC    FGCT     CGC    CGCT       GCT   
    0.0      2048.0         0.0      1319.0     256000.0     184320.0     184320.0     130305.0   106368.0   105551.6   12544.0   12131.7  43521   146.160     0     0.000  4510    29.960   176.120

So what I observed in Production

  1. Eden Space is filling very fast which is triggering more GC events
  2. Old Space is also growing consistently

We wanted to tune GC params so that we can get the optimal performance from the application.

Our application is String heavy (uses a lot of strings) for sure which I can say, so I wanted to check what all option we can consider for tuning.

-Xmx -Xms -XX:+UseStringDeduplication -XX:+UseAdaptiveSizePolicy

Ajay Kumar
  • 586
  • 5
  • 21
  • I doubt it's possible to say much without seeing your code. But in some cases which had lots of functions returning strings and concatenating them, I got big wins by instead passing a StringBuilder around so functions could append to it. I'd suggest checking your code to see whether you can do similar things to reduce object allocation. – gidds Jul 11 '23 at 22:29

0 Answers0