@crawlee/core 3.0.0-alpha.2 → 3.0.0-alpha.3
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/dist/LICENSE.md +201 -0
- package/{README.md → dist/README.md} +0 -0
- package/dist/autoscaling/autoscaled_pool.d.ts +286 -0
- package/dist/autoscaling/autoscaled_pool.d.ts.map +1 -0
- package/dist/autoscaling/autoscaled_pool.js +624 -0
- package/dist/autoscaling/autoscaled_pool.js.map +1 -0
- package/dist/autoscaling/index.d.ts +4 -0
- package/dist/autoscaling/index.d.ts.map +1 -0
- package/dist/autoscaling/index.js +7 -0
- package/dist/autoscaling/index.js.map +1 -0
- package/dist/autoscaling/snapshotter.d.ts +193 -0
- package/dist/autoscaling/snapshotter.d.ts.map +1 -0
- package/dist/autoscaling/snapshotter.js +377 -0
- package/dist/autoscaling/snapshotter.js.map +1 -0
- package/dist/autoscaling/system_status.d.ts +181 -0
- package/dist/autoscaling/system_status.d.ts.map +1 -0
- package/dist/autoscaling/system_status.js +194 -0
- package/dist/autoscaling/system_status.js.map +1 -0
- package/dist/cache_container.d.ts +18 -0
- package/dist/cache_container.d.ts.map +1 -0
- package/dist/cache_container.js +42 -0
- package/dist/cache_container.js.map +1 -0
- package/dist/configuration.d.ts +150 -0
- package/dist/configuration.d.ts.map +1 -0
- package/dist/configuration.js +284 -0
- package/dist/configuration.js.map +1 -0
- package/dist/constants.d.ts +3 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +6 -0
- package/dist/constants.js.map +1 -0
- package/dist/crawlers/crawler_commons.d.ts +23 -0
- package/dist/crawlers/crawler_commons.d.ts.map +1 -0
- package/dist/crawlers/crawler_commons.js +3 -0
- package/dist/crawlers/crawler_commons.js.map +1 -0
- package/dist/crawlers/crawler_extension.d.ts +11 -0
- package/dist/crawlers/crawler_extension.d.ts.map +1 -0
- package/dist/crawlers/crawler_extension.js +30 -0
- package/dist/crawlers/crawler_extension.js.map +1 -0
- package/dist/crawlers/crawler_utils.d.ts +25 -0
- package/dist/crawlers/crawler_utils.d.ts.map +1 -0
- package/dist/crawlers/crawler_utils.js +72 -0
- package/dist/crawlers/crawler_utils.js.map +1 -0
- package/dist/crawlers/index.d.ts +5 -0
- package/dist/crawlers/index.d.ts.map +1 -0
- package/dist/crawlers/index.js +8 -0
- package/dist/crawlers/index.js.map +1 -0
- package/dist/crawlers/statistics.d.ts +147 -0
- package/dist/crawlers/statistics.d.ts.map +1 -0
- package/dist/crawlers/statistics.js +360 -0
- package/dist/crawlers/statistics.js.map +1 -0
- package/dist/enqueue_links/enqueue_links.d.ts +138 -0
- package/dist/enqueue_links/enqueue_links.d.ts.map +1 -0
- package/dist/enqueue_links/enqueue_links.js +123 -0
- package/dist/enqueue_links/enqueue_links.js.map +1 -0
- package/dist/enqueue_links/index.d.ts +3 -0
- package/dist/enqueue_links/index.d.ts.map +1 -0
- package/dist/enqueue_links/index.js +6 -0
- package/dist/enqueue_links/index.js.map +1 -0
- package/dist/enqueue_links/shared.d.ts +60 -0
- package/dist/enqueue_links/shared.d.ts.map +1 -0
- package/dist/enqueue_links/shared.js +148 -0
- package/dist/enqueue_links/shared.js.map +1 -0
- package/dist/errors.d.ts +8 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +12 -0
- package/dist/errors.js.map +1 -0
- package/dist/events/event_manager.d.ts +41 -0
- package/dist/events/event_manager.d.ts.map +1 -0
- package/dist/events/event_manager.js +103 -0
- package/dist/events/event_manager.js.map +1 -0
- package/dist/events/index.d.ts +3 -0
- package/dist/events/index.d.ts.map +1 -0
- package/dist/events/index.js +6 -0
- package/dist/events/index.js.map +1 -0
- package/dist/events/local_event_manager.d.ts +32 -0
- package/dist/events/local_event_manager.d.ts.map +1 -0
- package/dist/events/local_event_manager.js +114 -0
- package/dist/events/local_event_manager.js.map +1 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +17 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +63 -0
- package/dist/log.d.ts +3 -0
- package/dist/log.d.ts.map +1 -0
- package/dist/log.js +12 -0
- package/dist/log.js.map +1 -0
- package/dist/package.json +82 -0
- package/dist/proxy_configuration.d.ts +181 -0
- package/dist/proxy_configuration.d.ts.map +1 -0
- package/dist/proxy_configuration.js +209 -0
- package/dist/proxy_configuration.js.map +1 -0
- package/dist/request.d.ts +174 -0
- package/dist/request.d.ts.map +1 -0
- package/dist/request.js +270 -0
- package/dist/request.js.map +1 -0
- package/dist/serialization.d.ts +33 -0
- package/dist/serialization.d.ts.map +1 -0
- package/dist/serialization.js +146 -0
- package/dist/serialization.js.map +1 -0
- package/dist/session_pool/errors.d.ts +8 -0
- package/dist/session_pool/errors.d.ts.map +1 -0
- package/dist/session_pool/errors.js +20 -0
- package/dist/session_pool/errors.js.map +1 -0
- package/dist/session_pool/events.d.ts +3 -0
- package/dist/session_pool/events.d.ts.map +1 -0
- package/dist/session_pool/events.js +6 -0
- package/dist/session_pool/events.js.map +1 -0
- package/dist/session_pool/index.d.ts +6 -0
- package/dist/session_pool/index.d.ts.map +1 -0
- package/dist/session_pool/index.js +9 -0
- package/dist/session_pool/index.js.map +1 -0
- package/dist/session_pool/session.d.ts +212 -0
- package/dist/session_pool/session.d.ts.map +1 -0
- package/dist/session_pool/session.js +360 -0
- package/dist/session_pool/session.js.map +1 -0
- package/dist/session_pool/session_pool.d.ts +222 -0
- package/dist/session_pool/session_pool.d.ts.map +1 -0
- package/dist/session_pool/session_pool.js +389 -0
- package/dist/session_pool/session_pool.js.map +1 -0
- package/dist/session_pool/session_utils.d.ts +9 -0
- package/dist/session_pool/session_utils.d.ts.map +1 -0
- package/dist/session_pool/session_utils.js +19 -0
- package/dist/session_pool/session_utils.js.map +1 -0
- package/dist/storages/dataset.d.ts +358 -0
- package/dist/storages/dataset.d.ts.map +1 -0
- package/dist/storages/dataset.js +415 -0
- package/dist/storages/dataset.js.map +1 -0
- package/dist/storages/index.d.ts +7 -0
- package/dist/storages/index.d.ts.map +1 -0
- package/dist/storages/index.js +11 -0
- package/dist/storages/index.js.map +1 -0
- package/dist/storages/key_value_store.d.ts +242 -0
- package/dist/storages/key_value_store.d.ts.map +1 -0
- package/dist/storages/key_value_store.js +319 -0
- package/dist/storages/key_value_store.js.map +1 -0
- package/dist/storages/request_list.d.ts +461 -0
- package/dist/storages/request_list.d.ts.map +1 -0
- package/dist/storages/request_list.js +715 -0
- package/dist/storages/request_list.js.map +1 -0
- package/dist/storages/request_queue.d.ts +312 -0
- package/dist/storages/request_queue.d.ts.map +1 -0
- package/dist/storages/request_queue.js +708 -0
- package/dist/storages/request_queue.js.map +1 -0
- package/dist/storages/storage.d.ts +260 -0
- package/dist/storages/storage.d.ts.map +1 -0
- package/dist/storages/storage.js +3 -0
- package/dist/storages/storage.js.map +1 -0
- package/dist/storages/storage_manager.d.ts +40 -0
- package/dist/storages/storage_manager.d.ts.map +1 -0
- package/dist/storages/storage_manager.js +119 -0
- package/dist/storages/storage_manager.js.map +1 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -0
- package/dist/typedefs.d.ts +12 -0
- package/dist/typedefs.d.ts.map +1 -0
- package/dist/typedefs.js +15 -0
- package/dist/typedefs.js.map +1 -0
- package/dist/validators.d.ts +21 -0
- package/dist/validators.d.ts.map +1 -0
- package/dist/validators.js +26 -0
- package/dist/validators.js.map +1 -0
- package/package.json +11 -10
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import { Log } from '@apify/log';
|
|
2
|
+
import { BetterIntervalID } from '@apify/utilities';
|
|
3
|
+
import { Configuration } from '../configuration';
|
|
4
|
+
import { SystemInfo } from './system_status';
|
|
5
|
+
import { StorageClient } from '../storages/storage';
|
|
6
|
+
import { EventManager } from '../events/event_manager';
|
|
7
|
+
export interface SnapshotterOptions {
|
|
8
|
+
/**
|
|
9
|
+
* Defines the interval of measuring the event loop response time.
|
|
10
|
+
* @default 0.5
|
|
11
|
+
*/
|
|
12
|
+
eventLoopSnapshotIntervalSecs?: number;
|
|
13
|
+
/**
|
|
14
|
+
* Defines the interval of checking the current state
|
|
15
|
+
* of the remote API client.
|
|
16
|
+
* @default 1
|
|
17
|
+
*/
|
|
18
|
+
clientSnapshotIntervalSecs?: number;
|
|
19
|
+
/**
|
|
20
|
+
* Maximum allowed delay of the event loop in milliseconds.
|
|
21
|
+
* Exceeding this limit overloads the event loop.
|
|
22
|
+
* @default 50
|
|
23
|
+
*/
|
|
24
|
+
maxBlockedMillis?: number;
|
|
25
|
+
/**
|
|
26
|
+
* Defines the maximum ratio of total memory that can be used.
|
|
27
|
+
* Exceeding this limit overloads the memory.
|
|
28
|
+
* @default 0.7
|
|
29
|
+
*/
|
|
30
|
+
maxUsedMemoryRatio?: number;
|
|
31
|
+
/**
|
|
32
|
+
* Defines the maximum number of new rate limit errors within
|
|
33
|
+
* the given interval.
|
|
34
|
+
* @default 1
|
|
35
|
+
*/
|
|
36
|
+
maxClientErrors?: number;
|
|
37
|
+
/**
|
|
38
|
+
* Sets the interval in seconds for which a history of resource snapshots
|
|
39
|
+
* will be kept. Increasing this to very high numbers will affect performance.
|
|
40
|
+
* @default 60
|
|
41
|
+
*/
|
|
42
|
+
snapshotHistorySecs?: number;
|
|
43
|
+
/** @internal */
|
|
44
|
+
log?: Log;
|
|
45
|
+
/** @internal */
|
|
46
|
+
client?: StorageClient;
|
|
47
|
+
/** @internal */
|
|
48
|
+
config?: Configuration;
|
|
49
|
+
}
|
|
50
|
+
declare type MemorySnapshot = {
|
|
51
|
+
createdAt: Date;
|
|
52
|
+
isOverloaded: boolean;
|
|
53
|
+
usedBytes?: number;
|
|
54
|
+
};
|
|
55
|
+
declare type CpuSnapshot = {
|
|
56
|
+
createdAt: Date;
|
|
57
|
+
isOverloaded: boolean;
|
|
58
|
+
usedRatio: number;
|
|
59
|
+
ticks?: {
|
|
60
|
+
idle: number;
|
|
61
|
+
total: number;
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
declare type EventLoopSnapshot = {
|
|
65
|
+
createdAt: Date;
|
|
66
|
+
isOverloaded: boolean;
|
|
67
|
+
exceededMillis: number;
|
|
68
|
+
};
|
|
69
|
+
declare type ClientSnapshot = {
|
|
70
|
+
createdAt: Date;
|
|
71
|
+
isOverloaded: boolean;
|
|
72
|
+
rateLimitErrorCount: number;
|
|
73
|
+
};
|
|
74
|
+
/**
|
|
75
|
+
* Creates snapshots of system resources at given intervals and marks the resource
|
|
76
|
+
* as either overloaded or not during the last interval. Keeps a history of the snapshots.
|
|
77
|
+
* It tracks the following resources: Memory, EventLoop, API and CPU.
|
|
78
|
+
* The class is used by the {@link AutoscaledPool} class.
|
|
79
|
+
*
|
|
80
|
+
* When running on the Apify platform, the CPU and memory statistics are provided by the platform,
|
|
81
|
+
* as collected from the running Docker container. When running locally, `Snapshotter`
|
|
82
|
+
* makes its own statistics by querying the OS.
|
|
83
|
+
*
|
|
84
|
+
* CPU becomes overloaded locally when its current use exceeds the `maxUsedCpuRatio` option or
|
|
85
|
+
* when Apify platform marks it as overloaded.
|
|
86
|
+
*
|
|
87
|
+
* Memory becomes overloaded if its current use exceeds the `maxUsedMemoryRatio` option.
|
|
88
|
+
* It's computed using the total memory available to the container when running on
|
|
89
|
+
* the Apify platform and a quarter of total system memory when running locally.
|
|
90
|
+
* Max total memory when running locally may be overridden by using the `APIFY_MEMORY_MBYTES`
|
|
91
|
+
* environment variable.
|
|
92
|
+
*
|
|
93
|
+
* Event loop becomes overloaded if it slows down by more than the `maxBlockedMillis` option.
|
|
94
|
+
*
|
|
95
|
+
* Client becomes overloaded when rate limit errors (429 - Too Many Requests),
|
|
96
|
+
* typically received from the request queue, exceed the set limit within the set interval.
|
|
97
|
+
* @category Scaling
|
|
98
|
+
*/
|
|
99
|
+
export declare class Snapshotter {
|
|
100
|
+
log: Log;
|
|
101
|
+
client: StorageClient;
|
|
102
|
+
config: Configuration;
|
|
103
|
+
events: EventManager;
|
|
104
|
+
eventLoopSnapshotIntervalMillis: number;
|
|
105
|
+
clientSnapshotIntervalMillis: number;
|
|
106
|
+
snapshotHistoryMillis: number;
|
|
107
|
+
maxBlockedMillis: number;
|
|
108
|
+
maxUsedMemoryRatio: number;
|
|
109
|
+
maxClientErrors: number;
|
|
110
|
+
maxMemoryBytes: number;
|
|
111
|
+
cpuSnapshots: CpuSnapshot[];
|
|
112
|
+
eventLoopSnapshots: EventLoopSnapshot[];
|
|
113
|
+
memorySnapshots: MemorySnapshot[];
|
|
114
|
+
clientSnapshots: ClientSnapshot[];
|
|
115
|
+
eventLoopInterval: BetterIntervalID;
|
|
116
|
+
clientInterval: BetterIntervalID;
|
|
117
|
+
lastLoggedCriticalMemoryOverloadAt: Date | null;
|
|
118
|
+
/**
|
|
119
|
+
* @param [options] All `Snapshotter` configuration options.
|
|
120
|
+
*/
|
|
121
|
+
constructor(options?: SnapshotterOptions);
|
|
122
|
+
/**
|
|
123
|
+
* Starts capturing snapshots at configured intervals.
|
|
124
|
+
*/
|
|
125
|
+
start(): Promise<void>;
|
|
126
|
+
/**
|
|
127
|
+
* Stops all resource capturing.
|
|
128
|
+
*/
|
|
129
|
+
stop(): Promise<void>;
|
|
130
|
+
/**
|
|
131
|
+
* Returns a sample of latest memory snapshots, with the size of the sample defined
|
|
132
|
+
* by the sampleDurationMillis parameter. If omitted, it returns a full snapshot history.
|
|
133
|
+
*/
|
|
134
|
+
getMemorySample(sampleDurationMillis?: number): MemorySnapshot[];
|
|
135
|
+
/**
|
|
136
|
+
* Returns a sample of latest event loop snapshots, with the size of the sample defined
|
|
137
|
+
* by the sampleDurationMillis parameter. If omitted, it returns a full snapshot history.
|
|
138
|
+
*/
|
|
139
|
+
getEventLoopSample(sampleDurationMillis?: number): EventLoopSnapshot[];
|
|
140
|
+
/**
|
|
141
|
+
* Returns a sample of latest CPU snapshots, with the size of the sample defined
|
|
142
|
+
* by the sampleDurationMillis parameter. If omitted, it returns a full snapshot history.
|
|
143
|
+
*/
|
|
144
|
+
getCpuSample(sampleDurationMillis?: number): CpuSnapshot[];
|
|
145
|
+
/**
|
|
146
|
+
* Returns a sample of latest Client snapshots, with the size of the sample defined
|
|
147
|
+
* by the sampleDurationMillis parameter. If omitted, it returns a full snapshot history.
|
|
148
|
+
*/
|
|
149
|
+
getClientSample(sampleDurationMillis?: number): ClientSnapshot[];
|
|
150
|
+
/**
|
|
151
|
+
* Finds the latest snapshots by sampleDurationMillis in the provided array.
|
|
152
|
+
*/
|
|
153
|
+
protected _getSample<T extends {
|
|
154
|
+
createdAt: Date;
|
|
155
|
+
}>(snapshots: T[], sampleDurationMillis?: number): T[];
|
|
156
|
+
/**
|
|
157
|
+
* Creates a snapshot of current memory usage
|
|
158
|
+
* using the Apify platform `systemInfo` event.
|
|
159
|
+
*/
|
|
160
|
+
protected _snapshotMemory(systemInfo: SystemInfo): void;
|
|
161
|
+
/**
|
|
162
|
+
* Checks for critical memory overload and logs it to the console.
|
|
163
|
+
*/
|
|
164
|
+
protected _memoryOverloadWarning(systemInfo: SystemInfo): void;
|
|
165
|
+
/**
|
|
166
|
+
* Creates a snapshot of current event loop delay.
|
|
167
|
+
*/
|
|
168
|
+
protected _snapshotEventLoop(intervalCallback: () => unknown): void;
|
|
169
|
+
/**
|
|
170
|
+
* Creates a snapshot of current CPU usage using the Apify platform `systemInfo` event.
|
|
171
|
+
*/
|
|
172
|
+
protected _snapshotCpu(systemInfo: SystemInfo): void;
|
|
173
|
+
/**
|
|
174
|
+
* Creates a snapshot of current API state by checking for
|
|
175
|
+
* rate limit errors. Only errors produced by a 2nd retry
|
|
176
|
+
* of the API call are considered for snapshotting since
|
|
177
|
+
* earlier errors may just be caused by a random spike in
|
|
178
|
+
* number of requests and do not necessarily signify API
|
|
179
|
+
* overloading.
|
|
180
|
+
*/
|
|
181
|
+
protected _snapshotClient(intervalCallback: () => unknown): void;
|
|
182
|
+
/**
|
|
183
|
+
* Removes snapshots that are older than the snapshotHistorySecs option
|
|
184
|
+
* from the array (destructively - in place).
|
|
185
|
+
*/
|
|
186
|
+
protected _pruneSnapshots(snapshots: MemorySnapshot[] | CpuSnapshot[] | EventLoopSnapshot[] | ClientSnapshot[], now: Date): void;
|
|
187
|
+
/**
|
|
188
|
+
* Helper method for easier mocking.
|
|
189
|
+
*/
|
|
190
|
+
private _getMemoryInfo;
|
|
191
|
+
}
|
|
192
|
+
export {};
|
|
193
|
+
//# sourceMappingURL=snapshotter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"snapshotter.d.ts","sourceRoot":"","sources":["../../src/autoscaling/snapshotter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,YAAY,CAAC;AACjC,OAAO,EAAuB,gBAAgB,EAAqB,MAAM,kBAAkB,CAAC;AAG5F,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEjD,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAa,MAAM,yBAAyB,CAAC;AAMlE,MAAM,WAAW,kBAAkB;IAC/B;;;OAGG;IACH,6BAA6B,CAAC,EAAE,MAAM,CAAC;IAEvC;;;;OAIG;IACH,0BAA0B,CAAC,EAAE,MAAM,CAAC;IAEpC;;;;OAIG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAE1B;;;;OAIG;IACH,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAE5B;;;;OAIG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;IAEzB;;;;OAIG;IACH,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAE7B,gBAAgB;IAChB,GAAG,CAAC,EAAE,GAAG,CAAC;IAEV,gBAAgB;IAChB,MAAM,CAAC,EAAE,aAAa,CAAC;IAEvB,gBAAgB;IAChB,MAAM,CAAC,EAAE,aAAa,CAAC;CAC1B;AAED,aAAK,cAAc,GAAG;IAAE,SAAS,EAAE,IAAI,CAAC;IAAC,YAAY,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
const utilities_1 = require("@apify/utilities");
|
|
6
|
+
const utils_1 = require("@crawlee/utils");
|
|
7
|
+
const ow_1 = tslib_1.__importDefault(require("ow"));
|
|
8
|
+
const configuration_1 = require("../configuration");
|
|
9
|
+
const log_1 = require("../log");
|
|
10
|
+
const RESERVE_MEMORY_RATIO = 0.5;
|
|
11
|
+
const CLIENT_RATE_LIMIT_ERROR_RETRY_COUNT = 2;
|
|
12
|
+
const CRITICAL_OVERLOAD_RATE_LIMIT_MILLIS = 10000;
|
|
13
|
+
/**
|
|
14
|
+
* Creates snapshots of system resources at given intervals and marks the resource
|
|
15
|
+
* as either overloaded or not during the last interval. Keeps a history of the snapshots.
|
|
16
|
+
* It tracks the following resources: Memory, EventLoop, API and CPU.
|
|
17
|
+
* The class is used by the {@link AutoscaledPool} class.
|
|
18
|
+
*
|
|
19
|
+
* When running on the Apify platform, the CPU and memory statistics are provided by the platform,
|
|
20
|
+
* as collected from the running Docker container. When running locally, `Snapshotter`
|
|
21
|
+
* makes its own statistics by querying the OS.
|
|
22
|
+
*
|
|
23
|
+
* CPU becomes overloaded locally when its current use exceeds the `maxUsedCpuRatio` option or
|
|
24
|
+
* when Apify platform marks it as overloaded.
|
|
25
|
+
*
|
|
26
|
+
* Memory becomes overloaded if its current use exceeds the `maxUsedMemoryRatio` option.
|
|
27
|
+
* It's computed using the total memory available to the container when running on
|
|
28
|
+
* the Apify platform and a quarter of total system memory when running locally.
|
|
29
|
+
* Max total memory when running locally may be overridden by using the `APIFY_MEMORY_MBYTES`
|
|
30
|
+
* environment variable.
|
|
31
|
+
*
|
|
32
|
+
* Event loop becomes overloaded if it slows down by more than the `maxBlockedMillis` option.
|
|
33
|
+
*
|
|
34
|
+
* Client becomes overloaded when rate limit errors (429 - Too Many Requests),
|
|
35
|
+
* typically received from the request queue, exceed the set limit within the set interval.
|
|
36
|
+
* @category Scaling
|
|
37
|
+
*/
|
|
38
|
+
class Snapshotter {
|
|
39
|
+
/**
|
|
40
|
+
* @param [options] All `Snapshotter` configuration options.
|
|
41
|
+
*/
|
|
42
|
+
constructor(options = {}) {
|
|
43
|
+
Object.defineProperty(this, "log", {
|
|
44
|
+
enumerable: true,
|
|
45
|
+
configurable: true,
|
|
46
|
+
writable: true,
|
|
47
|
+
value: void 0
|
|
48
|
+
});
|
|
49
|
+
Object.defineProperty(this, "client", {
|
|
50
|
+
enumerable: true,
|
|
51
|
+
configurable: true,
|
|
52
|
+
writable: true,
|
|
53
|
+
value: void 0
|
|
54
|
+
});
|
|
55
|
+
Object.defineProperty(this, "config", {
|
|
56
|
+
enumerable: true,
|
|
57
|
+
configurable: true,
|
|
58
|
+
writable: true,
|
|
59
|
+
value: void 0
|
|
60
|
+
});
|
|
61
|
+
Object.defineProperty(this, "events", {
|
|
62
|
+
enumerable: true,
|
|
63
|
+
configurable: true,
|
|
64
|
+
writable: true,
|
|
65
|
+
value: void 0
|
|
66
|
+
});
|
|
67
|
+
Object.defineProperty(this, "eventLoopSnapshotIntervalMillis", {
|
|
68
|
+
enumerable: true,
|
|
69
|
+
configurable: true,
|
|
70
|
+
writable: true,
|
|
71
|
+
value: void 0
|
|
72
|
+
});
|
|
73
|
+
Object.defineProperty(this, "clientSnapshotIntervalMillis", {
|
|
74
|
+
enumerable: true,
|
|
75
|
+
configurable: true,
|
|
76
|
+
writable: true,
|
|
77
|
+
value: void 0
|
|
78
|
+
});
|
|
79
|
+
Object.defineProperty(this, "snapshotHistoryMillis", {
|
|
80
|
+
enumerable: true,
|
|
81
|
+
configurable: true,
|
|
82
|
+
writable: true,
|
|
83
|
+
value: void 0
|
|
84
|
+
});
|
|
85
|
+
Object.defineProperty(this, "maxBlockedMillis", {
|
|
86
|
+
enumerable: true,
|
|
87
|
+
configurable: true,
|
|
88
|
+
writable: true,
|
|
89
|
+
value: void 0
|
|
90
|
+
});
|
|
91
|
+
Object.defineProperty(this, "maxUsedMemoryRatio", {
|
|
92
|
+
enumerable: true,
|
|
93
|
+
configurable: true,
|
|
94
|
+
writable: true,
|
|
95
|
+
value: void 0
|
|
96
|
+
});
|
|
97
|
+
Object.defineProperty(this, "maxClientErrors", {
|
|
98
|
+
enumerable: true,
|
|
99
|
+
configurable: true,
|
|
100
|
+
writable: true,
|
|
101
|
+
value: void 0
|
|
102
|
+
});
|
|
103
|
+
Object.defineProperty(this, "maxMemoryBytes", {
|
|
104
|
+
enumerable: true,
|
|
105
|
+
configurable: true,
|
|
106
|
+
writable: true,
|
|
107
|
+
value: void 0
|
|
108
|
+
});
|
|
109
|
+
Object.defineProperty(this, "cpuSnapshots", {
|
|
110
|
+
enumerable: true,
|
|
111
|
+
configurable: true,
|
|
112
|
+
writable: true,
|
|
113
|
+
value: []
|
|
114
|
+
});
|
|
115
|
+
Object.defineProperty(this, "eventLoopSnapshots", {
|
|
116
|
+
enumerable: true,
|
|
117
|
+
configurable: true,
|
|
118
|
+
writable: true,
|
|
119
|
+
value: []
|
|
120
|
+
});
|
|
121
|
+
Object.defineProperty(this, "memorySnapshots", {
|
|
122
|
+
enumerable: true,
|
|
123
|
+
configurable: true,
|
|
124
|
+
writable: true,
|
|
125
|
+
value: []
|
|
126
|
+
});
|
|
127
|
+
Object.defineProperty(this, "clientSnapshots", {
|
|
128
|
+
enumerable: true,
|
|
129
|
+
configurable: true,
|
|
130
|
+
writable: true,
|
|
131
|
+
value: []
|
|
132
|
+
});
|
|
133
|
+
Object.defineProperty(this, "eventLoopInterval", {
|
|
134
|
+
enumerable: true,
|
|
135
|
+
configurable: true,
|
|
136
|
+
writable: true,
|
|
137
|
+
value: null
|
|
138
|
+
});
|
|
139
|
+
Object.defineProperty(this, "clientInterval", {
|
|
140
|
+
enumerable: true,
|
|
141
|
+
configurable: true,
|
|
142
|
+
writable: true,
|
|
143
|
+
value: null
|
|
144
|
+
});
|
|
145
|
+
Object.defineProperty(this, "lastLoggedCriticalMemoryOverloadAt", {
|
|
146
|
+
enumerable: true,
|
|
147
|
+
configurable: true,
|
|
148
|
+
writable: true,
|
|
149
|
+
value: null
|
|
150
|
+
});
|
|
151
|
+
(0, ow_1.default)(options, ow_1.default.object.exactShape({
|
|
152
|
+
eventLoopSnapshotIntervalSecs: ow_1.default.optional.number,
|
|
153
|
+
clientSnapshotIntervalSecs: ow_1.default.optional.number,
|
|
154
|
+
snapshotHistorySecs: ow_1.default.optional.number,
|
|
155
|
+
maxBlockedMillis: ow_1.default.optional.number,
|
|
156
|
+
maxUsedMemoryRatio: ow_1.default.optional.number,
|
|
157
|
+
maxClientErrors: ow_1.default.optional.number,
|
|
158
|
+
log: ow_1.default.optional.object,
|
|
159
|
+
client: ow_1.default.optional.object,
|
|
160
|
+
config: ow_1.default.optional.object,
|
|
161
|
+
}));
|
|
162
|
+
const { eventLoopSnapshotIntervalSecs = 0.5, clientSnapshotIntervalSecs = 1, snapshotHistorySecs = 30, maxBlockedMillis = 50, maxUsedMemoryRatio = 0.7, maxClientErrors = 3, log = log_1.log, config = configuration_1.Configuration.getGlobalConfig(), client = config.getStorageClient(), } = options;
|
|
163
|
+
this.log = log.child({ prefix: 'Snapshotter' });
|
|
164
|
+
this.client = client;
|
|
165
|
+
this.config = config;
|
|
166
|
+
this.events = this.config.getEventManager();
|
|
167
|
+
this.eventLoopSnapshotIntervalMillis = eventLoopSnapshotIntervalSecs * 1000;
|
|
168
|
+
this.clientSnapshotIntervalMillis = clientSnapshotIntervalSecs * 1000;
|
|
169
|
+
this.snapshotHistoryMillis = snapshotHistorySecs * 1000;
|
|
170
|
+
this.maxBlockedMillis = maxBlockedMillis;
|
|
171
|
+
this.maxUsedMemoryRatio = maxUsedMemoryRatio;
|
|
172
|
+
this.maxClientErrors = maxClientErrors;
|
|
173
|
+
// We need to pre-bind those functions to be able to successfully remove listeners.
|
|
174
|
+
this._snapshotCpu = this._snapshotCpu.bind(this);
|
|
175
|
+
this._snapshotMemory = this._snapshotMemory.bind(this);
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Starts capturing snapshots at configured intervals.
|
|
179
|
+
*/
|
|
180
|
+
async start() {
|
|
181
|
+
const { totalBytes } = await this._getMemoryInfo();
|
|
182
|
+
this.maxMemoryBytes = Math.ceil(totalBytes * this.config.get('availableMemoryRatio'));
|
|
183
|
+
this.log.debug(`Setting max memory of this run to ${Math.round(this.maxMemoryBytes / 1024 / 1024)} MB. Use the AVAILABLE_MEMORY_RATIO environment variable to override it.`); // eslint-disable-line max-len
|
|
184
|
+
// Ensure events are initialized.
|
|
185
|
+
// await this.events.init();
|
|
186
|
+
// Start snapshotting.
|
|
187
|
+
this.eventLoopInterval = (0, utilities_1.betterSetInterval)(this._snapshotEventLoop.bind(this), this.eventLoopSnapshotIntervalMillis);
|
|
188
|
+
this.clientInterval = (0, utilities_1.betterSetInterval)(this._snapshotClient.bind(this), this.clientSnapshotIntervalMillis);
|
|
189
|
+
this.events.on("systemInfo" /* SYSTEM_INFO */, this._snapshotCpu);
|
|
190
|
+
this.events.on("systemInfo" /* SYSTEM_INFO */, this._snapshotMemory);
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Stops all resource capturing.
|
|
194
|
+
*/
|
|
195
|
+
async stop() {
|
|
196
|
+
(0, utilities_1.betterClearInterval)(this.eventLoopInterval);
|
|
197
|
+
(0, utilities_1.betterClearInterval)(this.clientInterval);
|
|
198
|
+
this.events.off("systemInfo" /* SYSTEM_INFO */, this._snapshotCpu);
|
|
199
|
+
this.events.off("systemInfo" /* SYSTEM_INFO */, this._snapshotMemory);
|
|
200
|
+
// Allow microtask queue to unwind before stop returns.
|
|
201
|
+
await new Promise((resolve) => setImmediate(resolve));
|
|
202
|
+
// await this.events.close();
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Returns a sample of latest memory snapshots, with the size of the sample defined
|
|
206
|
+
* by the sampleDurationMillis parameter. If omitted, it returns a full snapshot history.
|
|
207
|
+
*/
|
|
208
|
+
getMemorySample(sampleDurationMillis) {
|
|
209
|
+
return this._getSample(this.memorySnapshots, sampleDurationMillis);
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Returns a sample of latest event loop snapshots, with the size of the sample defined
|
|
213
|
+
* by the sampleDurationMillis parameter. If omitted, it returns a full snapshot history.
|
|
214
|
+
*/
|
|
215
|
+
getEventLoopSample(sampleDurationMillis) {
|
|
216
|
+
return this._getSample(this.eventLoopSnapshots, sampleDurationMillis);
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Returns a sample of latest CPU snapshots, with the size of the sample defined
|
|
220
|
+
* by the sampleDurationMillis parameter. If omitted, it returns a full snapshot history.
|
|
221
|
+
*/
|
|
222
|
+
getCpuSample(sampleDurationMillis) {
|
|
223
|
+
return this._getSample(this.cpuSnapshots, sampleDurationMillis);
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Returns a sample of latest Client snapshots, with the size of the sample defined
|
|
227
|
+
* by the sampleDurationMillis parameter. If omitted, it returns a full snapshot history.
|
|
228
|
+
*/
|
|
229
|
+
getClientSample(sampleDurationMillis) {
|
|
230
|
+
return this._getSample(this.clientSnapshots, sampleDurationMillis);
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* Finds the latest snapshots by sampleDurationMillis in the provided array.
|
|
234
|
+
*/
|
|
235
|
+
_getSample(snapshots, sampleDurationMillis) {
|
|
236
|
+
if (!sampleDurationMillis)
|
|
237
|
+
return snapshots;
|
|
238
|
+
const sample = [];
|
|
239
|
+
let idx = snapshots.length;
|
|
240
|
+
if (!idx)
|
|
241
|
+
return sample;
|
|
242
|
+
const latestTime = snapshots[idx - 1].createdAt;
|
|
243
|
+
while (idx--) {
|
|
244
|
+
const snapshot = snapshots[idx];
|
|
245
|
+
if (+latestTime - +snapshot.createdAt <= sampleDurationMillis) {
|
|
246
|
+
sample.unshift(snapshot);
|
|
247
|
+
}
|
|
248
|
+
else {
|
|
249
|
+
break;
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
return sample;
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* Creates a snapshot of current memory usage
|
|
256
|
+
* using the Apify platform `systemInfo` event.
|
|
257
|
+
*/
|
|
258
|
+
_snapshotMemory(systemInfo) {
|
|
259
|
+
const createdAt = systemInfo.createdAt ? new Date(systemInfo.createdAt) : new Date();
|
|
260
|
+
this._pruneSnapshots(this.memorySnapshots, createdAt);
|
|
261
|
+
const { memCurrentBytes } = systemInfo;
|
|
262
|
+
const snapshot = {
|
|
263
|
+
createdAt,
|
|
264
|
+
isOverloaded: memCurrentBytes / this.maxMemoryBytes > this.maxUsedMemoryRatio,
|
|
265
|
+
usedBytes: memCurrentBytes,
|
|
266
|
+
};
|
|
267
|
+
this.memorySnapshots.push(snapshot);
|
|
268
|
+
this._memoryOverloadWarning(systemInfo);
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* Checks for critical memory overload and logs it to the console.
|
|
272
|
+
*/
|
|
273
|
+
_memoryOverloadWarning(systemInfo) {
|
|
274
|
+
const { memCurrentBytes } = systemInfo;
|
|
275
|
+
const createdAt = systemInfo.createdAt ? new Date(systemInfo.createdAt) : new Date();
|
|
276
|
+
if (this.lastLoggedCriticalMemoryOverloadAt && +createdAt < +this.lastLoggedCriticalMemoryOverloadAt + CRITICAL_OVERLOAD_RATE_LIMIT_MILLIS)
|
|
277
|
+
return;
|
|
278
|
+
const maxDesiredMemoryBytes = this.maxUsedMemoryRatio * this.maxMemoryBytes;
|
|
279
|
+
const reserveMemory = this.maxMemoryBytes * (1 - this.maxUsedMemoryRatio) * RESERVE_MEMORY_RATIO;
|
|
280
|
+
const criticalOverloadBytes = maxDesiredMemoryBytes + reserveMemory;
|
|
281
|
+
const isCriticalOverload = memCurrentBytes > criticalOverloadBytes;
|
|
282
|
+
if (isCriticalOverload) {
|
|
283
|
+
const usedPercentage = Math.round((memCurrentBytes / this.maxMemoryBytes) * 100);
|
|
284
|
+
const toMb = (bytes) => Math.round(bytes / (1024 ** 2));
|
|
285
|
+
this.log.warning('Memory is critically overloaded. '
|
|
286
|
+
+ `Using ${toMb(memCurrentBytes)} MB of ${toMb(this.maxMemoryBytes)} MB (${usedPercentage}%). Consider increasing the actor memory.`);
|
|
287
|
+
this.lastLoggedCriticalMemoryOverloadAt = createdAt;
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* Creates a snapshot of current event loop delay.
|
|
292
|
+
*/
|
|
293
|
+
_snapshotEventLoop(intervalCallback) {
|
|
294
|
+
const now = new Date();
|
|
295
|
+
this._pruneSnapshots(this.eventLoopSnapshots, now);
|
|
296
|
+
const snapshot = {
|
|
297
|
+
createdAt: now,
|
|
298
|
+
isOverloaded: false,
|
|
299
|
+
exceededMillis: 0,
|
|
300
|
+
};
|
|
301
|
+
const previousSnapshot = this.eventLoopSnapshots[this.eventLoopSnapshots.length - 1];
|
|
302
|
+
if (previousSnapshot) {
|
|
303
|
+
const { createdAt } = previousSnapshot;
|
|
304
|
+
const delta = now.getTime() - +createdAt - this.eventLoopSnapshotIntervalMillis;
|
|
305
|
+
if (delta > this.maxBlockedMillis)
|
|
306
|
+
snapshot.isOverloaded = true;
|
|
307
|
+
snapshot.exceededMillis = Math.max(delta - this.maxBlockedMillis, 0);
|
|
308
|
+
}
|
|
309
|
+
this.eventLoopSnapshots.push(snapshot);
|
|
310
|
+
intervalCallback();
|
|
311
|
+
}
|
|
312
|
+
/**
|
|
313
|
+
* Creates a snapshot of current CPU usage using the Apify platform `systemInfo` event.
|
|
314
|
+
*/
|
|
315
|
+
_snapshotCpu(systemInfo) {
|
|
316
|
+
const { cpuCurrentUsage, isCpuOverloaded } = systemInfo;
|
|
317
|
+
const createdAt = systemInfo.createdAt ? new Date(systemInfo.createdAt) : new Date();
|
|
318
|
+
this._pruneSnapshots(this.cpuSnapshots, createdAt);
|
|
319
|
+
this.cpuSnapshots.push({
|
|
320
|
+
createdAt,
|
|
321
|
+
isOverloaded: isCpuOverloaded,
|
|
322
|
+
usedRatio: Math.ceil(cpuCurrentUsage / 100),
|
|
323
|
+
});
|
|
324
|
+
}
|
|
325
|
+
/**
|
|
326
|
+
* Creates a snapshot of current API state by checking for
|
|
327
|
+
* rate limit errors. Only errors produced by a 2nd retry
|
|
328
|
+
* of the API call are considered for snapshotting since
|
|
329
|
+
* earlier errors may just be caused by a random spike in
|
|
330
|
+
* number of requests and do not necessarily signify API
|
|
331
|
+
* overloading.
|
|
332
|
+
*/
|
|
333
|
+
_snapshotClient(intervalCallback) {
|
|
334
|
+
const now = new Date();
|
|
335
|
+
this._pruneSnapshots(this.clientSnapshots, now);
|
|
336
|
+
const allErrorCounts = this.client.stats?.rateLimitErrors ?? []; // storage client might not support this
|
|
337
|
+
const currentErrCount = allErrorCounts[CLIENT_RATE_LIMIT_ERROR_RETRY_COUNT] || 0;
|
|
338
|
+
// Handle empty snapshots array
|
|
339
|
+
const snapshot = {
|
|
340
|
+
createdAt: now,
|
|
341
|
+
isOverloaded: false,
|
|
342
|
+
rateLimitErrorCount: currentErrCount,
|
|
343
|
+
};
|
|
344
|
+
const previousSnapshot = this.clientSnapshots[this.clientSnapshots.length - 1];
|
|
345
|
+
if (previousSnapshot) {
|
|
346
|
+
const { rateLimitErrorCount } = previousSnapshot;
|
|
347
|
+
const delta = currentErrCount - rateLimitErrorCount;
|
|
348
|
+
if (delta > this.maxClientErrors)
|
|
349
|
+
snapshot.isOverloaded = true;
|
|
350
|
+
}
|
|
351
|
+
this.clientSnapshots.push(snapshot);
|
|
352
|
+
intervalCallback();
|
|
353
|
+
}
|
|
354
|
+
/**
|
|
355
|
+
* Removes snapshots that are older than the snapshotHistorySecs option
|
|
356
|
+
* from the array (destructively - in place).
|
|
357
|
+
*/
|
|
358
|
+
_pruneSnapshots(snapshots, now) {
|
|
359
|
+
let oldCount = 0;
|
|
360
|
+
for (let i = 0; i < snapshots.length; i++) {
|
|
361
|
+
const { createdAt } = snapshots[i];
|
|
362
|
+
if (now.getTime() - new Date(createdAt).getTime() > this.snapshotHistoryMillis)
|
|
363
|
+
oldCount++;
|
|
364
|
+
else
|
|
365
|
+
break;
|
|
366
|
+
}
|
|
367
|
+
snapshots.splice(0, oldCount);
|
|
368
|
+
}
|
|
369
|
+
/**
|
|
370
|
+
* Helper method for easier mocking.
|
|
371
|
+
*/
|
|
372
|
+
async _getMemoryInfo() {
|
|
373
|
+
return (0, utils_1.getMemoryInfo)();
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
exports.Snapshotter = Snapshotter;
|
|
377
|
+
//# sourceMappingURL=snapshotter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"snapshotter.js","sourceRoot":"","sources":["../../src/autoscaling/snapshotter.ts"],"names":[],"mappings":";;;;AACA,gDAA4F;AAC5F,0CAA+C;AAC/C,oDAAoB;AACpB,oDAAiD;AACjD,gCAA2C;AAK3C,MAAM,oBAAoB,GAAG,GAAG,CAAC;AACjC,MAAM,mCAAmC,GAAG,CAAC,CAAC;AAC9C,MAAM,mCAAmC,GAAG,KAAK,CAAC;AA2DlD;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAa,WAAW;IAuBpB;;OAEG;IACH,YAAY,UAA8B,EAAE;QAzB5C;;;;;WAAS;QACT;;;;;WAAsB;QACtB;;;;;WAAsB;QACtB;;;;;WAAqB;QACrB;;;;;WAAwC;QACxC;;;;;WAAqC;QACrC;;;;;WAA8B;QAC9B;;;;;WAAyB;QACzB;;;;;WAA2B;QAC3B;;;;;WAAwB;QACxB;;;;;WAAwB;QAExB;;;;mBAA8B,EAAE;WAAC;QACjC;;;;mBAA0C,EAAE;WAAC;QAC7C;;;;mBAAoC,EAAE;WAAC;QACvC;;;;mBAAoC,EAAE;WAAC;QAEvC;;;;mBAAsC,IAAK;WAAC;QAC5C;;;;mBAAmC,IAAK;WAAC;QAEzC;;;;mBAAkD,IAAI;WAAC;QAMnD,IAAA,YAAE,EAAC,OAAO,EAAE,YAAE,CAAC,MAAM,CAAC,UAAU,CAAC;YAC7B,6BAA6B,EAAE,YAAE,CAAC,QAAQ,CAA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