Missing loads of CPU allocation on partially-active shards

  • Bot only receives a fraction of the CPU allocated.


    • main code runs on shard2
    • periodically you send scouts to shard1 and shard3. Roughly 20% of the time at least one scout creep will be on the other shards.

    What I expect to happen:

    If X CPU is allocated to a shard, then I would expect that no matter what the bucket was when a creep left the shard, after 10k/X ticks my bucket is at the maximum level of 10k CPU. E.g. 2 CPU allocated should mean that after 5000 ticks of shard inactivity bucket will be replenished.

    What actually happens:

    When my scout creep leaves the shard, the code stops running, and the bucket is frozen at whatever level it was when the previous scout creep left the shard.

    What makes this even worse:

    When your code stops running on a shard because you have no creeps/buildings, the global is reset. This means that when you next enter the shard the first thing that happens is that global is initialised which takes a substantial amount of CPU. There are no guarantees about global lifetime and it's completely reasonable for the resources held by global to be released if there are no creeps/buildings on the shard. But this interacts very badly with the way that the bucket is not refilled while the shard is not running. You immediately lose a substantial part of the bucket due to the global initialisation, soon after the code stops running while the bucket is depleted, then next thing that happens on that shard is another global initialisation which depletes the bucket even further.

    Log examples:

    2019-02-07 04:09:25 shard1: CPU used: 21.86 avg| 10: 22.31 100: 18.16 1000: 17.25 tick: 15247697 bucket: 500

    My bucket protection code kicks in as the last tick used 26 CPU and pushed the bucket below 500

    2019-02-07 04:09:29 shard1: Skipping tick for your own good - bucket 474

    2 CPU allocated to the shard recharges the bucket by 1 CPU (presumably due to some overhead outside my bot)

    2019-02-07 04:09:32 shard1: Skipping tick for your own good - bucket 475

    Code stops running for half an hour as no creeps or buildings exist on the shard

    After half an hour the code starts running again, the initial tick takes 76 CPU, and the inital bucket is 476, 1 more than it was half an hour ago

    2019-02-07 04:48:39 shard1: finish global_initialise: cpu used= 75.93313199999999

    2019-02-07 04:48:39 shard1: Skipping tick for your own good - bucket 476

    2019-02-07 04:48:42 shard1: Skipping tick for your own good - bucket 396

    Once we get past the automatic bucket protection we see that the code was stopped for about 700 ticks (+100 ticks for bucket regeneration)

    2019-02-07 04:54:37 shard1: tick skipped - we went from 15247697 to 15248502 a jump of 805. bucket is 500

    Because 700 ticks went past, the bucket should have been replenished by 2x700 = 1400 CPU. So the bucket should have started at almost 2000 CPU when the next scout went onto the shard and the code started running again. Instead, in just half an hour 1400 CPU of processing power that should have been assigned to my bot was "stolen".

    What I think the screeps servers should be doing:

    When the code stops running because of no active creeps or buildings, the tick time is saved. When the code is restarted, the current tick time is checked and the bucket is replenished based on the number of ticks since the code was executed.

    If there's a possible exploit in changing the cpu allocated to the shard while the code isn't running, then the allocated cpu could be saved when the code stops running, and the bucket is replenished by the minimum of the current allocated cpu and the saved cpu. This is probably not an issue though, because the cpu allocation can only be changed every 12 hours.


  • Can confirm, I am not receiving the allocated CPU into bucket on inactive shards either.

    My situation:

    1. I have colonies on shard1 and shard3.
    2. I am intermittently sending creeps (trade convoys or attack parties to harass bots) from shard to shard, passing through shard2.The creeps are spending 50 ticks maximum on shard2 (as long as it takes them to pop out of portal, remember who they are, and scamper over to the next portal).
    3. I have allocated 1 CPU to the shard2, and like 98% of the time the shard has no creeps or other owned objects on it and code is not running. I was expecting that extra 1 CPU to go into the bucket and slowly replenish it over time, so I don't have to jump a gazillion hoops and re-assign cpu every time I need a convoy run.

    I am not receiving bucket replenishment from that allocated spare CPU.

  • In the mean-time, would it work to replenish if you just dumped a creep though the portal and assigned them no memory? Depending on how much life it would have when it got there it would be an object that is yours on the shard not taking any actions once its though.

  • hmm wonder what'd happen if someone maintained a stationary scout somewhere in the shard they are passing through and just replaced it before it died? Would the bug still happen?

  • Dev Team

    @stormwing0 scouts would help.

  • Keeping an active room on the shard would also solve the problem.

    I'd be willing to maintain another player's room controller on Shard 2 for a reasonable fee.

  • @o4kapuk Can you check when user last active on shard and just add (ticks since then) times (cpu allocation) to their bucket when they go back to the shard?


  • Dev Team

    @davaned Sounds reasonable, we'll see what we can do.