A small, statically linked CLI tool that simplifies tuning of Java applications for containerized environments. It automatically detects available CPU and memory resources, then generates optimal JVM options to improve performance and reliability.
java-tuner inspects your container or host environment to determine CPU and memory limits, then sets recommended JVM flags. These flags help Java applications run efficiently by:
- Setting memory usage based on available RAM and a configurable percentage.
- Configuring JVM to use the correct number of CPUs.
- Applying sensible defaults for server-class JVM, DNS caching, string deduplication, and more.
This automation removes the guesswork from JVM tuning, especially in dynamic or resource-constrained environments like Docker containers and Kubernetes.
Java's default resource detection often fails in containers, leading to poor performance or crashes. By explicitly setting JVM options based on actual limits, you ensure:
- Predictable memory usage (avoiding OOM errors)
- Efficient CPU utilization
- Faster startup and better runtime stability
Run the CLI to start your Java application with tuned JVM options:
java-tuner [flags] -- [java-class-or-jar] [java-args]All arguments after -- are passed directly to the Java process, allowing you to specify the main class, JAR file, and any application arguments.
You can set environment variables to override detection and behavior:
JAVA_TUNER_PREFIXChange env var prefix (default: JAVA_TUNER_)JAVA_TUNER_CPU_COUNTOverride detected CPU count (same as --cpu-count)JAVA_TUNER_MEM_PERCENTAGEOverride detected memory percentage (same as --mem-percentage)JAVA_TUNER_OPTSAdditional JVM flags (same as --opts)JAVA_TUNER_NO_COLORDisable color output (same as --no-color)JAVA_TUNER_VERBOSEIncrease verbosity (same as --verbose)JAVA_TUNER_LOG_FORMATLog format to use (plain, json, console)JAVA_TUNER_JAVA_BINPath to the Java binary to use (same as --java-bin)
--dry-run, -dPrint actions but don't execute them--no-colorDisable color output--verbose, -vIncrease verbosity of output (shows debug info)--version, -VDisplay the application version and exit--cpu-countOverride detected CPU count--mem-percentageOverride detected memory percentage--optsAdditional JVM flags to pass--java-binPath to the Java binary to use (default: auto-detect)--log-format, -lLog format to use (plain, json, console)
- Docker Entrypoint: Use
java-tunerto launch your Java app with tuned JVM flags automatically. - Kubernetes: Ensure your Java app respects pod resource limits and receives all signals.
- CI/CD: Run Java apps with optimal JVM options for different environments.
JAVA_TUNER_CPU=2 JAVA_TUNER_MEM_PERCENTAGE=75 java-tuner -- -jar myapp.jar --spring.config.location=prod.yamlIn Dockerfile it would look like:
FROM amazoncorretto:17
ADD https://github.com/tgagor/java-tuner/releases/latest/download/java-tuner-linux-amd64 /usr/local/bin/java-tuner
RUN chmod +x /usr/local/bin/java-tuner
ENTRYPOINT ["java-tuner", "--verbose", "--"]
COPY my-app.jar ./
CMD ["java", "-jar", "my-app.jar"]This will:
- Detect resources and generate JVM flags
- Start your Java application (
myapp.jar) with those flags - Pass all arguments after
--to the Java process