Skip to content

Instantly share code, notes, and snippets.

@blackjack4494
Last active February 6, 2024 06:08
Show Gist options
  • Star 17 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save blackjack4494/63e4e49609e1940a56f69fc095e5bd4f to your computer and use it in GitHub Desktop.
Save blackjack4494/63e4e49609e1940a56f69fc095e5bd4f to your computer and use it in GitHub Desktop.
Palworld Dedicated Server (Linux) limit ram usage & run as systemd service + auto restart

To limit ram usage:

systemd-run --scope -p MemoryMax=4G ./PalServer.sh

Leave at least 1G available under 10G. If you have more than 10G leave 10% for OS.
This assumes you are running nothing else on the server but Palworld.

==== AUTHENTICATING FOR org.freedesktop.systemd1.manage-units ===
Authentication is required to manage system services or other units.
Authenticating as: root
Password:
==== AUTHENTICATION COMPLETE ===
Running scope as unit: run-u121.scope
Shutdown handler: initalize.
Increasing per-process limit of core file size to infinity.
setrlimit() failed with error 22 (Invalid argument)
- Max per-process value allowed is 0 (we wanted infinity).
...

You should have SWAPfile enabled on the server with an appropriate size.
Generally the faster the drive ssd/nvme the better the swap can work.

Some tweaks:
-generous amount of memory

vm.swappiness=10
vm.vfs_cache_pressure=50

-low amount of memory

vm.swappiness=10
vm.vfs_cache_pressure=500

General rule of thumb:
2G Minimum for Base Server
+0.5 to +1G per Player

Lower values are possible but will result in poor performance experience especially the longer the game runs.
Alternatively you can restart the server at set intervals (e.g. daily at 3:00 am).

You can also use a systemd service
sudo nano /etc/systemd/system/palserver.service
simple

[Unit]
Description=Palworld Server
After=network.target

[Service]
Type=simple
User=steam
MemoryMax=12G
ExecStart=/home/steam/Steam/steamapps/common/PalServer/PalServer.sh 
;-useperfthreads -NoAsyncLoadingThread -UseMultithreadForDS

[Install]
WantedBy=multi-user.target

restart - you rather want on-failure

[Unit]
Description=Palworld Server
After=network.target

[Service]
Type=simple
User=steam
Restart=no|always|on-success|on-failure|on-abnormal|on-abort|on-watchdog
RestartSec=30s
MemoryMax=12G
ExecStart=/home/steam/Steam/steamapps/common/PalServer/PalServer.sh 
;-useperfthreads -NoAsyncLoadingThread -UseMultithreadForDS

[Install]
WantedBy=multi-user.target

You can also add RuntimeMaxSec=86400 under [Service] to restart every 24hrs but will require restart to make sense.
But rather use a cronjob for this.

then

sudo systemctl daemon-reload
sudo systemctl enable palserver.service
sudo systemctl start palserver.service
sudo systemctl status palserver.service

can also use

service palserver start|stop|status|restart

-useperfthreads -NoAsyncLoadingThread -UseMultithreadForDS is optional

All options should help against high ram usage and potential crashes.

DO NOT USE!!!
-useperfthreads -NoAsyncLoadingThread -UseMultithreadForDS There seems to be issues with this which will lead to frequent crashes.

@killerwhiteshark
Copy link

The MemoryMax format is wrong. It needs to be in Bytes instead. For me I allocated 28 GB.

MemoryMax=28000000000

@bnlf
Copy link

bnlf commented Jan 29, 2024

The MemoryMax format is wrong. It needs to be in Bytes instead. For me I allocated 28 GB.

MemoryMax=28000000000

K, M, G, T also works. Doens't need to be bytes.

https://www.freedesktop.org/software/systemd/man/latest/systemd.resource-control.html#MemoryMax=bytes

@rehv
Copy link

rehv commented Jan 29, 2024

DO NOT USE!!! -useperfthreads -NoAsyncLoadingThread -UseMultithreadForDS There seems to be issues with this which will lead to frequent crashes.

Hi, is there a source for this? Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment