itzg / itzg/docker-minecraft-server

Force GC on auto-pause to save RAM

Open
#2,687 7 comments 1 reaction 0 assignees View on GitHub
enhancement
Dominant language
Shell
Stars
14.3k
Forks
1.9k
Avg merge
2d 10h
Merged PRs (30d)
31

Description

## Problem

Auto-pause, despite saving the CPU power, does little to curb the rather enormous RAM usage a Minecraft server, especially with Forge, can impose on the system, being rather problematic for installations where Minecraft lives alongside other services like a home server. Auto-shutdown may seem like a solution, but as far as I can see, it doesn't support automatic startup on new network connections like auto-pause, so isn't considered a viable alternative.

## Proposed solution

I propose to amend this feature by forcing the JVM to perform a garbage collection before pausing. One way I found of achieving it would look something like

```sh
jcmd $(jps -l | grep forge-1.12.2-14.23.5.2860.jar | awk '{print $1}') GC.run
```

which would require the following options for the JVM to enable debugging

```
-Dcom.sun.management.jmxremote
-Dcom.sun.management.jmxremote.port=9010
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.ssl=false
```

Perhaps there is a better implementation, but this serves as illustration for my proposal. This simple feature may make a great difference for many RAM-scarce homelabs.

## Alternatives considered

- Network-based auto-startup paired with existing auto-shutdown, like https://github.com/gekware/minecraft-server-hibernation.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by locating the auto-pause entry point and reviewing how the Minecraft server process is paused. Compare the proposed jcmd/jps/awk command with the listed JMX JVM options; done means auto-pause can trigger garbage collection reliably without breaking automatic resume.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, shell
Domain
backend, devops
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.