Unusual high used-cpu values right at the start of the loop



  • I get some straneg and high used CPU values right at the start of my script. To check it, my main loop looks like this:
    module.exports.loop = function () {
    if (!Memory['colony'].active) {
    console.log('CPU:' + Game.cpu.getUsed() +' Bucket: ' + Game.cpu.bucket);
    return;
    }
    }
    So I'm only accessing memory once, print the getUsed value and return. Even though, the values are not constant at all. 
    When I do a manual JSON.parse(MemoryRaw.get()), I can see, that the deserialization takes about 5CPU, which is about the same as my scripts base cpu load.

    So two questions: Is 5 CPU an ok value for deserialization of 400kb memory? Few days ago, it was at 0.5 cpu for one day Not sure, which of those two values has been the wrong one.
    And then there are those spikes of up to 28CPU. (The script did not restart. If code outside of module.exports.loop would have been executed, this would have resultet in separate console.log. The last time this happened was more than 20 ticks before i captured the following output.
    Remember, that my loop returns immediately after the console.log, so there has been no changes to memory for the duration of that printout.

     

    [23:21:12]
    CPU:7.596775 Bucket: 87
    [23:21:15]
    CPU:4.766738 Bucket: 159
    [23:21:18]
    CPU:4.680823 Bucket: 234
    [23:21:21]
    CPU:9.365896 Bucket: 309
    [23:21:25]
    CPU:7.350569 Bucket: 379
    [23:21:28]
    CPU:4.807187 Bucket: 451
    [23:21:31]
    CPU:7.522593 Bucket: 525
    [23:21:34]
    CPU:7.11024 Bucket: 597
    [23:21:37]
    CPU:4.989253 Bucket: 669
    [23:21:40]
    CPU:20.900664 Bucket: 743
    [23:21:43]
    CPU:7.559229 Bucket: 801
    [23:21:46]
    CPU:21.438833 Bucket: 873
    [23:21:49]
    CPU:4.953994 Bucket: 931
    [23:21:54]
    CPU:7.013379 Bucket: 1005
    [23:21:57]
    CPU:28.783975 Bucket: 1077
    [23:22:00]
    CPU:7.059026 Bucket: 1127
    [23:22:03]
    CPU:4.819619 Bucket: 1199
    [23:22:06]

  • Culture

    400kb is a lot of memory, but it's also going to depend on how many objects you use. I had a bug that threw a ton of empty objects into an array and that caused my JSON parsing to go up quite a bit even though my memory usage itself did not.

    That being said 5cpu doesn't seem unreasonable.



  • @tedvim: It's 350kb now, but yes, there are many small objects.I've made the mistake to use quite long property names, even in memory, maybe I should have avoided that.

    But about the high peak values: Now it has settled down a lot, and high values appear very rarely. But few hours after posting this topic, nearly every fourth tick started at about 20cpu (without a script restart in the last 20 ticks)


  • Culture

    You might be getting hit by the garbage collector. When it runs your script basically pauses, and since there isn't a way for the admins to detect this it raises your cpu usage that tick.



  • GarbaceCollection makes sense.

    As I said, now it settled down a lot. My intuition tells me, that it's worse, the more people are online in the slack-channel. Maybe the more people are working on their scripts and regularly commit them to screeps, the harder the garbage collection hits. However, I don't have any statistics for this, just my intuition.

    But as long as I have an explanation for what it could have been, I'm quite fine with it.