Skip to content

Crawlee—A web scraping and browser automation library for Node.js to build reliable crawlers. In JavaScript and TypeScript. Extract data for AI, LLMs, RAG, or GPTs. Download HTML, PDF, JPG, PNG, and other files from websites. Works with Puppeteer, Playwright, Cheerio, JSDOM, and raw HTTP. Both headful and headless mode. With proxy rotation.

Add support for client error tracking to AutoscaledPool

Ondra Urbaneddf07d62ab3
diff --git a/package.json b/package.json
index ca17a197e..d075c5d87 100644
--- a/package.json
+++ b/package.json
@@ -50,7 +50,7 @@
},
"dependencies": {
"@apify/ps-tree": "^1.1.3",
- "apify-client": "^0.5.0",
+ "apify-client": "^0.5.1",
"apify-shared": "^0.1.11",
"bluebird": "^3.5.3",
"cheerio": "^1.0.0-rc.2",
diff --git a/src/autoscaling/snapshotter.js b/src/autoscaling/snapshotter.js
index e22de68b0..9e1f2323b 100644
--- a/src/autoscaling/snapshotter.js
+++ b/src/autoscaling/snapshotter.js
@@ -3,21 +3,23 @@ import { betterSetInterval, betterClearInterval } from 'apify-shared/utilities';
import log from 'apify-shared/log';
import { ACTOR_EVENT_NAMES, ENV_VARS } from 'apify-shared/consts';
import { checkParamOrThrow } from 'apify-client/build/utils';
-import { getMemoryInfo, isAtHome } from '../utils';
+import { getMemoryInfo, isAtHome, apifyClient } from '../utils';
import events from '../events';
const DEFAULT_OPTIONS = {
eventLoopSnapshotIntervalSecs: 0.5,
maxBlockedMillis: 50, // 0.05
memorySnapshotIntervalSecs: 1,
+ clientSnapshotIntervalSecs: 1,
maxUsedMemoryRatio: 0.7,
snapshotHistorySecs: 30,
+ maxClientErrors: 1,
};
/**
* Creates snapshots of system resources at given intervals and marks the resource
* as either overloaded or not during the last interval. Keeps a history of the snapshots.
- * It tracks the following resources: Memory, EventLoop and CPU.
+ * It tracks the following resources: Memory, EventLoop, API and CPU.
* The class is used by the {@link AutoscaledPool} class.
*
* There are differences in behavior when running locally and on the Apify platform,
@@ -30,6 +32,9 @@ const DEFAULT_OPTIONS = {
*
* Event loop becomes overloaded if it slows down by more than the `maxBlockedMillis` option.
*
+ * Client becomes overloaded when rate limit errors (429 - Too Many Requests),
+ * typically received from the request queue exceed the set limit within the set interval.
+ *
* CPU tracking is available only on the Apify platform and the CPU overloaded event is read
* directly off the container and is not configurable.
*
@@ -37,6 +42,9 @@ const DEFAULT_OPTIONS = {
* via an options object with the following keys:
* @param {Number} [options.eventLoopSnapshotIntervalSecs=0.5]
* Defines the interval of measuring the event loop response time.
+ * @param {Number} [options.clientSnapshotIntervalSecs=1]
+ * Defines the interval of checking the current state
+ * of the remote API client.
* @param {Number} [options.maxBlockedMillis=50]
* Maximum allowed delay of the event loop in milliseconds.
* Exceeding this limit overloads the event loop.
@@ -47,6 +55,9 @@ const DEFAULT_OPTIONS = {
* @param {Number} [options.maxUsedMemoryRatio=0.7]
* Defines the maximum ratio of total memory that can be used.
* Exceeding this limit overloads the memory.
+ * @param {Number} [options.maxClientErrors=1]
+ * Defines the maximum number of new rate limit errors within
+ * the given interval.
* @param {Number} [options.snapshotHistorySecs=60]
* Sets the interval in seconds for which a history of resource snapshots
* will be kept. Increasing this to very high numbers will affect performance.
@@ -56,27 +67,39 @@ class Snapshotter {
const {
eventLoopSnapshotIntervalSecs,
memorySnapshotIntervalSecs,
+ clientSnapshotIntervalSecs,
snapshotHistorySecs,
maxBlockedMillis,
maxUsedMemoryRatio,
+ maxClientErrors,
} = _.defaults({}, options, DEFAULT_OPTIONS);
checkParamOrThrow(eventLoopSnapshotIntervalSecs, 'options.eventLoopSnapshotIntervalSecs', 'Number');
checkParamOrThrow(memorySnapshotIntervalSecs, 'options.memorySnapshotIntervalSecs', 'Number');
checkParamOrThrow(snapshotHistorySecs, 'options.snapshotHistorySecs', 'Number');
+ checkParamOrThrow(clientSnapshotIntervalSecs, 'options.clientSnapshotIntervalSecs', 'Number');
checkParamOrThrow(maxBlockedMillis, 'options.maxBlockedMillis', 'Number');
checkParamOrThrow(maxUsedMemoryRatio, 'options.maxUsedMemoryRatio', 'Number');
+ checkParamOrThrow(maxClientErrors, 'options.maxClientErrors', 'Number');
+
this.eventLoopSnapshotIntervalMillis = eventLoopSnapshotIntervalSecs * 1000;
this.memorySnapshotIntervalMillis = memorySnapshotIntervalSecs * 1000;
+ this.clientSnapshotIntervalMillis = clientSnapshotIntervalSecs * 1000;
this.snapshotHistoryMillis = snapshotHistorySecs * 1000;
this.maxBlockedMillis = maxBlockedMillis;
this.maxUsedMemoryRatio = maxUsedMemoryRatio;
+ this.maxClientErrors = maxClientErrors;
this.maxMemoryBytes = (parseInt(process.env[ENV_VARS.MEMORY_MBYTES], 10) * 1024 * 1024) || null;
this.cpuSnapshots = [];
this.eventLoopSnapshots = [];
this.memorySnapshots = [];
+ this.clientSnapshots = [];
+
+ this.eventLoopInterval = null;
+ this.memoryInterval = null;
+ this.clientInterval = null;
}
/**
@@ -99,6 +122,7 @@ class Snapshotter {
// Start snapshotting.
this.eventLoopInterval = betterSetInterval(this._snapshotEventLoop.bind(this), this.eventLoopSnapshotIntervalMillis);
this.memoryInterval = betterSetInterval(this._snapshotMemory.bind(this), this.memorySnapshotIntervalMillis);
+ this.clientInterval = betterSetInterval(this._snapshotClient.bind(this), this.clientSnapshotIntervalMillis);
events.on(ACTOR_EVENT_NAMES.CPU_INFO, this._snapshotCpu.bind(this));
}
@@ -109,6 +133,7 @@ class Snapshotter {
async stop() {
betterClearInterval(this.eventLoopInterval);
betterClearInterval(this.memoryInterval);
+ betterClearInterval(this.clientInterval);
events.removeListener(ACTOR_EVENT_NAMES.CPU_INFO, this._snapshotCpu);
// Allow microtask queue to unwind before stop returns.
await new Promise(resolve => setImmediate(resolve));
@@ -144,6 +169,16 @@ class Snapshotter {
return this._getSample(this.cpuSnapshots, sampleDurationMillis);
}
+ /**
+ * Returns a sample of latest Client snapshots, with the size of the sample defined
+ * by the sampleDurationMillis parameter. If omitted, it returns a full snapshot history.
+ * @param {Number} sampleDurationMillis
+ * @return {Array}
+ */
+ getClientSample(sampleDurationMillis) {
+ return this._getSample(this.clientSnapshots, sampleDurationMillis);
+ }
+
/**
* Finds the latest snapshots by sampleDurationMillis in the provided array.
* @param {Array} snapshots
@@ -188,7 +223,7 @@ class Snapshotter {
this.memorySnapshots.push(snapshot);
} catch (err) {
- log.exception(err, 'AutoscaledPool: Memory snapshot failed.');
+ log.exception(err, 'Snapshotter: Memory snapshot failed.');
} finally {
intervalCallback();
}
@@ -220,7 +255,7 @@ class Snapshotter {
if (delta > this.maxBlockedMillis) snapshot.isOverloaded = true;
this.eventLoopSnapshots.push(snapshot);
} catch (err) {
- log.exception(err, 'AutoscaledPool: Event loop snapshot failed.');
+ log.exception(err, 'Snapshotter: Event loop snapshot failed.');
} finally {
intervalCallback();
}
@@ -241,6 +276,40 @@ class Snapshotter {
});
}
+ /**
+ * Creates a snapshot of current API state.
+ * @param intervalCallback
+ * @return {number}
+ * @private
+ */
+ _snapshotClient(intervalCallback) {
+ try {
+ const now = new Date();
+ this._pruneSnapshots(this.clientSnapshots, now);
+
+ const currentErrCount = apifyClient.stats.rateLimitErrors;
+
+ // Handle empty snapshots array
+ const snapshot = {
+ createdAt: now,
+ isOverloaded: false,
+ rateLimitErrorCount: currentErrCount,
+ };
+ const previousSnapshot = this.clientSnapshots[this.clientSnapshots.length - 1];
+ if (!previousSnapshot) return this.clientSnapshots.push(snapshot);
+
+ // Compare with previous snapshot
+ const { rateLimitErrorCount } = previousSnapshot;
+ const delta = currentErrCount - rateLimitErrorCount;
+ if (delta > this.maxClientErrors) snapshot.isOverloaded = true;
+ this.clientSnapshots.push(snapshot);
+ } catch (err) {
+ log.exception(err, 'Snapshotter: Client snapshot failed.');
+ } finally {
+ intervalCallback();
+ }
+ }
+
/**
* Removes snapshots that are older than the snapshotHistorySecs option
* from the array (destructively - in place).
diff --git a/src/autoscaling/system_status.js b/src/autoscaling/system_status.js
index c4516742c..6bc84c749 100644
--- a/src/autoscaling/system_status.js
+++ b/src/autoscaling/system_status.js
@@ -8,6 +8,7 @@ const DEFAULT_OPTIONS = {
maxMemoryOverloadedRatio: 0.2,
maxEventLoopOverloadedRatio: 0.2,
maxCpuOverloadedRatio: 0.4,
+ maxClientOverloadedRatio: 0.2,
};
/**
@@ -42,9 +43,12 @@ const DEFAULT_OPTIONS = {
* @param {Number} [options.maxEventLoopOverloadedRatio=0.2]
* Sets the maximum ratio of overloaded snapshots in an event loop sample.
* If the sample exceeds this ratio, the system will be overloaded.
- * @param {Number} [options.maxCpuOverloadedRatio=0.1]
+ * @param {Number} [options.maxCpuOverloadedRatio=0.4]
* Sets the maximum ratio of overloaded snapshots in a CPU sample.
* If the sample exceeds this ratio, the system will be overloaded.
+ * @param {Number} [options.maxClientOverloadedRatio=0.2]
+ * Sets the maximum ratio of overloaded snapshots in a Client sample.
+ * If the sample exceeds this ratio, the system will be overloaded.
*/
class SystemStatus {
constructor(options = {}) {
@@ -53,6 +57,7 @@ class SystemStatus {
maxMemoryOverloadedRatio,
maxEventLoopOverloadedRatio,
maxCpuOverloadedRatio,
+ maxClientOverloadedRatio,
snapshotter,
} = _.defaults({}, options, DEFAULT_OPTIONS);
@@ -60,12 +65,14 @@ class SystemStatus {
checkParamOrThrow(maxMemoryOverloadedRatio, 'options.maxMemoryOverloadedRatio', 'Number');
checkParamOrThrow(maxEventLoopOverloadedRatio, 'options.maxEventLoopOverloadedRatio', 'Number');
checkParamOrThrow(maxCpuOverloadedRatio, 'options.maxCpuOverloadedRatio', 'Number');
+ checkParamOrThrow(maxClientOverloadedRatio, 'options.maxClientOverloadedRatio', 'Number');
checkParamOrThrow(snapshotter, 'options.snapshotter', 'Maybe Object');
this.currentHistorySecs = currentHistorySecs * 1000;
this.maxMemoryOverloadedRatio = maxMemoryOverloadedRatio;
this.maxEventLoopOverloadedRatio = maxEventLoopOverloadedRatio;
this.maxCpuOverloadedRatio = maxCpuOverloadedRatio;
+ this.maxClientOverloadedRatio = maxClientOverloadedRatio;
this.snapshotter = snapshotter || new Snapshotter();
}
@@ -123,17 +130,19 @@ class SystemStatus {
const memInfo = this._isMemoryOverloaded(sampleDurationMillis);
const eventLoopInfo = this._isEventLoopOverloaded(sampleDurationMillis);
const cpuInfo = this._isCpuOverloaded(sampleDurationMillis);
+ const clientInfo = this._isClientOverloaded(sampleDurationMillis);
return {
- isSystemIdle: !memInfo.isOverloaded && !eventLoopInfo.isOverloaded && !cpuInfo.isOverloaded,
+ isSystemIdle: !memInfo.isOverloaded && !eventLoopInfo.isOverloaded && !cpuInfo.isOverloaded && !clientInfo.isOverloaded,
memInfo,
eventLoopInfo,
cpuInfo,
+ clientInfo,
};
}
/**
- * Returns true if the memory has been overloaded
- * in the last sampleDurationMillis.
+ * Returns an object with an isOverloaded property set to true
+ * if the memory has been overloaded in the last sampleDurationMillis.
*
* @param {Number} sampleDurationMillis
* @return {Object}
@@ -145,8 +154,8 @@ class SystemStatus {
}
/**
- * Returns true if the event loop has been overloaded
- * in the last sampleDurationMillis.
+ * Returns an object with an isOverloaded property set to true
+ * if the event loop has been overloaded in the last sampleDurationMillis.
*
* @param {Number} sampleDurationMillis
* @return {Object}
@@ -170,6 +179,18 @@ class SystemStatus {
return this._isSampleOverloaded(sample, this.maxCpuOverloadedRatio);
}
+ /**
+ * Returns an object with an isOverloaded property set to true
+ * if the client has been overloaded in the last sampleDurationMillis.
+ * @param sampleDurationMillis
+ * @return {{isOverloaded, maxOverloadedRatio, actualRatio}}
+ * @private
+ */
+ _isClientOverloaded(sampleDurationMillis) {
+ const sample = this.snapshotter.getClientSample(sampleDurationMillis);
+ return this._isSampleOverloaded(sample, this.maxClientOverloadedRatio);
+ }
+
/**
* Returns an object with sample information and an isOverloaded property
* set to true if at least the ratio of snapshots in the sample are overloaded.
diff --git a/test/autoscaling/snapshotter.js b/test/autoscaling/snapshotter.js
index 1eab41243..358aa8b69 100644
--- a/test/autoscaling/snapshotter.js
+++ b/test/autoscaling/snapshotter.js
@@ -4,6 +4,7 @@ import { ACTOR_EVENT_NAMES, ENV_VARS } from 'apify-shared/consts';
import * as Apify from '../../build/index';
import events from '../../build/events';
import Snapshotter from '../../build/autoscaling/snapshotter';
+import { apifyClient } from '../../build/utils';
// const toBytes = x => x * 1024 * 1024;
@@ -19,13 +20,23 @@ describe('Snapshotter', () => {
});
it('should collect snapshots with some values', async () => {
+ // mock client data
+ const oldStats = apifyClient.stats;
+ apifyClient.stats = {};
+ apifyClient.stats.rateLimitErrors = 0;
+
const snapshotter = new Snapshotter();
await snapshotter.start();
- await Apify.utils.sleep(1250);
+
+ await Apify.utils.sleep(625);
+ apifyClient.stats.rateLimitErrors = 2;
+ await Apify.utils.sleep(625);
+
await snapshotter.stop();
const memorySnapshots = snapshotter.getMemorySample();
const eventLoopSnapshots = snapshotter.getEventLoopSample();
const cpuSnapshots = snapshotter.getCpuSample();
+ const clientSnapshots = snapshotter.getClientSample();
expect(cpuSnapshots).to.be.an('array');
expect(cpuSnapshots).to.have.lengthOf(0);
@@ -49,6 +60,16 @@ describe('Snapshotter', () => {
expect(ss.isOverloaded).to.be.a('boolean');
expect(ss.exceededMillis).to.be.a('number');
});
+
+ expect(clientSnapshots).to.be.an('array');
+ expect(clientSnapshots).to.have.lengthOf(2);
+ clientSnapshots.forEach((ss) => {
+ expect(ss.createdAt).to.be.a('date');
+ expect(ss.isOverloaded).to.be.a('boolean');
+ expect(ss.rateLimitErrorCount).to.be.a('number');
+ });
+
+ apifyClient.stats = oldStats;
});
it('should override default timers', async () => {
@@ -162,7 +183,36 @@ describe('Snapshotter', () => {
});
*/
- it('.get...Sample limits amount of samples', async () => {
+ it('correctly marks clientOverloaded', async () => {
+ // mock client data
+ const oldStats = apifyClient.stats;
+ apifyClient.stats = {};
+ apifyClient.stats.rateLimitErrors = 0;
+
+ const options = {
+ clientSnapshotIntervalSecs: 0.001,
+ };
+
+ const snapshotter = new Snapshotter(options);
+ await snapshotter.start();
+ apifyClient.stats.rateLimitErrors = 1;
+ await Apify.utils.sleep(1);
+ apifyClient.stats.rateLimitErrors = 2;
+ await Apify.utils.sleep(1);
+ apifyClient.stats.rateLimitErrors = 10000;
+ await Apify.utils.sleep(1);
+ await snapshotter.stop();
+ const clientSnapshots = snapshotter.getClientSample();
+
+ expect(clientSnapshots.length).to.be.above(2);
+ expect(clientSnapshots[0].isOverloaded).to.be.eql(false);
+ expect(clientSnapshots[1].isOverloaded).to.be.eql(false);
+ expect(clientSnapshots[clientSnapshots.length - 1].isOverloaded).to.be.eql(true);
+
+ apifyClient.stats = oldStats;
+ });
+
+ it('.get[.*]Sample limits amount of samples', async () => {
const SAMPLE_SIZE_MILLIS = 120;
const options = {
eventLoopSnapshotIntervalSecs: 0.01,
diff --git a/test/autoscaling/system_status.js b/test/autoscaling/system_status.js
index 4f38ff383..e10eeb8b5 100644
--- a/test/autoscaling/system_status.js
+++ b/test/autoscaling/system_status.js
@@ -15,10 +15,11 @@ describe('SystemStatus', () => {
});
class MockSnapshotter {
- constructor(memSnapshots, loopSnapshots, cpuSnapshots) {
+ constructor(memSnapshots, loopSnapshots, cpuSnapshots, clientSnapshots) {
this.memSnapshots = memSnapshots;
this.loopSnapshots = loopSnapshots;
this.cpuSnapshots = cpuSnapshots;
+ this.clientSnapshots = clientSnapshots;
}
getMemorySample(offset) {
@@ -32,6 +33,10 @@ describe('SystemStatus', () => {
getCpuSample(offset) {
return this.cpuSnapshots.slice(-offset);
}
+
+ getClientSample(offset) {
+ return this.clientSnapshots.slice(-offset);
+ }
}
const generateSnapsSync = (percentage, overloaded) => {
@@ -49,7 +54,7 @@ describe('SystemStatus', () => {
it('should return OK for OK snapshots', () => {
const snaps = generateSnapsSync(100, false);
const systemStatus = new SystemStatus({
- snapshotter: new MockSnapshotter(snaps, snaps, snaps),
+ snapshotter: new MockSnapshotter(snaps, snaps, snaps, snaps),
});
expect(systemStatus.getCurrentStatus().isSystemIdle).to.be.eql(true);
expect(systemStatus.getHistoricalStatus().isSystemIdle).to.be.eql(true);
@@ -58,7 +63,7 @@ describe('SystemStatus', () => {
it('should return overloaded for overloaded snapshots', () => {
const snaps = generateSnapsSync(100, true);
const systemStatus = new SystemStatus({
- snapshotter: new MockSnapshotter(snaps, snaps, snaps),
+ snapshotter: new MockSnapshotter(snaps, snaps, snaps, snaps),
});
expect(systemStatus.getCurrentStatus().isSystemIdle).to.be.eql(false);
expect(systemStatus.getHistoricalStatus().isSystemIdle).to.be.eql(false);
@@ -67,22 +72,22 @@ describe('SystemStatus', () => {
it('should work with some samples empty', () => {
const snaps = generateSnapsSync(100, true);
let systemStatus = new SystemStatus({
- snapshotter: new MockSnapshotter(snaps, [], []),
+ snapshotter: new MockSnapshotter(snaps, [], [], []),
});
expect(systemStatus.getCurrentStatus().isSystemIdle).to.be.eql(false);
expect(systemStatus.getHistoricalStatus().isSystemIdle).to.be.eql(false);
systemStatus = new SystemStatus({
- snapshotter: new MockSnapshotter([], snaps, []),
+ snapshotter: new MockSnapshotter([], snaps, [], []),
});
expect(systemStatus.getCurrentStatus().isSystemIdle).to.be.eql(false);
expect(systemStatus.getHistoricalStatus().isSystemIdle).to.be.eql(false);
systemStatus = new SystemStatus({
- snapshotter: new MockSnapshotter([], [], snaps),
+ snapshotter: new MockSnapshotter([], [], snaps, snaps),
});
expect(systemStatus.getCurrentStatus().isSystemIdle).to.be.eql(false);
expect(systemStatus.getHistoricalStatus().isSystemIdle).to.be.eql(false);
systemStatus = new SystemStatus({
- snapshotter: new MockSnapshotter([], [], []),
+ snapshotter: new MockSnapshotter([], [], [], []),
});
expect(systemStatus.getCurrentStatus().isSystemIdle).to.be.eql(true);
expect(systemStatus.getHistoricalStatus().isSystemIdle).to.be.eql(true);
@@ -92,17 +97,22 @@ describe('SystemStatus', () => {
const overloaded = generateSnapsSync(100, true);
const fine = generateSnapsSync(100, false);
let systemStatus = new SystemStatus({
- snapshotter: new MockSnapshotter(fine, fine, overloaded),
+ snapshotter: new MockSnapshotter(fine, fine, overloaded, fine),
});
expect(systemStatus.getCurrentStatus().isSystemIdle).to.be.eql(false);
expect(systemStatus.getHistoricalStatus().isSystemIdle).to.be.eql(false);
systemStatus = new SystemStatus({
- snapshotter: new MockSnapshotter(fine, overloaded, fine),
+ snapshotter: new MockSnapshotter(fine, overloaded, fine, fine),
});
expect(systemStatus.getCurrentStatus().isSystemIdle).to.be.eql(false);
expect(systemStatus.getHistoricalStatus().isSystemIdle).to.be.eql(false);
systemStatus = new SystemStatus({
- snapshotter: new MockSnapshotter(overloaded, fine, fine),
+ snapshotter: new MockSnapshotter(overloaded, fine, fine, fine),
+ });
+ expect(systemStatus.getCurrentStatus().isSystemIdle).to.be.eql(false);
+ expect(systemStatus.getHistoricalStatus().isSystemIdle).to.be.eql(false);
+ systemStatus = new SystemStatus({
+ snapshotter: new MockSnapshotter(fine, fine, fine, overloaded),
});
expect(systemStatus.getCurrentStatus().isSystemIdle).to.be.eql(false);
expect(systemStatus.getHistoricalStatus().isSystemIdle).to.be.eql(false);
@@ -111,29 +121,33 @@ describe('SystemStatus', () => {
it('should overload when threshold is crossed', () => {
const snaps = generateSnapsSync(50, true);
const systemStatus = new SystemStatus({
- snapshotter: new MockSnapshotter(snaps, snaps, snaps),
+ snapshotter: new MockSnapshotter(snaps, snaps, snaps, snaps),
maxMemoryOverloadedRatio: 0.5,
maxEventLoopOverloadedRatio: 0.5,
maxCpuOverloadedRatio: 0.5,
+ maxClientOverloadedRatio: 0.5,
});
expect(systemStatus.getCurrentStatus().isSystemIdle).to.be.eql(true);
expect(systemStatus.getHistoricalStatus().isSystemIdle).to.be.eql(true);
systemStatus.maxMemoryOverloadedRatio = 0.49;
systemStatus.maxEventLoopOverloadedRatio = 0.49;
- systemStatus.maxEventLoopOverloadedRatio = 0.49;
+ systemStatus.maxCpuOverloadedRatio = 0.49;
+ systemStatus.maxClientOverloadedRatio = 0.49;
expect(systemStatus.getCurrentStatus().isSystemIdle).to.be.eql(false);
expect(systemStatus.getHistoricalStatus().isSystemIdle).to.be.eql(false);
systemStatus.maxMemoryOverloadedRatio = 0.5;
systemStatus.maxEventLoopOverloadedRatio = 0.5;
- systemStatus.maxEventLoopOverloadedRatio = 0.49;
+ systemStatus.maxCpuOverloadedRatio = 0.49;
+ systemStatus.maxClientOverloadedRatio = 0.49;
expect(systemStatus.getCurrentStatus().isSystemIdle).to.be.eql(false);
expect(systemStatus.getHistoricalStatus().isSystemIdle).to.be.eql(false);
systemStatus.maxMemoryOverloadedRatio = 1;
systemStatus.maxEventLoopOverloadedRatio = 1;
- systemStatus.maxEventLoopOverloadedRatio = 1;
+ systemStatus.maxCpuOverloadedRatio = 1;
+ systemStatus.maxClientOverloadedRatio = 1;
expect(systemStatus.getCurrentStatus().isSystemIdle).to.be.eql(true);
expect(systemStatus.getHistoricalStatus().isSystemIdle).to.be.eql(true);
});
@@ -141,10 +155,11 @@ describe('SystemStatus', () => {
it('should show different values for now and lately', () => {
let snaps = generateSnapsSync(95, false);
let systemStatus = new SystemStatus({
- snapshotter: new MockSnapshotter(snaps, snaps, snaps),
+ snapshotter: new MockSnapshotter(snaps, snaps, snaps, snaps),
maxMemoryOverloadedRatio: 0.5,
maxEventLoopOverloadedRatio: 0.5,
maxCpuOverloadedRatio: 0.5,
+ maxClientOverloadedRatio: 0.5,
});
systemStatus.currentHistorySecs = 5;
expect(systemStatus.getCurrentStatus().isSystemIdle).to.be.eql(false);
@@ -160,10 +175,11 @@ describe('SystemStatus', () => {
snaps = generateSnapsSync(95, true);
systemStatus = new SystemStatus({
- snapshotter: new MockSnapshotter(snaps, snaps, snaps),
+ snapshotter: new MockSnapshotter(snaps, snaps, snaps, snaps),
maxMemoryOverloadedRatio: 0.5,
maxEventLoopOverloadedRatio: 0.5,
maxCpuOverloadedRatio: 0.5,
+ maxClientOverloadedRatio: 0.5,
});
systemStatus.currentHistorySecs = 5;
expect(systemStatus.getCurrentStatus().isSystemIdle).to.be.eql(true);