Skip to content

Commit

Permalink
allow for garbage collection algo preference (#40)
Browse files Browse the repository at this point in the history
* allow for garbage collection algo preference

https://theindiestone.com/forums/index.php?/topic/47417-dedicated-server-on-linux-vps-jre-crashes/

Only way to keep my server stable with 10+ people is to set to G1GC, but there's other java jre gc options

Afaik there's only a few java GC's that'd matter. ZGC is usually best, but G1GC can sometimes be more efficient with it's RAM usage. Probably related to something dumb in either my vm configs or otherwise, but seems like an easy change to allow it to be configurable more generally.

Maybe just adds tech debt to potential future work to deal with #38 and #23 but idk, this is an easy fix for my specific problems.

Signed-off-by: Dylan Shepard <[email protected]>

* readme updates

* updating docker-compose, fixing src/run-server reference

* Update GC Env RegEx pattern;

Signed-off-by: Renegade-Master <[email protected]>

* Add test for new GC;

- .github/workflows/docker-build.yml
  - Add environment configuration for new GC Config option.
  - Add Test for new configuration option.

- README.md
  - Formatting pass.

- docker-compose.yaml
  - Formatting pass.

* Correct GC Config replacement;

* Minor correction;

* Correct sed replacement;

Signed-off-by: Dylan Shepard <[email protected]>
Signed-off-by: Renegade-Master <[email protected]>
Co-authored-by: Renegade-Master <[email protected]>
  • Loading branch information
ryphon and Renegade-Master authored Nov 2, 2022
1 parent 15a676d commit bdb86eb
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 1 deletion.
4 changes: 4 additions & 0 deletions .github/workflows/docker-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ jobs:
--mount type=bind,source="$(pwd)/ZomboidConfig",target=/home/steam/Zomboid \
--env=AUTOSAVE_INTERVAL="16" \
--env=DEFAULT_PORT="25496" \
--env=GC_CONFIG="G1GC" \
--env=MAP_NAMES="BedfordFalls;North;South;West" \
--env=MAX_PLAYERS="14" \
--env=MAX_RAM="6144m" \
Expand All @@ -107,6 +108,7 @@ jobs:
run: |
sed -i "s/AUTOSAVE_INTERVAL=.*\"/AUTOSAVE_INTERVAL=16\"/g" "./docker-compose.yaml"
sed -i "s/DEFAULT_PORT=.*\"/DEFAULT_PORT=25496\"/g" "./docker-compose.yaml"
sed -i "s/GC_CONFIG=.*\"/GC_CONFIG=G1GC\"/g" "./docker-compose.yaml"
sed -i "s/MAP_NAMES=.*\"/MAP_NAMES=BedfordFalls;North;South;West\"/g" "./docker-compose.yaml"
sed -i "s/MAX_PLAYERS=.*\"/MAX_PLAYERS=14\"/g" "./docker-compose.yaml"
sed -i "s/MAX_RAM=.*m\"/MAX_RAM=6144m\"/g" "./docker-compose.yaml"
Expand Down Expand Up @@ -169,6 +171,7 @@ jobs:
--mount type=bind,source="$(pwd)/ZomboidConfig",target=/home/steam/Zomboid \
--env=AUTOSAVE_INTERVAL="16" \
--env=DEFAULT_PORT="25496" \
--env=GC_CONFIG="G1GC" \
--env=MAP_NAMES="BedfordFalls;North;South;West" \
--env=MAX_PLAYERS="14" \
--env=MAX_RAM="6144m" \
Expand Down Expand Up @@ -293,6 +296,7 @@ jobs:
}
check_for_config "\-Xmx6144m"
check_for_config "\-XX:\+UseG1GC"
- name: Test - Server Configuration Applied
run: |
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ recommended for ease of configuration.
| `ADMIN_USERNAME` | Server Admin account username | [a-zA-Z0-9]+ | superuser |
| `BIND_IP` | IP to bind the server to | 0.0.0.0 | 0.0.0.0 |
| `GAME_VERSION` | Game version to serve | [a-zA-Z0-9_]+ | `public` |
| `GC_CONFIG` | Specifices Java GC to use | [a-zA-Z0-9_]+ | ZGC |
| `MAP_NAMES` | Map Names (e.g. North;South) | map1;map2;map3 | Muldraugh, KY |
| `MAX_RAM` | Maximum amount of RAM to be used | ([0-9]+)m | 4096m |
| `STEAM_VAC` | Use Steam VAC anti-cheat | (true&vert;false) | true |
Expand Down Expand Up @@ -214,6 +215,7 @@ The following are instructions for running the server using the Docker image.
[--env=BIND_IP=<value>] \
[--env=GAME_PORT=<value>] \
[--env=GAME_VERSION=<value>] \
[--env=GC_CONFIG=<value>] \
[--env=MAP_NAMES=<value>] \
[--env=MAX_PLAYERS=<value>] \
[--env=MAX_RAM=<value>] \
Expand Down
1 change: 1 addition & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ services:
- "BIND_IP=0.0.0.0"
- "DEFAULT_PORT=16261"
- "GAME_VERSION=public"
- "GC_CONFIG=ZGC"
- "MAP_NAMES=Muldraugh, KY"
- "MAX_PLAYERS=16"
- "MAX_RAM=4096m"
Expand Down
8 changes: 7 additions & 1 deletion src/run_server.sh
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,10 @@ function apply_postinstall_config() {
"$EDIT_CONFIG" "$SERVER_CONFIG" "Password" "$SERVER_PASSWORD"

# Set the maximum amount of RAM for the JVM
sed -i "s/-Xmx.*/-Xmx$MAX_RAM\",/g" "$SERVER_VM_CONFIG"
sed -i "s/-Xmx.*/-Xmx${MAX_RAM}\",/g" "${SERVER_VM_CONFIG}"

# Set the GC for the JVM (advanced, some crashes can be fixed with a different GC algorithm)
sed -i "s/-XX:+Use.*/-XX:+Use${GC_CONFIG}\",/g" "${SERVER_VM_CONFIG}"

printf "\n### Post Install Configuration applied.\n"
}
Expand Down Expand Up @@ -189,6 +192,9 @@ function set_variables() {
# Set the Maximum RAM variable
MAX_RAM=${MAX_RAM:-"4096m"}

# Sets GC
GC_CONFIG=${GC_CONFIG:-"ZGC"}

# Set the Mods to use from workshop
MOD_NAMES=${MOD_NAMES:-""}
MOD_WORKSHOP_IDS=${MOD_WORKSHOP_IDS:-""}
Expand Down

0 comments on commit bdb86eb

Please sign in to comment.