Headless engine stops calling script update function after some time

I’ve created headless game build with command below:

java -jar bob.jar clean resolve build --platform x86_64-macos --variant headless --settings game_server.settings

And run it with command:

./dmengine_headless

In game I have a script with method update below:

local sleepTime = 0.03 -- 30 ms

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
    --socket.select(nil, nil, tonumber(sleepTime))
    os.execute("sleep " .. tonumber(sleepTime))
  end
  -- checkDataRecievedFromClientSocketAndSendResultBack(dt)
end

So, this update function running for some time and then just stops!
I’ve commented out heavy socket read/write method but it does not help;(

Can someone explain why?

I am using Defold version 1.9.1 because editor with version 1.9.2 just hanging on splash screen on Mac M1 Max;(

PS: Maybe instead of C# it’s better to add Java support?:wink:

I don’t have a good idea, but perhaps the OS doesn’t like the many calls to the external sleep tool?

I seem to remember someone else sharing a native extension which limited the CPU usage of a headless Defold build. I can’t find it now though. Was it maybe @d954mas ?

1 Like

We also readded support for display.update_frequency in Defold 1.9.3 BETA, which is coming out on monday.

1 Like

I’ve removed sleep and added rate limiter, but anyway update stops after some time;(

M.RATE_LIMIT = 1

function M.createRateLimiter(rateLimit)
	local _rateLimit = rateLimit or M.RATE_LIMIT
	local send_cooldown = _rateLimit

	return function (dt)
		send_cooldown = send_cooldown - dt
		if send_cooldown > 0 then
			return true
		else
			send_cooldown = _rateLimit
		end
		return false
	end
end

Perhaps you have a sys log somewhere that let’s you know what the system does with your process?
E.g. check Console app.

I suppose we can blame MacBook M1 Max.

I’ve just created a Docker container and build & run with docker-compose for platform: linux/amd64.

Inside docker with ubuntu image sleep works as expected!

So, thank you everyone!