GenSpectrum / LAPIS

An API, a query engine, and a database schema for genomic sequences; currently with a focus on SARS-CoV-2
https://lapis-three.vercel.app
GNU Affero General Public License v3.0
19 stars 5 forks source link

Allow passing JVM_OPTS to LAPIS #821

Closed corneliusroemer closed 2 months ago

corneliusroemer commented 2 months ago

If one wants LAPIS to release unused heap back to the system, it's necessary to add JVM_OPTS like this:

JVM_OPTS="-XX:+UseContainerSupport -XX:+UseG1GC -XX:MaxHeapFreeRatio=5 -XX:MinHeapFreeRatio=2"

because otherwise the JVM is happy to reserve a lot of memory, close to the allocated memory, even though little of the heap is in fact used.

I can't see from the docs whether or not, and if so how to add those JVM_OPTS.

A current workaround to limit LAPIS memory usage is to limit available memory tightly, e.g. via memory limits in kubernetes. But it would be good to have high limits and still use minimum memory whenever possible.

corneliusroemer commented 2 months ago

A simple way of allowing custom JVM_OPTS would be to use an entrypoint.sh script instead of the current https://github.com/GenSpectrum/LAPIS/blob/60862b7c7834dfb8bfbdba9bd147c982bada14e5/lapis2/Dockerfile#L17-L23

The entrypoint would then be ENTRYPOINT ["./entrypoint.sh"] and entrypoint.sh would look like:

#!/bin/sh
JVM_OPTS=${JVM_OPTS:-}
# Take script arguments
ARGS="${*}"

if [ -n "$JVM_OPTS" ]; then
    CMD="java $JVM_OPTS -jar app.jar --spring.profiles.active=docker --referenceGenomeFilename=./reference_genomes.json  $ARGS"
else
    CMD="java -jar app.jar --spring.profiles.active=docker --referenceGenomeFilename=./reference_genomes.json $ARGS"
fi
echo Running:
echo "$CMD"
$CMD