Palworld Server (Linux) limit ram usage and resolve server lag issues!

When playing games again, you may encounter sudden lag due to a memory leak on the server. This article will provide a method to reduce memory consumption


To limit Palworld Server 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.

Comments