checkmarx-ts / checkmarx-cxflow-github-action

Checkmarx CxFlow GitHub Action with SARIF output
GNU General Public License v3.0
52 stars 53 forks source link

JVM Heap Settings are not optimized causing JVM OOM #37

Closed benjaminstokes closed 2 years ago

benjaminstokes commented 2 years ago

checkmarx-cxflow-github-action does not provide any mechanism to configure Java memory settings like -Xmx -Xms or other.

Background

The CxFlow Runtime Environment for Github Actions

Github actions are executed on Github's servers which have 2 processors and 7 GB of memory available.

See Supported runners and hardware resources which states:

Hardware specification for Windows and Linux virtual machines:

CxFlow is executed using the Java 8 version of the cxflow container.

java.runtime.name = OpenJDK Runtime Environment
java.runtime.version = 1.8.0_275-b01

Improved container memory configuration support was backported from Java 10 into Java 8 in sufficiently long ago builds of 8. See https://blog.softwaremill.com/docker-support-in-new-java-8-finally-fd595df0ca54.

These new features provide 3 JVM options for configuring jvm memory in container environments.

For CxFlow's purposes where we anticipate it will run on server environments, the -XX:MinRAMPercentage is irrelevant.

How do these settings affect CxFlow's memory?

CxFlow is using these percentage default values today:

double InitialRAMPercentage                      = 1.562500
double MaxRAMPercentage                        = 25.000000
double MinRAMPercentage                         = 50.000000

The default percentages in Github Action environments result in these settings:

uintx HeapSizePerGCThread                       = 87241520
uintx LargePageHeapSizeThreshold           = 134217728
uintx InitialHeapSize                                   := 115343360
uintx MaxHeapSize                                     := 1822425088

Where 1822425088 bytes is approx 1.8 GB which is approx 25% of 7GB available in the Github Action environment.

How out of memory exceptions occur

If CxFlow requires more heap than 1.8 GB then an out of memory exception will occur. This can happen if a report for a scan is sufficiently large.

Proposed Solution

Github Action Environment Memory Percentages

MaxRAMPercentage Max Heap Size (bytes) Max Heap Size (GB)
1.0 132120576 0.132
25.0 1822425088 1.8
50.0 3644850176 3.6
75 5467275264 5.4
90 6561988608 6.5