MCPcopy
hub / github.com/apify/crawlee / evaluateLoadSignalSample

Function evaluateLoadSignalSample

packages/core/src/autoscaling/load_signal.ts:188–215  ·  view source on GitHub ↗
(sample: LoadSnapshot[], overloadedRatio: number)

Source from the content-addressed store, hash-verified

186 * evaluation logic used by `SystemStatus` for all signal types.
187 */
188export function evaluateLoadSignalSample(sample: LoadSnapshot[], overloadedRatio: number): ClientInfo {
189 if (sample.length === 0) {
190 return {
191 isOverloaded: false,
192 limitRatio: overloadedRatio,
193 actualRatio: 0,
194 };
195 }
196
197 const weights: number[] = [];
198 const values: number[] = [];
199
200 for (let i = 1; i < sample.length; i++) {
201 const previous = sample[i - 1];
202 const current = sample[i];
203 const weight = +current.createdAt - +previous.createdAt;
204 weights.push(weight || 1); // Prevent errors from 0ms long intervals (sync) between snapshots.
205 values.push(+current.isOverloaded);
206 }
207
208 const wAvg = sample.length === 1 ? +sample[0].isOverloaded : weightedAvg(values, weights);
209
210 return {
211 isOverloaded: wAvg > overloadedRatio,
212 limitRatio: overloadedRatio,
213 actualRatio: Math.round(wAvg * 1000) / 1000,
214 };
215}

Callers 1

_isSystemIdleMethod · 0.90

Calls 2

weightedAvgFunction · 0.90
pushMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…