sureshg / openjdk-playground

:coffee: A sample repo to test the latest OpenJDK releases for both Java and Kotlin.

Home Page:https://suresh.dev/notes

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Module OpenJDK PlayGround

WorksWithOpenJDK

GitHub Workflow Status OpenJDK Version Kotlin release Docker Image Style guide SonarCloud CloudRun

Install OpenJDK

$ curl -s "https://get.sdkman.io" | bash
$ sdk i java openjdk-ea-23

Build

$ ./gradlew build

# Lint Github Actions
$ brew install actionlint
$ actionlint

Run the App

$ java -jar \
       --enable-preview \
       --add-modules=ALL-SYSTEM \
       -XX:+UseZGC -XX:+ZGenerational \
       build/libs/openjdk-playground-*-uber.jar

# Show all pinned virtual threads
$ jfr print --events jdk.VirtualThreadPinned openjdk-playground.jfr

# Show all socket events
$ jfr print --stack-depth 100 --events jdk.Socket\* openjdk-playground.jfr

# Virtual thread dump
$ jcmd dev.suresh.Main Thread.dump_to_file -format=json openjdk-playground-threads.json

Run using OpenJDK Image

$ docker run \
        -it \
        --rm \
        --pull always \
        --workdir /app \
        --publish 8000:8000 \
        --name openjdk-playground \
        --mount type=bind,source=$(pwd),destination=/app,readonly \
        openjdk:23-slim /bin/bash -c "./build/openjdk-playground && printenv && jwebserver -b 0.0.0.0 -p 8000 -d /"

# Download the JFR files
$ wget http://localhost:8000/tmp/openjdk-playground.jfr

# Build the container image
$ ./gradlew jibDockerBuild
$ docker run -it --rm --name openjdk-playground sureshg/openjdk-playground

SBOM and Vulnerability Scan

$ ./gradlew cyclonedxBom

$ osv-scanner --sbom=build/sbom/bom.json
# OR use https://bomdoctor.sonatype.com/

Load testing the Web Server

  • Check if the service is up and running!

    $ curl -v -k https://localhost:8443
  • Set the os ulimit for Vegeta

    $ ulimit -n 4096 // FD limit
    $ ulimit -u 1024 // processes limit
  • Run with kernel threads.

    $ echo "GET https://127.0.0.1:8443/" | vegeta attack -insecure -duration=10s -name=Threads -rate=250 | tee thread-results.bin | vegeta report
    $ vegeta report -type=json thread-results.bin > thread-metrics.json
    $ cat thread-results.bin | vegeta report -type="hist[0,100ms,200ms,300ms]"
    $ cat thread-results.bin | vegeta plot -title "Normal Threads" > plot.html && open plot.html
  • Run with Virtual threads.

    $ echo "GET https://127.0.0.1:8443/" | vegeta attack -insecure -duration=10s -name=VirtualThreads -rate=250 | tee vthread-results.bin | vegeta report
    $ vegeta report -type=json vthread-results.bin > vthread-metrics.json
    $ cat vthread-results.bin | vegeta report -type="hist[0,100ms,200ms,300ms]"
    $ cat vthread-results.bin | vegeta plot -title "Virtual Threads" > plot.html && open plot.html
  • Combine the results and plot a single graph.

    $ vegeta plot -title "Threads vs Virtual Threads"  vthread-results.bin thread-results.bin > plot.html && open plot.html

Troubleshooting

Commands
# Check the current version
$ ./gradlew -q --console plain version

# Publish to local repository
$ ./gradlew publishMavenPublicationToLocalRepository

# Stop Gradle and Kotlin daemon
$ ./gradlew --stop && pkill -f KotlinCompileDaemon

# Runs all checks
$ ./gradlew clean check

# Check tasks dependencies
$ ./gradlew clean build --dry-run

# Dep version updates
$ ./gradlew clean dependencyUpdates

# List all available toolchains
$ ./gradlew -q javaToolchains
Resources

About

:coffee: A sample repo to test the latest OpenJDK releases for both Java and Kotlin.

https://suresh.dev/notes

License:Apache License 2.0


Languages

Language:Kotlin 69.7%Language:Java 22.3%Language:Shell 7.4%Language:HTML 0.5%Language:C 0.1%