lloesche / valheim-server-docker

Valheim dedicated gameserver with automatic update, World backup, BepInEx and ValheimPlus mod support
https://hub.docker.com/r/lloesche/valheim-server
Apache License 2.0
1.91k stars 269 forks source link

High idle load - 40-50% of CPU (i9 8700) #626

Closed draconb closed 1 year ago

draconb commented 1 year ago

Hey I've noticed that my server has gotten pretty loud the last few days and realized that even when idle (no one connected) the valheim docker container is using 40-50% or more of the CPU so its constantly under load.

I've checked it with both sudo top and portainer stats and both track it in the 40-50 range constantly.

I'm not sure if a recent valheim update caused an issue or what as I didn't start tracking it until the last few days. I'm using valheim+ grantapher edition

I saw older posts which said you had to frame cap to 30/60 but that was then defaulted on year+ ago, is there still a way to do this manually to see if maybe they broke the fps cap in linux recently?

draconb commented 1 year ago

https://i.imgur.com/qljrlpp.png

There is an example of how its been running. I changed the update_cron to run every 4 hours instead of 15 minutes as I noticed it was in the log a lot. There appears to be a lot of memory usage as well, not sure why its using more and more. let me know how I can help you debug it :)

Here are the logs around that time:

Apr 24 20:00:24 supervisord: valheim-backup INFO - Removing backups older than 3 days

Apr 24 20:00:24 supervisord: valheim-backup /config/backups/worlds-20230421-200009.zip

Apr 24 20:04:53 supervisord: valheim-server 04/24/2023 20:04:53: clone 1114

Apr 24 20:04:53 supervisord: valheim-server 04/24/2023 20:04:53: World save writing starting

Apr 24 20:04:53 supervisord: valheim-server 04/24/2023 20:04:53: World save writing started

Apr 24 20:04:54 supervisord: valheim-server [Info :Valheim Plus] Saved 179568 map points to disk.

Apr 24 20:04:55 supervisord: valheim-server 04/24/2023 20:04:55: Saved 795901 zdos

Apr 24 20:04:55 supervisord: valheim-server 04/24/2023 20:04:55: World save writing finishing

Apr 24 20:04:55 supervisord: valheim-server 04/24/2023 20:04:55: World save writing finished

Apr 24 20:04:55 supervisord: valheim-server 04/24/2023 20:04:55: Considering autobackup. World time: 3591.5, short time: 7200, long time: 43200, backup count: 4

Apr 24 20:04:55 supervisord: valheim-server 04/24/2023 20:04:55: Overwrite our newest autobackup since the second one isn't so old

Apr 24 20:04:55 supervisord: valheim-server 04/24/2023 20:04:55: Replacing backup file: /home/valheim/.config/unity3d/IronGate/Valheim/worlds_local/Draconia_backup_auto-20230424180404.fwl

Apr 24 20:04:55 supervisord: valheim-server 04/24/2023 20:04:55: Saving backup at: /home/valheim/.config/unity3d/IronGate/Valheim/worlds_local/Draconia_backup_auto-20230424200453.fwl

Apr 24 20:04:55 supervisord: valheim-server 04/24/2023 20:04:55: World saved ( 1978.912ms )

Apr 24 20:04:55 supervisord: valheim-server 04/24/2023 20:04:55: Considering autobackup. World time: 3591.54, short time: 7200, long time: 43200, backup count: 4

Apr 24 20:04:55 supervisord: valheim-server 04/24/2023 20:04:55: Overwrite our newest autobackup since the second one isn't so old

Apr 24 20:04:55 supervisord: valheim-server 04/24/2023 20:04:55: Replacing backup file: /home/valheim/.config/unity3d/IronGate/Valheim/worlds_local/Draconia_backup_auto-20230424180404.db

Apr 24 20:04:55 supervisord: valheim-server 04/24/2023 20:04:55: Saving backup at: /home/valheim/.config/unity3d/IronGate/Valheim/worlds_local/Draconia_backup_auto-20230424200453.db

Apr 24 20:04:56 supervisord: valheim-server 04/24/2023 20:04:56: World auto backup saved ( 00:00:00.0898740ms )

Apr 24 20:05:04 supervisord: valheim-server 04/24/2023 20:05:04: Unloading unused assets

Apr 24 20:05:04 supervisord: valheim-server 04/24/2023 20:05:04: Connections 0 ZDOS:795901 sent:0 recv:0

Apr 24 20:05:04 supervisord: valheim-server Unloading 1 Unused Serialized files (Serialized files now loaded: 2)

Apr 24 20:05:05 supervisord: valheim-server Unloading 1 unused Assets to reduce memory usage. Loaded Objects now: 1662293.

Apr 24 20:05:05 supervisord: valheim-server Total: 849.939735 ms (FindLiveObjects: 74.169062 ms CreateObjectMapping: 36.219776 ms MarkObjects: 738.728010 ms DeleteObjects: 0.822487 ms)

Apr 24 20:09:54 supervisord: valheim-server [Info :Valheim Plus] Saved 179568 map points to disk.

Apr 24 20:14:54 supervisord: valheim-server [Info :Valheim Plus] Saved 179568 map points to disk.

lloesche commented 1 year ago

This should probably be reported to the Valheim developers, as this container just executes the Valheim server. Though we've seen this behaviour for years and it's still there, so I suspect there's not much they can or will do about it. We had discussions about building a proxy that would shutdown the server when no players are connected and then spin it back up when someone connects but so far nobody has volunteered the considerable amount of time required to build and maintain this functionality.

ciphersimian commented 1 year ago

I'm not too familiar with the internals of all this, but I suspect this could be accomplished relatively easily by someone who is, using systemd socket activation:

https://blog.developer.atlassian.com/docker-systemd-socket-activation/