Team Spartan Cookies & Milk Forums
  • Issue Tracker
  • Donations
  • Search
  • Member List
  • Help

Register

Team Spartan Cookies & Milk Forums Garry's Mod Starfall v
1 2 3 4 5 … 18 Next »
How to run heavy tasks without reaching quota ?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Threaded Mode
How to run heavy tasks without reaching quota ?
26-01-2025, 11:15 PM,
#1
The17thDoctor Offline
TSCM Average Enjoyer
****
Posts: 1,100
Threads: 249
Joined: Oct 2015
How to run heavy tasks without reaching quota ?
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 ?

The17thDoctor: Server take me to the most handsome person
srcds_linux: I cant send people to themselves...
Website Find
Reply
27-01-2025, 05:11 PM,
#2
Person8880 Offline
gpj.ecafllorT
*******
Posts: 2,407
Threads: 45
Joined: Sep 2013
RE: How to run heavy tasks without reaching quota ?
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.
Find
Reply
27-01-2025, 06:05 PM,
#3
The17thDoctor Offline
TSCM Average Enjoyer
****
Posts: 1,100
Threads: 249
Joined: Oct 2015
RE: How to run heavy tasks without reaching quota ?
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 ?

The17thDoctor: Server take me to the most handsome person
srcds_linux: I cant send people to themselves...
Website Find
Reply
27-01-2025, 06:58 PM,
#4
Person8880 Offline
gpj.ecafllorT
*******
Posts: 2,407
Threads: 45
Joined: Sep 2013
RE: How to run heavy tasks without reaching quota ?
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:
  • Exceeding the maximum burst in a single frame (i.e. cpuTime() becoming too large).
  • Exceeding the time quota on average over a short sliding window (i.e. cpuAverage() exceeding cpuMax()).

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.
Find
Reply
« Next Oldest | Next Newest »


  • View a Printable Version
Forum Jump:


Users browsing this thread: 1 Guest(s)
Contact UsTeam Spartan Cookies & MilkReturn to TopLite (Archive) ModeMark all forums readRSS Syndication

Powered By MyBB, © 2002-2026 MyBB Group.