Display.update_frequency in Defold 1.9.3 is useless for headless but working solution to limit CPU usage and adjust frequency of update(self, dt) calls is here

Hi there!

I supposed that setting display.update_frequency=5 will call update(self, dt) 5 times per second which should limit CPU usage but it does not!

Actually update(self, dt) called 1 time per second and CPU used about 70-100%. Same behavior I see on setting any number to display.update_frequency except 0 which works as expected!

Working solution to limit CPU usage and adjust frequency of update(self, dt) calls are below:

  1. I added some other params to display and maybe smth. is wrong
-- file: game_server.settings
[display]
width = 1136
height = 640
variable_dt = 0
vsync = 0
swap_interval = 0
frame_cap = 0
update_frequency = 0
-- VPS: Ubuntu 22.04.4 LTS(architecture: amd64)
-- Running headless defold engine(v1.9.3) inside docker container with ubuntu image
-- sleep timeouts:
-- 0.1(100ms): update called 8 times per second
-- 0.05(50ms): update called 17 times per second
-- 0.03(30 ms): update called 28 times per second
-- Without docker updates should be more frequent and CPU usage should be less!
local sleepTime = 0.03

function update(self, dt)
  local current_time = os.date("%Y-%m-%d %H:%M:%S")
  log(current_time, "update", dt)
  if sleepTime > 0 then
    -- this limits CPU usage on VPS
    os.execute("sleep " .. tonumber(sleepTime))
  end
  checkDataRecievedFromClientSocketAndSendResultBack(dt)
end
1 Like

Yeah, this setting is deprecated.
But due to backwards compatibility, we do read it.
So, if it’s present and set to 0, then we disable vsync.

Try removing it or setting it to 1.

If I set vsync=1 then it switch vsync ON for headless build but I suppose it can make some overhead?

There is no actual vsync on headless as we don’t use an actual graphics backend.
So there should be no overhead in that sense.

3 Likes