![]() |
|
How to run heavy tasks without reaching quota ? - Printable Version +- Team Spartan Cookies & Milk Forums (https://teamscm.co.uk) +-- Forum: Garry's Mod (https://teamscm.co.uk/forum-4.html) +--- Forum: Starfall (https://teamscm.co.uk/forum-7.html) +--- Thread: How to run heavy tasks without reaching quota ? (/thread-3793.html) |
How to run heavy tasks without reaching quota ? - The17thDoctor - 26-01-2025 Since a few years now, I've had starfalls performing load-heavy tasks on people's client and one of the main problem with performing said tasks is to make sure code doesn't exceed quota. The most naïve but relatively reliable approach is to use cpuAverage / cpuMax < threshold% and use that to decide whether an iteration of the heavy task will be able to run. However it's not the best and doesnt take into account other Starfalls that might be running clientside which also take from the client quota. I've been trying to think of smarter approaches to make sure quota won't be reached but I cannot think of any. Are there any alternative ? RE: How to run heavy tasks without reaching quota ? - Person8880 - 27-01-2025 On the client, quota is assigned on a per-player basis, there is no global average quota being tracked. Thus you only have to worry about what cpuMax() and cpuTime() are telling you for the most part. Using cpuAverage() is not an accurate measure as it doesn't update in real-time, it updates once per frame. It can give you an indication of how close you are to triggering the average time check for the chip at the point the current frame started processing, but not beyond that. There's also the burst quota which permits exceeding cpuMax() for a short time which can muddy the tracking slightly. But providing you're keeping below the max the vast majority of the time, you shouldn't hit quota exceeded errors, as the average will stay below the limit. RE: How to run heavy tasks without reaching quota ? - The17thDoctor - 27-01-2025 I suppose this is where I'm having issues as tick-wise, quota can go up to 15000µs in a single tick for my rig (which is quite a performing one) and 30000µs on more "modest" computers. The problem here is that it's either I don't perform the function in which case cpuTime() will be close to 0, or I perform it in which case I reach the values previously mentionned. I suppose if bursts are allowed (up to a certain extent, I believe bursts can't go higher than 100000µs), the average quota is the one determining whether quota is gonna be reached ? RE: How to run heavy tasks without reaching quota ? - Person8880 - 27-01-2025 Bursts are allowed for a few frames at most, up to 100ms in a single frame. The burst slowly regenerates over frames that don't exceed the normal maximum time. You can hit the time quota by either:
In the event of a large spike (I'm assuming it's IMesh:buildFromTriangles()), you'll need to wait for cpuAverage() to settle down before doing anything overly taxing again, plus you'll want to wait for the burst quota to regenerate. There's probably additional information that could be exposed to help calculate the exact time, but waiting a second or two between large spikes should be sufficient as a rough starting point. |