Consistently using 1-2 cpu above last Game.cpu.getUsed()


  • int_max

    So I have some code at the end of my main loop that logs my cpu usage, but UI and bucket both show that I use 1-2 cpu more than what my logs show. I know the log isn't to blame because I've put two of them back to back (to measure the usage). I don't think it's Memory parsing either because stringify costs ~0.4cpu.

    Thanks for your help.

    log usage

    UI usage



  • From driver/lib/runtime.js#274 you'll see the getUsedCpu function:

    var getUsedCpu = function () {
                var elapsed = process.hrtime(startTime);
                elapsed = elapsed[0] * 1e3 + elapsed[1] / 1e6 + intents.cpu;
                return elapsed;
            };
    

    but then at line 375 you'll see this:

    outMessage.usedTime = process.hrtime(startTime);
    outMessage.usedTime = Math.ceil(outMessage.usedTime[0] * 1e3 + outMessage.usedTime[1] / 1e6 + intents.cpu);
    
    outMessage.usedDirtyTime = process.hrtime(startDirtyTime);
    outMessage.usedDirtyTime = Math.ceil(outMessage.usedDirtyTime[0] * 1e3 + outMessage.usedDirtyTime[1] / 1e6);
    

    Time is rounded up. That should account for some of the error, at least.


  • Culture

    That's correct warinternal. The getting of elapsed time is also done a tad bit later. This can account for the missing ~0.19 CPU.


  • YP

    I wonder if it would make sense to expose the intents cpu additionally .. would be interesting how much "real" cpu I use .)


  • int_max

    It's rather annoying, I'm trying to limit my stuff when my bucket gets low but I still end up using 10 ( while limiting to 8 )



  • разрабы как вы это прокомментируете? год прошел, а таже херь и ладнобы врал на десятые, но в конце цикла гетюзед=15 а желтая фигня грит аж 24!



  • Are you know that you pay for serialization your memory? Try to do JSON.stringify(Memory) and you'll know about how much. So when you try to get used CPU at the end of tick this is not the same CPU that used your AI, because you will not take account of the CPU to serialization memory.

    For example to serialization my memory needs about 18 CPU. You can perform let cpu = Game.cpu.getUsed();JSON.stringify(Memory);console.log(Game.cpu.getUsed()-cpu) in the game console to check it.



  • @flyasd1 said in Consistently using 1-2 cpu above last Game.cpu.getUsed():

    JSON.stringify

    I did not know this, thank you.


  • Dev Team

    Also, please keep in mind that expenses of garbage collection performed against a player's heap will be paid from the player's bucket.