Inconsistent CPU Usage

  • At the moment my CPU usage ranges from 40 to 200+. However, I have the feeling that it heavily depends on the serverload than rather on my script. This feels very unsatisfying, since I have to maintain a rather expensive CPU limit of ~200 while 75% of the time I would be able to run with 150 (or even less) quite easily.

    Anyone else experiencing the same issues?

  • My numbers aren't as high as yours. But I see the same thing. My minimums are around 5-10, average around 30 and max spikes at 100+. But i keep a CPU limit just a bit above the average and I don't see CPU terminations. See if you can set your limit to around the average instead.

  • Well, even with 200 there are spiky times, where I run into TO regularly, while at other times I'm at 110 avg and never even tough the 200. However, since there is no option to 1) get the "real" cpuLimit (=the one you set) and 2) set it accordingly programatically, I feel rather limited.

    The API should look like following:

    Game.cpuLimit => the limit you set (="soft" limit)
    Game.cpuAvailable => the cpu you actually can use per tick
    Game.setCpuLimit(<number>) => sets the limit programatically

  • You might use some expensive operations. For example any pathfinding operation is expensive and if there's no way to target position, it's very expensive, make sure that your creeps don't block each other. Another issue might be related to some advanced JavaScript constructions. I tested for loop vs forEach method and I found that forEach method is much heavier. 'use strict', ES6 let keyword and so on. So you might want to stick with basic JavaScript constructions if you want to squeeze every bit of performance.

    Other than that, I can't say that I observed server load. I played at 20 CPU some time and it was enough for my base. All spikes were caused by pathfinding operations. Probably with 5-10 rooms or fighting mobs I would need more CPU.