Thursday, 8 May 2025

Releasing unused but committed Heap memory

As mentioned in the references below, with some commandline arguments to the JVM, you can force periodic Garbage Collection cycles when on low load to reclaim memory that isn't used (because it's not doing anything).

This comes in handy when using containers, where committed unused memory in the node just costs money.

The application is considered inactive, and G1 triggers a periodic garbage collection if the following conditions hold:

G1PeriodicGCInterval
number of milliseconds have passed since any previous garbage collection pause and there is no concurrent cycle in progress at this point. A value of zero indicates that periodic garbage collections to promptly reclaim memory are disabled.
G1PeriodicGCSystemLoadThreshold
The average one-minute system load value as returned by the getloadavg() call on the JVM host system (e.g. container) is below this value. A value of zero means this is ignored.

As an example:

java -server -XX:+UnlockExperimentalVMOptions -XX:+UseStringDeduplication -XX:+UseG1GC \
-XX:G1PeriodicGCInterval=30000 -XX:G1PeriodicGCSystemLoadThreshold=0.5 \
-Xmaxf0.3 -Xminf0.1 -Xmx2048M -Xms32M \
-jar ../releases/mrbear.war

This example would indicate that every 30 seconds, if the average system load is below 0.5, a Garbage Collection cycle may be initiated to reclaim memory.

Java Agent

In the past Virtuozzo, which I used, had to put in a java-agent in the command line to have the same functionality. So this is no longer necessary.

Progress!

References

Virtuozzo - Elastic JVM with Automatic Vertical Memory Scaling
https://www.virtuozzo.com/company/blog/elastic-jvm-vertical-scaling/
JEP 346: Promptly Return Unused Committed Memory from G1
https://openjdk.org/jeps/346

Thursday, 1 May 2025

Links related to VoxxedDays Amsterdam

I had some links to useful websites that I needed to put somewhere.

Apache Calcite

It seems to be a kind of proxy that you can put between your application and your data layer. It allows for data manipulations, for example using SQL, and your data layer can be anything (and frequently is). If there's an Adapter for it, you can connect Calcite to your data thing. If there isn't you have to write your own adapter.

https://calcite.apache.org/

Cursor - The AI Code Editor

What it says on the box.

https://www.cursor.com/

Micrometer

A system to check what your software is doing (in the field).

https://micrometer.io/

Github - Oracle - graalvm-reachability-metadata

Find out if there's support for certain frameworks in the GraalVM for Native using this list.

https://github.com/oracle/graalvm-reachability-metadata

Baeldun - Code Snippets in Java API Documentation

Besides Markdown syntax in JavaDoc in the new versions of Java, it is also possible to add code snippets to your javadoc.

I think it's interesting. It would for example be a good idea to add a code snippet in the JavaDoc that refers to a specific Class in your testset.

https://www.baeldung.com/java-doc-code-snippets

GitLab - BeyondxScratch - hexagonal-architecture-java-springboot

There was a talk about hexagonal architecture, that I seem to have seen before.

https://gitlab.com/beyondxscratch/hexagonal-architecture-java-springboot

StarWars REST API

An interesting little website that can provide REST services about the Star Wars films. If you want to quickly test some REST responses. (Their certificate seems to have expired though)

Coolify - Self-hosting with superpowers.

What is says on the box. Easily selfhosting a cloud environment.

https://coolify.io

Cheap dedicated servers, cloud & hosting from Germany

Kind of an standard hosting company, but they seems to have Server Auctions? Buy some cloud with refurbished hardware, is basically the idea. I thought that was interesting.

https://www.hetzner.com/