@crawlee/core 3.16.1-beta.34 → 3.16.1-beta.35
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/autoscaling/autoscaled_pool.d.ts +2 -0
- package/autoscaling/autoscaled_pool.d.ts.map +1 -1
- package/autoscaling/autoscaled_pool.js +10 -0
- package/autoscaling/autoscaled_pool.js.map +1 -1
- package/autoscaling/client_load_signal.d.ts +26 -0
- package/autoscaling/client_load_signal.d.ts.map +1 -0
- package/autoscaling/client_load_signal.js +40 -0
- package/autoscaling/client_load_signal.js.map +1 -0
- package/autoscaling/cpu_load_signal.d.ts +29 -0
- package/autoscaling/cpu_load_signal.d.ts.map +1 -0
- package/autoscaling/cpu_load_signal.js +27 -0
- package/autoscaling/cpu_load_signal.js.map +1 -0
- package/autoscaling/event_loop_load_signal.d.ts +24 -0
- package/autoscaling/event_loop_load_signal.d.ts.map +1 -0
- package/autoscaling/event_loop_load_signal.js +39 -0
- package/autoscaling/event_loop_load_signal.js.map +1 -0
- package/autoscaling/index.d.ts +5 -0
- package/autoscaling/index.d.ts.map +1 -1
- package/autoscaling/index.js +5 -0
- package/autoscaling/index.js.map +1 -1
- package/autoscaling/load_signal.d.ts +100 -0
- package/autoscaling/load_signal.d.ts.map +1 -0
- package/autoscaling/load_signal.js +151 -0
- package/autoscaling/load_signal.js.map +1 -0
- package/autoscaling/memory_load_signal.d.ts +44 -0
- package/autoscaling/memory_load_signal.d.ts.map +1 -0
- package/autoscaling/memory_load_signal.js +159 -0
- package/autoscaling/memory_load_signal.js.map +1 -0
- package/autoscaling/snapshotter.d.ts +27 -63
- package/autoscaling/snapshotter.d.ts.map +1 -1
- package/autoscaling/snapshotter.js +77 -243
- package/autoscaling/snapshotter.js.map +1 -1
- package/autoscaling/system_status.d.ts +20 -32
- package/autoscaling/system_status.d.ts.map +1 -1
- package/autoscaling/system_status.js +46 -92
- package/autoscaling/system_status.js.map +1 -1
- package/index.mjs +6 -0
- package/package.json +5 -5
|
@@ -2,9 +2,11 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.SystemStatus = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
-
const utils_1 = require("@crawlee/utils");
|
|
6
5
|
const ow_1 = tslib_1.__importDefault(require("ow"));
|
|
6
|
+
const load_signal_1 = require("./load_signal");
|
|
7
7
|
const snapshotter_1 = require("./snapshotter");
|
|
8
|
+
/** The four built-in signal names that map to typed `SystemInfo` fields. */
|
|
9
|
+
const BUILTIN_SIGNAL_NAMES = new Set(['memInfo', 'eventLoopInfo', 'cpuInfo', 'clientInfo']);
|
|
8
10
|
/**
|
|
9
11
|
* Provides a simple interface to reading system status from a {@link Snapshotter} instance.
|
|
10
12
|
* It only exposes two functions {@link SystemStatus.getCurrentStatus}
|
|
@@ -35,31 +37,24 @@ class SystemStatus {
|
|
|
35
37
|
writable: true,
|
|
36
38
|
value: void 0
|
|
37
39
|
});
|
|
38
|
-
Object.defineProperty(this, "
|
|
39
|
-
enumerable: true,
|
|
40
|
-
configurable: true,
|
|
41
|
-
writable: true,
|
|
42
|
-
value: void 0
|
|
43
|
-
});
|
|
44
|
-
Object.defineProperty(this, "maxEventLoopOverloadedRatio", {
|
|
45
|
-
enumerable: true,
|
|
46
|
-
configurable: true,
|
|
47
|
-
writable: true,
|
|
48
|
-
value: void 0
|
|
49
|
-
});
|
|
50
|
-
Object.defineProperty(this, "maxCpuOverloadedRatio", {
|
|
40
|
+
Object.defineProperty(this, "snapshotter", {
|
|
51
41
|
enumerable: true,
|
|
52
42
|
configurable: true,
|
|
53
43
|
writable: true,
|
|
54
44
|
value: void 0
|
|
55
45
|
});
|
|
56
|
-
Object.defineProperty(this, "
|
|
46
|
+
Object.defineProperty(this, "signals", {
|
|
57
47
|
enumerable: true,
|
|
58
48
|
configurable: true,
|
|
59
49
|
writable: true,
|
|
60
50
|
value: void 0
|
|
61
51
|
});
|
|
62
|
-
|
|
52
|
+
/**
|
|
53
|
+
* Per-signal ratio overrides. The built-in four get their overrides from
|
|
54
|
+
* the legacy `max*OverloadedRatio` options; custom signals use their own
|
|
55
|
+
* `overloadedRatio`.
|
|
56
|
+
*/
|
|
57
|
+
Object.defineProperty(this, "ratioOverrides", {
|
|
63
58
|
enumerable: true,
|
|
64
59
|
configurable: true,
|
|
65
60
|
writable: true,
|
|
@@ -72,15 +67,21 @@ class SystemStatus {
|
|
|
72
67
|
maxCpuOverloadedRatio: ow_1.default.optional.number,
|
|
73
68
|
maxClientOverloadedRatio: ow_1.default.optional.number,
|
|
74
69
|
snapshotter: ow_1.default.optional.object,
|
|
70
|
+
loadSignals: ow_1.default.optional.array,
|
|
75
71
|
config: ow_1.default.optional.object,
|
|
76
72
|
}));
|
|
77
|
-
const { currentHistorySecs = 5, maxMemoryOverloadedRatio = 0.2, maxEventLoopOverloadedRatio = 0.6, maxCpuOverloadedRatio = 0.4, maxClientOverloadedRatio = 0.3, snapshotter, config, } = options;
|
|
73
|
+
const { currentHistorySecs = 5, maxMemoryOverloadedRatio = 0.2, maxEventLoopOverloadedRatio = 0.6, maxCpuOverloadedRatio = 0.4, maxClientOverloadedRatio = 0.3, snapshotter, loadSignals = [], config, } = options;
|
|
78
74
|
this.currentHistoryMillis = currentHistorySecs * 1000;
|
|
79
|
-
this.maxMemoryOverloadedRatio = maxMemoryOverloadedRatio;
|
|
80
|
-
this.maxEventLoopOverloadedRatio = maxEventLoopOverloadedRatio;
|
|
81
|
-
this.maxCpuOverloadedRatio = maxCpuOverloadedRatio;
|
|
82
|
-
this.maxClientOverloadedRatio = maxClientOverloadedRatio;
|
|
83
75
|
this.snapshotter = snapshotter || new snapshotter_1.Snapshotter({ config });
|
|
76
|
+
// Built-in signals from the snapshotter + any custom signals
|
|
77
|
+
this.signals = [...this.snapshotter.getLoadSignals(), ...loadSignals];
|
|
78
|
+
// Allow legacy options to override the built-in signal ratios
|
|
79
|
+
this.ratioOverrides = {
|
|
80
|
+
memInfo: maxMemoryOverloadedRatio,
|
|
81
|
+
eventLoopInfo: maxEventLoopOverloadedRatio,
|
|
82
|
+
cpuInfo: maxCpuOverloadedRatio,
|
|
83
|
+
clientInfo: maxClientOverloadedRatio,
|
|
84
|
+
};
|
|
84
85
|
}
|
|
85
86
|
/**
|
|
86
87
|
* Returns an {@link SystemInfo} object with the following structure:
|
|
@@ -124,80 +125,33 @@ class SystemStatus {
|
|
|
124
125
|
* Returns a system status object.
|
|
125
126
|
*/
|
|
126
127
|
_isSystemIdle(sampleDurationMillis) {
|
|
127
|
-
const
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
!eventLoopInfo.isOverloaded &&
|
|
134
|
-
!cpuInfo.isOverloaded &&
|
|
135
|
-
!clientInfo.isOverloaded,
|
|
136
|
-
memInfo,
|
|
137
|
-
eventLoopInfo,
|
|
138
|
-
cpuInfo,
|
|
139
|
-
clientInfo,
|
|
128
|
+
const result = {
|
|
129
|
+
isSystemIdle: true,
|
|
130
|
+
memInfo: { isOverloaded: false, limitRatio: 0, actualRatio: 0 },
|
|
131
|
+
eventLoopInfo: { isOverloaded: false, limitRatio: 0, actualRatio: 0 },
|
|
132
|
+
cpuInfo: { isOverloaded: false, limitRatio: 0, actualRatio: 0 },
|
|
133
|
+
clientInfo: { isOverloaded: false, limitRatio: 0, actualRatio: 0 },
|
|
140
134
|
};
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
return this._isSampleOverloaded(sample, this.maxEventLoopOverloadedRatio);
|
|
157
|
-
}
|
|
158
|
-
/**
|
|
159
|
-
* Returns an object with an isOverloaded property set to true
|
|
160
|
-
* if the CPU has been overloaded in the last sampleDurationMillis.
|
|
161
|
-
*/
|
|
162
|
-
_isCpuOverloaded(sampleDurationMillis) {
|
|
163
|
-
const sample = this.snapshotter.getCpuSample(sampleDurationMillis);
|
|
164
|
-
return this._isSampleOverloaded(sample, this.maxCpuOverloadedRatio);
|
|
165
|
-
}
|
|
166
|
-
/**
|
|
167
|
-
* Returns an object with an isOverloaded property set to true
|
|
168
|
-
* if the client has been overloaded in the last sampleDurationMillis.
|
|
169
|
-
*/
|
|
170
|
-
_isClientOverloaded(sampleDurationMillis) {
|
|
171
|
-
const sample = this.snapshotter.getClientSample(sampleDurationMillis);
|
|
172
|
-
return this._isSampleOverloaded(sample, this.maxClientOverloadedRatio);
|
|
173
|
-
}
|
|
174
|
-
/**
|
|
175
|
-
* Returns an object with sample information and an isOverloaded property
|
|
176
|
-
* set to true if at least the ratio of snapshots in the sample are overloaded.
|
|
177
|
-
*/
|
|
178
|
-
_isSampleOverloaded(sample, ratio) {
|
|
179
|
-
if (sample.length === 0) {
|
|
180
|
-
return {
|
|
181
|
-
isOverloaded: false,
|
|
182
|
-
limitRatio: ratio,
|
|
183
|
-
actualRatio: 0,
|
|
184
|
-
};
|
|
135
|
+
let loadSignalInfo;
|
|
136
|
+
for (const signal of this.signals) {
|
|
137
|
+
const ratio = this.ratioOverrides[signal.name] ?? signal.overloadedRatio;
|
|
138
|
+
const sample = signal.getSample(sampleDurationMillis);
|
|
139
|
+
const info = (0, load_signal_1.evaluateLoadSignalSample)(sample, ratio);
|
|
140
|
+
if (info.isOverloaded) {
|
|
141
|
+
result.isSystemIdle = false;
|
|
142
|
+
}
|
|
143
|
+
if (BUILTIN_SIGNAL_NAMES.has(signal.name)) {
|
|
144
|
+
result[signal.name] = info;
|
|
145
|
+
}
|
|
146
|
+
else {
|
|
147
|
+
loadSignalInfo ?? (loadSignalInfo = {});
|
|
148
|
+
loadSignalInfo[signal.name] = info;
|
|
149
|
+
}
|
|
185
150
|
}
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
for (let i = 1; i < sample.length; i++) {
|
|
189
|
-
const previous = sample[i - 1];
|
|
190
|
-
const current = sample[i];
|
|
191
|
-
const weight = +current.createdAt - +previous.createdAt;
|
|
192
|
-
weights.push(weight || 1); // Prevent errors from 0ms long intervals (sync) between snapshots.
|
|
193
|
-
values.push(+current.isOverloaded);
|
|
151
|
+
if (loadSignalInfo) {
|
|
152
|
+
result.loadSignalInfo = loadSignalInfo;
|
|
194
153
|
}
|
|
195
|
-
|
|
196
|
-
return {
|
|
197
|
-
isOverloaded: wAvg > ratio,
|
|
198
|
-
limitRatio: ratio,
|
|
199
|
-
actualRatio: Math.round(wAvg * 1000) / 1000,
|
|
200
|
-
};
|
|
154
|
+
return result;
|
|
201
155
|
}
|
|
202
156
|
}
|
|
203
157
|
exports.SystemStatus = SystemStatus;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"system_status.js","sourceRoot":"","sources":["../../src/autoscaling/system_status.ts"],"names":[],"mappings":";;;;AAAA,
|
|
1
|
+
{"version":3,"file":"system_status.js","sourceRoot":"","sources":["../../src/autoscaling/system_status.ts"],"names":[],"mappings":";;;;AAAA,oDAAoB;AAIpB,+CAAyD;AACzD,+CAA4C;AA4G5C,4EAA4E;AAC5E,MAAM,oBAAoB,GAAG,IAAI,GAAG,CAAC,CAAC,SAAS,EAAE,eAAe,EAAE,SAAS,EAAE,YAAY,CAAC,CAAC,CAAC;AAE5F;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAa,YAAY;IAYrB,YAAY,UAA+B,EAAE;QAX5B;;;;;WAA6B;QAC7B;;;;;WAAyB;QACzB;;;;;WAAsB;QAEvC;;;;WAIG;QACK;;;;;WAAuC;QAG3C,IAAA,YAAE,EACE,OAAO,EACP,YAAE,CAAC,MAAM,CAAC,UAAU,CAAC;YACjB,kBAAkB,EAAE,YAAE,CAAC,QAAQ,CAAC,MAAM;YACtC,wBAAwB,EAAE,YAAE,CAAC,QAAQ,CAAC,MAAM;YAC5C,2BAA2B,EAAE,YAAE,CAAC,QA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CAAC;QAED,OAAO,MAAM,CAAC;IAClB,CAAC;CACJ;AAlID,oCAkIC"}
|
package/index.mjs
CHANGED
|
@@ -26,6 +26,7 @@ export const LoggerJson = mod.LoggerJson;
|
|
|
26
26
|
export const LoggerText = mod.LoggerText;
|
|
27
27
|
export const MAX_POOL_SIZE = mod.MAX_POOL_SIZE;
|
|
28
28
|
export const MAX_QUERIES_FOR_CONSISTENCY = mod.MAX_QUERIES_FOR_CONSISTENCY;
|
|
29
|
+
export const MemoryLoadSignal = mod.MemoryLoadSignal;
|
|
29
30
|
export const MissingRouteError = mod.MissingRouteError;
|
|
30
31
|
export const NonRetryableError = mod.NonRetryableError;
|
|
31
32
|
export const PERSIST_STATE_KEY = mod.PERSIST_STATE_KEY;
|
|
@@ -53,6 +54,7 @@ export const Session = mod.Session;
|
|
|
53
54
|
export const SessionError = mod.SessionError;
|
|
54
55
|
export const SessionPool = mod.SessionPool;
|
|
55
56
|
export const SitemapRequestList = mod.SitemapRequestList;
|
|
57
|
+
export const SnapshotStore = mod.SnapshotStore;
|
|
56
58
|
export const Snapshotter = mod.Snapshotter;
|
|
57
59
|
export const Statistics = mod.Statistics;
|
|
58
60
|
export const StorageManager = mod.StorageManager;
|
|
@@ -65,11 +67,15 @@ export const constructGlobObjectsFromGlobs = mod.constructGlobObjectsFromGlobs;
|
|
|
65
67
|
export const constructRegExpObjectsFromPseudoUrls = mod.constructRegExpObjectsFromPseudoUrls;
|
|
66
68
|
export const constructRegExpObjectsFromRegExps = mod.constructRegExpObjectsFromRegExps;
|
|
67
69
|
export const cookieStringToToughCookie = mod.cookieStringToToughCookie;
|
|
70
|
+
export const createClientLoadSignal = mod.createClientLoadSignal;
|
|
71
|
+
export const createCpuLoadSignal = mod.createCpuLoadSignal;
|
|
68
72
|
export const createDeserialize = mod.createDeserialize;
|
|
73
|
+
export const createEventLoopLoadSignal = mod.createEventLoopLoadSignal;
|
|
69
74
|
export const createRequestOptions = mod.createRequestOptions;
|
|
70
75
|
export const createRequests = mod.createRequests;
|
|
71
76
|
export const deserializeArray = mod.deserializeArray;
|
|
72
77
|
export const enqueueLinks = mod.enqueueLinks;
|
|
78
|
+
export const evaluateLoadSignalSample = mod.evaluateLoadSignalSample;
|
|
73
79
|
export const filterRequestsByPatterns = mod.filterRequestsByPatterns;
|
|
74
80
|
export const getCookiesFromResponse = mod.getCookiesFromResponse;
|
|
75
81
|
export const getDefaultCookieExpirationDate = mod.getDefaultCookieExpirationDate;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@crawlee/core",
|
|
3
|
-
"version": "3.16.1-beta.
|
|
3
|
+
"version": "3.16.1-beta.35",
|
|
4
4
|
"description": "The scalable web crawling and scraping library for JavaScript/Node.js. Enables development of data extraction and web automation jobs (not only) with headless Chrome and Puppeteer.",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=16.0.0"
|
|
@@ -59,9 +59,9 @@
|
|
|
59
59
|
"@apify/pseudo_url": "^2.0.30",
|
|
60
60
|
"@apify/timeout": "^0.3.0",
|
|
61
61
|
"@apify/utilities": "^2.7.10",
|
|
62
|
-
"@crawlee/memory-storage": "3.16.1-beta.
|
|
63
|
-
"@crawlee/types": "3.16.1-beta.
|
|
64
|
-
"@crawlee/utils": "3.16.1-beta.
|
|
62
|
+
"@crawlee/memory-storage": "3.16.1-beta.35",
|
|
63
|
+
"@crawlee/types": "3.16.1-beta.35",
|
|
64
|
+
"@crawlee/utils": "3.16.1-beta.35",
|
|
65
65
|
"@sapphire/async-queue": "^1.5.1",
|
|
66
66
|
"@vladfrangu/async_event_emitter": "^2.2.2",
|
|
67
67
|
"csv-stringify": "^6.2.0",
|
|
@@ -83,5 +83,5 @@
|
|
|
83
83
|
}
|
|
84
84
|
}
|
|
85
85
|
},
|
|
86
|
-
"gitHead": "
|
|
86
|
+
"gitHead": "3d5fd8c11142549231b986efde65fe0cdd219776"
|
|
87
87
|
}
|