CPU usage and inconsistency



  • I'm seeing some strange and inconsistent numbers in my CPU usage.

    I have an array that pushes periodic values to Game.getUsedCpu() out to it.

    For some reason, the two lines below use anywhere between .5 and 7 CPU to perform. And i'm unsure how a simple variable definition can do that.

    Additionally, over the night (where my script has been running with no changes for 10 hours) I have seen a drastic increase in CPU usage. I used to be 4/5 times below my 20 cPU limit, now i'm only under it 2/5 times and seeing regular cpu errors.

    The beforementioned Lines:
    var claimer = require('claimer');
    var Roomcode = require('Roomcode');

    I'm not sure if the require mehtod is supposed to take a ton of CPU. But it certainly is.

    Has anyone else seen a change like this?



  • In talking to other players, they have also verified that the require command is taking large amounts of CPU in an inconsistent basis. sometimes as much as 20-30 CPU for a single require for a 20 line code.

    Considering that this isn't just on my account, and that overnight since yesterday, my average CPU usage per tick has risen from 20 to 35, there is something going wrong with the server side.

    Would appreciate some acknowledgement of the issue, and some confirmation from other players.



  • As far as I know (I am not an expert on how io.js handles require), require uses a synchronous file system fetch to load in the resource. As a result, if the hardware that the instance of io.js is running on is taking a long time to find the file, or if it is busy doing someone else's loading (most PAAS providers run multiple VMs on a single piece of hardware), then the script will block and wait for the data to come in. I assume that the CPU timer would continue to run during this time and as a result the amount of time wasted on loading the script could vary on things outside of anyone's control.

    The only way I can think of circumnavigating this problem is to not use require. Perhaps as a community we need to develop a Travis script that will go through all the files, replace any require calls with the code that they would fetch, and then push the modified files to the screeps api. That way, the hardware issues would not be reoccurring cost faced by the scripts, and instead would only be paid once during build time.