Page 1 of 1

[Twinsen] [0.13.10] Headless mode (--start-server) causes 100% cpu

Posted: Sat Jul 23, 2016 1:47 am
by daniel34
When starting a headless server on Linux or Windows the cpu consumption goes to 100% on one core/thread and stays there.
This does already happen directly after starting the server, without any clients connected. It's staying at 100% while connecting/downloading map and playing and never goes down.
Does not happen when hosting a multiplayer game using the GUI interface on Windows.

Code: Select all

top - 03:44:34 up 12 min,  2 users,  load average: 1.00, 0.90, 0.52
Tasks:  87 total,   2 running,  85 sleeping,   0 stopped,   0 zombie
%Cpu(s): 10.9 us, 14.1 sy,  0.0 ni, 75.0 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
KiB Mem:   4047304 total,   234672 used,  3812632 free,     7788 buffers
KiB Swap:  2094076 total,        0 used,  2094076 free.    56040 cached Mem

   PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND
   456 root      20   0  286684  91916  13328 R 100.1  2.3  11:17.69 factorio
   476 root      20   0   23520   2768   2364 R   0.3  0.1   0:00.02 top
     1 root      20   0   28640   4508   2904 S   0.0  0.1   0:01.34 systemd
     2 root      20   0       0      0      0 S   0.0  0.0   0:00.00 kthreadd

Re: [0.13.10] Headless mode (--start-server) causes 100% cpu

Posted: Sat Jul 23, 2016 2:16 am
by Megapants
I'm having the same issue:
Image

In the previous release (0.13.9) it was hovering around 35% with two people connected. Updated an hour ago and it's been 99.9% since with no one connected.

It's running on a 1GB DigitalOcean VPS with Ubuntu 14.04.4 LTS. No mods installed.

Using this to start the process:

Code: Select all

/opt/factorio/bin/x64/factorio --start-server /opt/factorio/data/saves/save-name.zip --latency-ms 60 --allow-commands=false --server-settings /opt/factorio/data/server-settings.json

Re: [0.13.10] Headless mode (--start-server) causes 100% cpu

Posted: Sat Jul 23, 2016 4:43 pm
by Klonan
Thanks for the reports,

I just tried loading a simple map as a server, and it was using all of the CPU it can, which i think pretty much confirms it

Re: [0.13.10] Headless mode (--start-server) causes 100% cpu

Posted: Mon Jul 25, 2016 8:58 am
by Rseding91
I'm pretty sure this is by design but Twinsen will need to confirm.

We changed our main loop implementation from a "sleep when needed" to "busy wait when needed" because sleep in programming is not accurate enough to wake up on time.

Re: [Twinsen] [0.13.10] Headless mode (--start-server) causes 100% cpu

Posted: Mon Jul 25, 2016 9:29 am
by Twinsen
This is indeed a side effect of the new main loop logic. It does not exactly busy wait, but rather tries to do updates as precise as possible without sleeping.

I'll probably need to write a different main loop for the headless mode. This is rather low priority now.

Re: [Twinsen] [0.13.10] Headless mode (--start-server) causes 100% cpu

Posted: Tue Jul 26, 2016 12:58 pm
by Oxyd
Fixed in 0.13.12.

Re: [Twinsen] [0.13.10] Headless mode (--start-server) causes 100% cpu

Posted: Tue Jul 26, 2016 1:02 pm
by Megapants
Great, I'll give it a try now.

Re: [Twinsen] [0.13.10] Headless mode (--start-server) causes 100% cpu

Posted: Tue Jul 26, 2016 1:05 pm
by Oxyd
Uh, sorry. I meant 0.13.12. The fix isn't released yet.

Re: [Twinsen] [0.13.10] Headless mode (--start-server) causes 100% cpu

Posted: Tue Jul 26, 2016 1:38 pm
by Megapants
Ah, alright. Thanks for looking into it.