@crawlee/core 4.0.0-beta.24 → 4.0.0-beta.240

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.
Files changed (265) hide show
  1. package/README.md +15 -15
  2. package/byte-utils.d.ts +17 -0
  3. package/byte-utils.js +42 -0
  4. package/configuration.d.ts +77 -235
  5. package/configuration.js +157 -227
  6. package/debug.d.ts +36 -0
  7. package/debug.js +70 -0
  8. package/errors.d.ts +45 -18
  9. package/errors.js +58 -27
  10. package/events/event-manager.d.ts +78 -0
  11. package/events/{event_manager.js → event-manager.js} +12 -13
  12. package/events/index.d.ts +3 -3
  13. package/events/index.js +2 -3
  14. package/events/local-event-manager.d.ts +32 -0
  15. package/events/local-event-manager.js +101 -0
  16. package/events/system-info.d.ts +38 -0
  17. package/events/system-info.js +1 -0
  18. package/index.d.ts +9 -12
  19. package/index.js +10 -11
  20. package/internal.d.ts +8 -0
  21. package/internal.js +9 -0
  22. package/iterables.d.ts +79 -0
  23. package/iterables.js +134 -0
  24. package/log.d.ts +77 -1
  25. package/log.js +134 -1
  26. package/memory-storage/consts.d.ts +4 -0
  27. package/memory-storage/consts.js +4 -0
  28. package/memory-storage/index.d.ts +1 -0
  29. package/memory-storage/index.js +1 -0
  30. package/memory-storage/memory-storage.d.ts +43 -0
  31. package/memory-storage/memory-storage.js +158 -0
  32. package/memory-storage/resource-clients/common/base-client.d.ts +4 -0
  33. package/memory-storage/resource-clients/common/base-client.js +6 -0
  34. package/memory-storage/resource-clients/dataset.d.ts +35 -0
  35. package/memory-storage/resource-clients/dataset.js +105 -0
  36. package/memory-storage/resource-clients/key-value-store.d.ts +54 -0
  37. package/memory-storage/resource-clients/key-value-store.js +179 -0
  38. package/memory-storage/resource-clients/request-queue.d.ts +55 -0
  39. package/memory-storage/resource-clients/request-queue.js +413 -0
  40. package/memory-storage/utils.d.ts +16 -0
  41. package/memory-storage/utils.js +41 -0
  42. package/owned-or-injected.d.ts +58 -0
  43. package/owned-or-injected.js +98 -0
  44. package/package.json +20 -20
  45. package/proxy-configuration.d.ts +118 -0
  46. package/proxy-configuration.js +141 -0
  47. package/recoverable-state.d.ts +177 -0
  48. package/recoverable-state.js +268 -0
  49. package/request.d.ts +48 -93
  50. package/request.js +112 -230
  51. package/serialization.d.ts +0 -1
  52. package/serialization.js +18 -18
  53. package/service-locator.d.ts +168 -0
  54. package/service-locator.js +255 -0
  55. package/storages/batched-adds.d.ts +37 -0
  56. package/storages/batched-adds.js +73 -0
  57. package/storages/dataset.d.ts +105 -58
  58. package/storages/dataset.js +292 -150
  59. package/storages/index.d.ts +11 -12
  60. package/storages/index.js +7 -12
  61. package/storages/key-value-store-codec.d.ts +32 -0
  62. package/storages/key-value-store-codec.js +108 -0
  63. package/storages/{key_value_store.d.ts → key-value-store.d.ts} +169 -72
  64. package/storages/key-value-store.js +767 -0
  65. package/storages/request-dedup-cache.d.ts +20 -0
  66. package/storages/request-dedup-cache.js +48 -0
  67. package/storages/{request_list.d.ts → request-list.d.ts} +33 -173
  68. package/storages/{request_list.js → request-list.js} +276 -255
  69. package/storages/request-loader.d.ts +127 -0
  70. package/storages/request-loader.js +36 -0
  71. package/storages/request-manager-tandem.d.ts +82 -0
  72. package/storages/request-manager-tandem.js +200 -0
  73. package/storages/request-manager.d.ts +119 -0
  74. package/storages/request-manager.js +1 -0
  75. package/storages/{request_provider.d.ts → request-queue.d.ts} +128 -159
  76. package/storages/request-queue.js +870 -0
  77. package/storages/storage-instance-manager.d.ts +86 -0
  78. package/storages/storage-instance-manager.js +256 -0
  79. package/storages/storage-stats.d.ts +48 -0
  80. package/storages/storage-stats.js +29 -0
  81. package/storages/transaction.d.ts +270 -0
  82. package/storages/transaction.js +296 -0
  83. package/storages/utils.d.ts +59 -11
  84. package/storages/utils.js +76 -16
  85. package/system-info/cpu-info.d.ts +67 -0
  86. package/system-info/cpu-info.js +216 -0
  87. package/system-info/memory-info.d.ts +31 -0
  88. package/system-info/memory-info.js +115 -0
  89. package/system-info/ps-tree.d.ts +17 -0
  90. package/system-info/ps-tree.js +144 -0
  91. package/system-info/runtime.d.ts +14 -0
  92. package/system-info/runtime.js +80 -0
  93. package/typedefs.d.ts +0 -6
  94. package/typedefs.js +0 -1
  95. package/url.d.ts +9 -0
  96. package/url.js +11 -0
  97. package/validators.d.ts +23 -18
  98. package/validators.js +14 -18
  99. package/autoscaling/autoscaled_pool.d.ts +0 -300
  100. package/autoscaling/autoscaled_pool.d.ts.map +0 -1
  101. package/autoscaling/autoscaled_pool.js +0 -533
  102. package/autoscaling/autoscaled_pool.js.map +0 -1
  103. package/autoscaling/index.d.ts +0 -4
  104. package/autoscaling/index.d.ts.map +0 -1
  105. package/autoscaling/index.js +0 -4
  106. package/autoscaling/index.js.map +0 -1
  107. package/autoscaling/snapshotter.d.ts +0 -189
  108. package/autoscaling/snapshotter.d.ts.map +0 -1
  109. package/autoscaling/snapshotter.js +0 -285
  110. package/autoscaling/snapshotter.js.map +0 -1
  111. package/autoscaling/system_status.d.ts +0 -181
  112. package/autoscaling/system_status.d.ts.map +0 -1
  113. package/autoscaling/system_status.js +0 -169
  114. package/autoscaling/system_status.js.map +0 -1
  115. package/configuration.d.ts.map +0 -1
  116. package/configuration.js.map +0 -1
  117. package/cookie_utils.d.ts +0 -43
  118. package/cookie_utils.d.ts.map +0 -1
  119. package/cookie_utils.js +0 -111
  120. package/cookie_utils.js.map +0 -1
  121. package/crawlers/context_pipeline.d.ts +0 -61
  122. package/crawlers/context_pipeline.d.ts.map +0 -1
  123. package/crawlers/context_pipeline.js +0 -99
  124. package/crawlers/context_pipeline.js.map +0 -1
  125. package/crawlers/crawler_commons.d.ts +0 -191
  126. package/crawlers/crawler_commons.d.ts.map +0 -1
  127. package/crawlers/crawler_commons.js +0 -108
  128. package/crawlers/crawler_commons.js.map +0 -1
  129. package/crawlers/crawler_utils.d.ts +0 -10
  130. package/crawlers/crawler_utils.d.ts.map +0 -1
  131. package/crawlers/crawler_utils.js +0 -12
  132. package/crawlers/crawler_utils.js.map +0 -1
  133. package/crawlers/error_snapshotter.d.ts +0 -60
  134. package/crawlers/error_snapshotter.d.ts.map +0 -1
  135. package/crawlers/error_snapshotter.js +0 -118
  136. package/crawlers/error_snapshotter.js.map +0 -1
  137. package/crawlers/error_tracker.d.ts +0 -55
  138. package/crawlers/error_tracker.d.ts.map +0 -1
  139. package/crawlers/error_tracker.js +0 -309
  140. package/crawlers/error_tracker.js.map +0 -1
  141. package/crawlers/index.d.ts +0 -7
  142. package/crawlers/index.d.ts.map +0 -1
  143. package/crawlers/index.js +0 -7
  144. package/crawlers/index.js.map +0 -1
  145. package/crawlers/internals/types.d.ts +0 -8
  146. package/crawlers/internals/types.d.ts.map +0 -1
  147. package/crawlers/internals/types.js +0 -2
  148. package/crawlers/internals/types.js.map +0 -1
  149. package/crawlers/statistics.d.ts +0 -213
  150. package/crawlers/statistics.d.ts.map +0 -1
  151. package/crawlers/statistics.js +0 -349
  152. package/crawlers/statistics.js.map +0 -1
  153. package/enqueue_links/enqueue_links.d.ts +0 -249
  154. package/enqueue_links/enqueue_links.d.ts.map +0 -1
  155. package/enqueue_links/enqueue_links.js +0 -269
  156. package/enqueue_links/enqueue_links.js.map +0 -1
  157. package/enqueue_links/index.d.ts +0 -3
  158. package/enqueue_links/index.d.ts.map +0 -1
  159. package/enqueue_links/index.js +0 -3
  160. package/enqueue_links/index.js.map +0 -1
  161. package/enqueue_links/shared.d.ts +0 -73
  162. package/enqueue_links/shared.d.ts.map +0 -1
  163. package/enqueue_links/shared.js +0 -212
  164. package/enqueue_links/shared.js.map +0 -1
  165. package/errors.d.ts.map +0 -1
  166. package/errors.js.map +0 -1
  167. package/events/event_manager.d.ts +0 -52
  168. package/events/event_manager.d.ts.map +0 -1
  169. package/events/event_manager.js.map +0 -1
  170. package/events/index.d.ts.map +0 -1
  171. package/events/index.js.map +0 -1
  172. package/events/local_event_manager.d.ts +0 -27
  173. package/events/local_event_manager.d.ts.map +0 -1
  174. package/events/local_event_manager.js +0 -75
  175. package/events/local_event_manager.js.map +0 -1
  176. package/index.d.ts.map +0 -1
  177. package/index.js.map +0 -1
  178. package/log.d.ts.map +0 -1
  179. package/log.js.map +0 -1
  180. package/proxy_configuration.d.ts +0 -169
  181. package/proxy_configuration.d.ts.map +0 -1
  182. package/proxy_configuration.js +0 -247
  183. package/proxy_configuration.js.map +0 -1
  184. package/recoverable_state.d.ts +0 -123
  185. package/recoverable_state.d.ts.map +0 -1
  186. package/recoverable_state.js +0 -140
  187. package/recoverable_state.js.map +0 -1
  188. package/request.d.ts.map +0 -1
  189. package/request.js.map +0 -1
  190. package/router.d.ts +0 -134
  191. package/router.d.ts.map +0 -1
  192. package/router.js +0 -164
  193. package/router.js.map +0 -1
  194. package/serialization.d.ts.map +0 -1
  195. package/serialization.js.map +0 -1
  196. package/session_pool/consts.d.ts +0 -4
  197. package/session_pool/consts.d.ts.map +0 -1
  198. package/session_pool/consts.js +0 -4
  199. package/session_pool/consts.js.map +0 -1
  200. package/session_pool/errors.d.ts +0 -8
  201. package/session_pool/errors.d.ts.map +0 -1
  202. package/session_pool/errors.js +0 -12
  203. package/session_pool/errors.js.map +0 -1
  204. package/session_pool/events.d.ts +0 -3
  205. package/session_pool/events.d.ts.map +0 -1
  206. package/session_pool/events.js +0 -3
  207. package/session_pool/events.js.map +0 -1
  208. package/session_pool/index.d.ts +0 -6
  209. package/session_pool/index.d.ts.map +0 -1
  210. package/session_pool/index.js +0 -6
  211. package/session_pool/index.js.map +0 -1
  212. package/session_pool/session.d.ts +0 -186
  213. package/session_pool/session.d.ts.map +0 -1
  214. package/session_pool/session.js +0 -278
  215. package/session_pool/session.js.map +0 -1
  216. package/session_pool/session_pool.d.ts +0 -258
  217. package/session_pool/session_pool.d.ts.map +0 -1
  218. package/session_pool/session_pool.js +0 -387
  219. package/session_pool/session_pool.js.map +0 -1
  220. package/storages/access_checking.d.ts +0 -13
  221. package/storages/access_checking.d.ts.map +0 -1
  222. package/storages/access_checking.js +0 -14
  223. package/storages/access_checking.js.map +0 -1
  224. package/storages/dataset.d.ts.map +0 -1
  225. package/storages/dataset.js.map +0 -1
  226. package/storages/index.d.ts.map +0 -1
  227. package/storages/index.js.map +0 -1
  228. package/storages/key_value_store.d.ts.map +0 -1
  229. package/storages/key_value_store.js +0 -512
  230. package/storages/key_value_store.js.map +0 -1
  231. package/storages/request_list.d.ts.map +0 -1
  232. package/storages/request_list.js.map +0 -1
  233. package/storages/request_list_adapter.d.ts +0 -58
  234. package/storages/request_list_adapter.d.ts.map +0 -1
  235. package/storages/request_list_adapter.js +0 -81
  236. package/storages/request_list_adapter.js.map +0 -1
  237. package/storages/request_manager_tandem.d.ts +0 -68
  238. package/storages/request_manager_tandem.d.ts.map +0 -1
  239. package/storages/request_manager_tandem.js +0 -124
  240. package/storages/request_manager_tandem.js.map +0 -1
  241. package/storages/request_provider.d.ts.map +0 -1
  242. package/storages/request_provider.js +0 -591
  243. package/storages/request_provider.js.map +0 -1
  244. package/storages/request_queue.d.ts +0 -128
  245. package/storages/request_queue.d.ts.map +0 -1
  246. package/storages/request_queue.js +0 -320
  247. package/storages/request_queue.js.map +0 -1
  248. package/storages/request_queue_v2.d.ts +0 -87
  249. package/storages/request_queue_v2.d.ts.map +0 -1
  250. package/storages/request_queue_v2.js +0 -438
  251. package/storages/request_queue_v2.js.map +0 -1
  252. package/storages/sitemap_request_list.d.ts +0 -250
  253. package/storages/sitemap_request_list.d.ts.map +0 -1
  254. package/storages/sitemap_request_list.js +0 -431
  255. package/storages/sitemap_request_list.js.map +0 -1
  256. package/storages/storage_manager.d.ts +0 -62
  257. package/storages/storage_manager.d.ts.map +0 -1
  258. package/storages/storage_manager.js +0 -105
  259. package/storages/storage_manager.js.map +0 -1
  260. package/storages/utils.d.ts.map +0 -1
  261. package/storages/utils.js.map +0 -1
  262. package/typedefs.d.ts.map +0 -1
  263. package/typedefs.js.map +0 -1
  264. package/validators.d.ts.map +0 -1
  265. package/validators.js.map +0 -1
@@ -1,189 +0,0 @@
1
- import type { StorageClient } from '@crawlee/types';
2
- import type { Log } from '@apify/log';
3
- import type { BetterIntervalID } from '@apify/utilities';
4
- import { Configuration } from '../configuration.js';
5
- import type { EventManager } from '../events/event_manager.js';
6
- import type { SystemInfo } from './system_status.js';
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.9
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
- interface MemorySnapshot {
51
- createdAt: Date;
52
- isOverloaded: boolean;
53
- usedBytes?: number;
54
- }
55
- interface CpuSnapshot {
56
- createdAt: Date;
57
- isOverloaded: boolean;
58
- usedRatio: number;
59
- ticks?: {
60
- idle: number;
61
- total: number;
62
- };
63
- }
64
- interface EventLoopSnapshot {
65
- createdAt: Date;
66
- isOverloaded: boolean;
67
- exceededMillis: number;
68
- }
69
- interface 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 `CRAWLEE_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
- export {};
189
- //# sourceMappingURL=snapshotter.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"snapshotter.d.ts","sourceRoot":"","sources":["../../src/autoscaling/snapshotter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAIpD,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAGzD,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAG/D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAMrD,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,UAAU,cAAc;IACpB,SAAS,EAAE,IAAI,CAAC;IAChB,YAAY,EAAE,OAAO,CAAC;IACtB,SAAS,CAAC,EAAE,MAAM,CAAC;CACtB;AACD,UAAU,WAAW;IACjB,SAAS,EAAE,IAAI,CAAC;IAChB,YAAY,EAAE,OA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oBAAoB,CAAC,EAAE,MAAM;IAI7C;;;OAGG;IACH,kBAAkB,CAAC,oBAAoB,CAAC,EAAE,MAAM;IAIhD;;;OAGG;IACH,YAAY,CAAC,oBAAoB,CAAC,EAAE,MAAM;IAI1C;;;OAGG;IACH,eAAe,CAAC,oBAAoB,CAAC,EAAE,MAAM;IAI7C;;OAEG;IACH,SAAS,CAAC,UAAU,CAAC,CAAC,SAAS;QAAE,SAAS,EAAE,IAAI,CAAA;KAAE,EAAE,SAAS,EAAE,CAAC,EAAE,EAAE,oBAAoB,CAAC,EAAE,MAAM,GAAG,CAAC,EAAE;IAoBvG;;;OAGG;IACH,SAAS,CAAC,eAAe,CAAC,UAAU,EAAE,UAAU;IAchD;;OAEG;IACH,SAAS,CAAC,sBAAsB,CAAC,UAAU,EAAE,UAAU;IA2BvD;;OAEG;IACH,SAAS,CAAC,kBAAkB,CAAC,gBAAgB,EAAE,MAAM,OAAO;IAuB5D;;OAEG;IACH,SAAS,CAAC,YAAY,CAAC,UAAU,EAAE,UAAU;IAY7C;;;;;;;OAOG;IACH,SAAS,CAAC,eAAe,CAAC,gBAAgB,EAAE,MAAM,OAAO;IAwBzD;;;OAGG;IACH,SAAS,CAAC,eAAe,CACrB,SAAS,EAAE,cAAc,EAAE,GAAG,WAAW,EAAE,GAAG,iBAAiB,EAAE,GAAG,cAAc,EAAE,EACpF,GAAG,EAAE,IAAI;CAUhB"}
@@ -1,285 +0,0 @@
1
- import { getMemoryInfo, isContainerized } from '@crawlee/utils';
2
- import ow from 'ow';
3
- import { betterClearInterval, betterSetInterval } from '@apify/utilities';
4
- import { Configuration } from '../configuration.js';
5
- import { log as defaultLog } from '../log.js';
6
- const RESERVE_MEMORY_RATIO = 0.5;
7
- const CLIENT_RATE_LIMIT_ERROR_RETRY_COUNT = 2;
8
- const CRITICAL_OVERLOAD_RATE_LIMIT_MILLIS = 10000;
9
- /**
10
- * Creates snapshots of system resources at given intervals and marks the resource
11
- * as either overloaded or not during the last interval. Keeps a history of the snapshots.
12
- * It tracks the following resources: Memory, EventLoop, API and CPU.
13
- * The class is used by the {@link AutoscaledPool} class.
14
- *
15
- * When running on the Apify platform, the CPU and memory statistics are provided by the platform,
16
- * as collected from the running Docker container. When running locally, `Snapshotter`
17
- * makes its own statistics by querying the OS.
18
- *
19
- * CPU becomes overloaded locally when its current use exceeds the `maxUsedCpuRatio` option or
20
- * when Apify platform marks it as overloaded.
21
- *
22
- * Memory becomes overloaded if its current use exceeds the `maxUsedMemoryRatio` option.
23
- * It's computed using the total memory available to the container when running on
24
- * the Apify platform and a quarter of total system memory when running locally.
25
- * Max total memory when running locally may be overridden by using the `CRAWLEE_MEMORY_MBYTES`
26
- * environment variable.
27
- *
28
- * Event loop becomes overloaded if it slows down by more than the `maxBlockedMillis` option.
29
- *
30
- * Client becomes overloaded when rate limit errors (429 - Too Many Requests),
31
- * typically received from the request queue, exceed the set limit within the set interval.
32
- * @category Scaling
33
- */
34
- export class Snapshotter {
35
- log;
36
- client;
37
- config;
38
- events;
39
- eventLoopSnapshotIntervalMillis;
40
- clientSnapshotIntervalMillis;
41
- snapshotHistoryMillis;
42
- maxBlockedMillis;
43
- maxUsedMemoryRatio;
44
- maxClientErrors;
45
- maxMemoryBytes;
46
- cpuSnapshots = [];
47
- eventLoopSnapshots = [];
48
- memorySnapshots = [];
49
- clientSnapshots = [];
50
- eventLoopInterval = null;
51
- clientInterval = null;
52
- lastLoggedCriticalMemoryOverloadAt = null;
53
- /**
54
- * @param [options] All `Snapshotter` configuration options.
55
- */
56
- constructor(options = {}) {
57
- ow(options, ow.object.exactShape({
58
- eventLoopSnapshotIntervalSecs: ow.optional.number,
59
- clientSnapshotIntervalSecs: ow.optional.number,
60
- snapshotHistorySecs: ow.optional.number,
61
- maxBlockedMillis: ow.optional.number,
62
- maxUsedMemoryRatio: ow.optional.number,
63
- maxClientErrors: ow.optional.number,
64
- log: ow.optional.object,
65
- client: ow.optional.object,
66
- config: ow.optional.object,
67
- }));
68
- const { eventLoopSnapshotIntervalSecs = 0.5, clientSnapshotIntervalSecs = 1, snapshotHistorySecs = 30, maxBlockedMillis = 50, maxUsedMemoryRatio = 0.9, maxClientErrors = 3, log = defaultLog, config = Configuration.getGlobalConfig(), client = config.getStorageClient(), } = options;
69
- this.log = log.child({ prefix: 'Snapshotter' });
70
- this.client = client;
71
- this.config = config;
72
- this.events = this.config.getEventManager();
73
- this.eventLoopSnapshotIntervalMillis = eventLoopSnapshotIntervalSecs * 1000;
74
- this.clientSnapshotIntervalMillis = clientSnapshotIntervalSecs * 1000;
75
- this.snapshotHistoryMillis = snapshotHistorySecs * 1000;
76
- this.maxBlockedMillis = maxBlockedMillis;
77
- this.maxUsedMemoryRatio = maxUsedMemoryRatio;
78
- this.maxClientErrors = maxClientErrors;
79
- // We need to pre-bind those functions to be able to successfully remove listeners.
80
- this._snapshotCpu = this._snapshotCpu.bind(this);
81
- this._snapshotMemory = this._snapshotMemory.bind(this);
82
- }
83
- /**
84
- * Starts capturing snapshots at configured intervals.
85
- */
86
- async start() {
87
- const memoryMbytes = this.config.get('memoryMbytes', 0);
88
- if (memoryMbytes > 0) {
89
- this.maxMemoryBytes = memoryMbytes * 1024 * 1024;
90
- }
91
- else {
92
- const containerized = this.config.get('containerized', await isContainerized());
93
- const memInfo = await getMemoryInfo(containerized);
94
- const totalBytes = memInfo.totalBytes;
95
- this.maxMemoryBytes = Math.ceil(totalBytes * this.config.get('availableMemoryRatio'));
96
- this.log.debug(`Setting max memory of this run to ${Math.round(this.maxMemoryBytes / 1024 / 1024)} MB. ` +
97
- 'Use the CRAWLEE_MEMORY_MBYTES or CRAWLEE_AVAILABLE_MEMORY_RATIO environment variable to override it.');
98
- }
99
- // Start snapshotting.
100
- this.eventLoopInterval = betterSetInterval(this._snapshotEventLoop.bind(this), this.eventLoopSnapshotIntervalMillis);
101
- this.clientInterval = betterSetInterval(this._snapshotClient.bind(this), this.clientSnapshotIntervalMillis);
102
- this.events.on("systemInfo" /* EventType.SYSTEM_INFO */, this._snapshotCpu);
103
- this.events.on("systemInfo" /* EventType.SYSTEM_INFO */, this._snapshotMemory);
104
- }
105
- /**
106
- * Stops all resource capturing.
107
- */
108
- async stop() {
109
- betterClearInterval(this.eventLoopInterval);
110
- betterClearInterval(this.clientInterval);
111
- this.events.off("systemInfo" /* EventType.SYSTEM_INFO */, this._snapshotCpu);
112
- this.events.off("systemInfo" /* EventType.SYSTEM_INFO */, this._snapshotMemory);
113
- // Allow microtask queue to unwind before stop returns.
114
- await new Promise((resolve) => {
115
- setImmediate(resolve);
116
- });
117
- }
118
- /**
119
- * Returns a sample of latest memory snapshots, with the size of the sample defined
120
- * by the sampleDurationMillis parameter. If omitted, it returns a full snapshot history.
121
- */
122
- getMemorySample(sampleDurationMillis) {
123
- return this._getSample(this.memorySnapshots, sampleDurationMillis);
124
- }
125
- /**
126
- * Returns a sample of latest event loop snapshots, with the size of the sample defined
127
- * by the sampleDurationMillis parameter. If omitted, it returns a full snapshot history.
128
- */
129
- getEventLoopSample(sampleDurationMillis) {
130
- return this._getSample(this.eventLoopSnapshots, sampleDurationMillis);
131
- }
132
- /**
133
- * Returns a sample of latest CPU snapshots, with the size of the sample defined
134
- * by the sampleDurationMillis parameter. If omitted, it returns a full snapshot history.
135
- */
136
- getCpuSample(sampleDurationMillis) {
137
- return this._getSample(this.cpuSnapshots, sampleDurationMillis);
138
- }
139
- /**
140
- * Returns a sample of latest Client snapshots, with the size of the sample defined
141
- * by the sampleDurationMillis parameter. If omitted, it returns a full snapshot history.
142
- */
143
- getClientSample(sampleDurationMillis) {
144
- return this._getSample(this.clientSnapshots, sampleDurationMillis);
145
- }
146
- /**
147
- * Finds the latest snapshots by sampleDurationMillis in the provided array.
148
- */
149
- _getSample(snapshots, sampleDurationMillis) {
150
- if (!sampleDurationMillis)
151
- return snapshots;
152
- const sample = [];
153
- let idx = snapshots.length;
154
- if (!idx)
155
- return sample;
156
- const latestTime = snapshots[idx - 1].createdAt;
157
- while (idx--) {
158
- const snapshot = snapshots[idx];
159
- if (+latestTime - +snapshot.createdAt <= sampleDurationMillis) {
160
- sample.unshift(snapshot);
161
- }
162
- else {
163
- break;
164
- }
165
- }
166
- return sample;
167
- }
168
- /**
169
- * Creates a snapshot of current memory usage
170
- * using the Apify platform `systemInfo` event.
171
- */
172
- _snapshotMemory(systemInfo) {
173
- const createdAt = systemInfo.createdAt ? new Date(systemInfo.createdAt) : new Date();
174
- this._pruneSnapshots(this.memorySnapshots, createdAt);
175
- const { memCurrentBytes } = systemInfo;
176
- const snapshot = {
177
- createdAt,
178
- isOverloaded: memCurrentBytes / this.maxMemoryBytes > this.maxUsedMemoryRatio,
179
- usedBytes: memCurrentBytes,
180
- };
181
- this.memorySnapshots.push(snapshot);
182
- this._memoryOverloadWarning(systemInfo);
183
- }
184
- /**
185
- * Checks for critical memory overload and logs it to the console.
186
- */
187
- _memoryOverloadWarning(systemInfo) {
188
- const { memCurrentBytes } = systemInfo;
189
- const createdAt = systemInfo.createdAt ? new Date(systemInfo.createdAt) : new Date();
190
- if (this.lastLoggedCriticalMemoryOverloadAt &&
191
- +createdAt < +this.lastLoggedCriticalMemoryOverloadAt + CRITICAL_OVERLOAD_RATE_LIMIT_MILLIS)
192
- return;
193
- const maxDesiredMemoryBytes = this.maxUsedMemoryRatio * this.maxMemoryBytes;
194
- const reserveMemory = this.maxMemoryBytes * (1 - this.maxUsedMemoryRatio) * RESERVE_MEMORY_RATIO;
195
- const criticalOverloadBytes = maxDesiredMemoryBytes + reserveMemory;
196
- const isCriticalOverload = memCurrentBytes > criticalOverloadBytes;
197
- if (isCriticalOverload) {
198
- const usedPercentage = Math.round((memCurrentBytes / this.maxMemoryBytes) * 100);
199
- const toMb = (bytes) => Math.round(bytes / 1024 ** 2);
200
- this.log.warning('Memory is critically overloaded. ' +
201
- `Using ${toMb(memCurrentBytes)} MB of ${toMb(this.maxMemoryBytes)} MB (${usedPercentage}%). Consider increasing available memory.`);
202
- this.lastLoggedCriticalMemoryOverloadAt = createdAt;
203
- }
204
- }
205
- /**
206
- * Creates a snapshot of current event loop delay.
207
- */
208
- _snapshotEventLoop(intervalCallback) {
209
- const now = new Date();
210
- this._pruneSnapshots(this.eventLoopSnapshots, now);
211
- const snapshot = {
212
- createdAt: now,
213
- isOverloaded: false,
214
- exceededMillis: 0,
215
- };
216
- const previousSnapshot = this.eventLoopSnapshots[this.eventLoopSnapshots.length - 1];
217
- if (previousSnapshot) {
218
- const { createdAt } = previousSnapshot;
219
- const delta = now.getTime() - +createdAt - this.eventLoopSnapshotIntervalMillis;
220
- if (delta > this.maxBlockedMillis)
221
- snapshot.isOverloaded = true;
222
- snapshot.exceededMillis = Math.max(delta - this.maxBlockedMillis, 0);
223
- }
224
- this.eventLoopSnapshots.push(snapshot);
225
- intervalCallback();
226
- }
227
- /**
228
- * Creates a snapshot of current CPU usage using the Apify platform `systemInfo` event.
229
- */
230
- _snapshotCpu(systemInfo) {
231
- const { cpuCurrentUsage, isCpuOverloaded } = systemInfo;
232
- const createdAt = systemInfo.createdAt ? new Date(systemInfo.createdAt) : new Date();
233
- this._pruneSnapshots(this.cpuSnapshots, createdAt);
234
- this.cpuSnapshots.push({
235
- createdAt,
236
- isOverloaded: isCpuOverloaded,
237
- usedRatio: Math.ceil(cpuCurrentUsage / 100),
238
- });
239
- }
240
- /**
241
- * Creates a snapshot of current API state by checking for
242
- * rate limit errors. Only errors produced by a 2nd retry
243
- * of the API call are considered for snapshotting since
244
- * earlier errors may just be caused by a random spike in
245
- * number of requests and do not necessarily signify API
246
- * overloading.
247
- */
248
- _snapshotClient(intervalCallback) {
249
- const now = new Date();
250
- this._pruneSnapshots(this.clientSnapshots, now);
251
- const allErrorCounts = this.client.stats?.rateLimitErrors ?? []; // storage client might not support this
252
- const currentErrCount = allErrorCounts[CLIENT_RATE_LIMIT_ERROR_RETRY_COUNT] || 0;
253
- // Handle empty snapshots array
254
- const snapshot = {
255
- createdAt: now,
256
- isOverloaded: false,
257
- rateLimitErrorCount: currentErrCount,
258
- };
259
- const previousSnapshot = this.clientSnapshots[this.clientSnapshots.length - 1];
260
- if (previousSnapshot) {
261
- const { rateLimitErrorCount } = previousSnapshot;
262
- const delta = currentErrCount - rateLimitErrorCount;
263
- if (delta > this.maxClientErrors)
264
- snapshot.isOverloaded = true;
265
- }
266
- this.clientSnapshots.push(snapshot);
267
- intervalCallback();
268
- }
269
- /**
270
- * Removes snapshots that are older than the snapshotHistorySecs option
271
- * from the array (destructively - in place).
272
- */
273
- _pruneSnapshots(snapshots, now) {
274
- let oldCount = 0;
275
- for (let i = 0; i < snapshots.length; i++) {
276
- const { createdAt } = snapshots[i];
277
- if (now.getTime() - new Date(createdAt).getTime() > this.snapshotHistoryMillis)
278
- oldCount++;
279
- else
280
- break;
281
- }
282
- snapshots.splice(0, oldCount);
283
- }
284
- }
285
- //# sourceMappingURL=snapshotter.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"snapshotter.js","sourceRoot":"","sources":["../../src/autoscaling/snapshotter.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAChE,OAAO,EAAE,MAAM,IAAI,CAAC;AAIpB,OAAO,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAE1E,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAGpD,OAAO,EAAE,GAAG,IAAI,UAAU,EAAE,MAAM,WAAW,CAAC;AAG9C,MAAM,oBAAoB,GAAG,GAAG,CAAC;AACjC,MAAM,mCAAmC,GAAG,CAAC,CAAC;AAC9C,MAAM,mCAAmC,GAAG,KAAK,CAAC;AA4ElD;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAM,OAAO,WAAW;IACpB,GAAG,CAAM;IACT,MAAM,CAAgB;IACtB,MAAM,CAAgB;IACtB,MAAM,CAAe;IACrB,+BAA+B,CAAS;IACxC,4BAA4B,CAAS;IACrC,qBAAqB,CAAS;IAC9B,gBAAgB,CAAS;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C;QACnE,CAAC;QAED,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QACpC,gBAAgB,EAAE,CAAC;IACvB,CAAC;IAED;;;OAGG;IACO,eAAe,CACrB,SAAoF,EACpF,GAAS;QAET,IAAI,QAAQ,GAAG,CAAC,CAAC;QACjB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,SAAS,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;YACxC,MAAM,EAAE,SAAS,EAAE,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC;YACnC,IAAI,GAAG,CAAC,OAAO,EAAE,GAAG,IAAI,IAAI,CAAC,SAAS,CAAC,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,qBAAqB;gBAAE,QAAQ,EAAE,CAAC;;gBACtF,MAAM;QACf,CAAC;QACD,SAAS,CAAC,MAAM,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC;IAClC,CAAC;CACJ"}
@@ -1,181 +0,0 @@
1
- import type { Configuration } from '../configuration.js';
2
- import { Snapshotter } from './snapshotter.js';
3
- /**
4
- * Represents the current status of the system.
5
- */
6
- export interface SystemInfo {
7
- /** If false, system is being overloaded. */
8
- isSystemIdle: boolean;
9
- memInfo: ClientInfo;
10
- eventLoopInfo: ClientInfo;
11
- cpuInfo: ClientInfo;
12
- clientInfo: ClientInfo;
13
- memCurrentBytes?: number;
14
- /**
15
- * Platform only property
16
- * @internal
17
- */
18
- cpuCurrentUsage?: number;
19
- /**
20
- * Platform only property
21
- * @internal
22
- */
23
- isCpuOverloaded?: boolean;
24
- /**
25
- * Platform only property
26
- * @internal
27
- */
28
- createdAt?: Date;
29
- }
30
- export interface SystemStatusOptions {
31
- /**
32
- * Defines max age of snapshots used in the {@link SystemStatus.getCurrentStatus} measurement.
33
- * @default 5
34
- */
35
- currentHistorySecs?: number;
36
- /**
37
- * Sets the maximum ratio of overloaded snapshots in a memory sample.
38
- * If the sample exceeds this ratio, the system will be overloaded.
39
- * @default 0.2
40
- */
41
- maxMemoryOverloadedRatio?: number;
42
- /**
43
- * Sets the maximum ratio of overloaded snapshots in an event loop sample.
44
- * If the sample exceeds this ratio, the system will be overloaded.
45
- * @default 0.6
46
- */
47
- maxEventLoopOverloadedRatio?: number;
48
- /**
49
- * Sets the maximum ratio of overloaded snapshots in a CPU sample.
50
- * If the sample exceeds this ratio, the system will be overloaded.
51
- * @default 0.4
52
- */
53
- maxCpuOverloadedRatio?: number;
54
- /**
55
- * Sets the maximum ratio of overloaded snapshots in a Client sample.
56
- * If the sample exceeds this ratio, the system will be overloaded.
57
- * @default 0.3
58
- */
59
- maxClientOverloadedRatio?: number;
60
- /**
61
- * The `Snapshotter` instance to be queried for `SystemStatus`.
62
- */
63
- snapshotter?: Snapshotter;
64
- /** @internal */
65
- config?: Configuration;
66
- }
67
- export interface ClientInfo {
68
- isOverloaded: boolean;
69
- limitRatio: number;
70
- actualRatio: number;
71
- }
72
- export interface FinalStatistics {
73
- requestsFinished: number;
74
- requestsFailed: number;
75
- retryHistogram: number[];
76
- requestAvgFailedDurationMillis: number;
77
- requestAvgFinishedDurationMillis: number;
78
- requestsFinishedPerMinute: number;
79
- requestsFailedPerMinute: number;
80
- requestTotalDurationMillis: number;
81
- requestsTotal: number;
82
- crawlerRuntimeMillis: number;
83
- }
84
- /**
85
- * Provides a simple interface to reading system status from a {@link Snapshotter} instance.
86
- * It only exposes two functions {@link SystemStatus.getCurrentStatus}
87
- * and {@link SystemStatus.getHistoricalStatus}.
88
- * The system status is calculated using a weighted average of overloaded
89
- * messages in the snapshots, with the weights being the time intervals
90
- * between the snapshots. Each resource is calculated separately
91
- * and the system is overloaded whenever at least one resource is overloaded.
92
- * The class is used by the {@link AutoscaledPool} class.
93
- *
94
- * {@link SystemStatus.getCurrentStatus}
95
- * returns a boolean that represents the current status of the system.
96
- * The length of the current timeframe in seconds is configurable
97
- * by the `currentHistorySecs` option and represents the max age
98
- * of snapshots to be considered for the calculation.
99
- *
100
- * {@link SystemStatus.getHistoricalStatus}
101
- * returns a boolean that represents the long-term status
102
- * of the system. It considers the full snapshot history available
103
- * in the {@link Snapshotter} instance.
104
- * @category Scaling
105
- */
106
- export declare class SystemStatus {
107
- private readonly currentHistoryMillis;
108
- private readonly maxMemoryOverloadedRatio;
109
- private readonly maxEventLoopOverloadedRatio;
110
- private readonly maxCpuOverloadedRatio;
111
- private readonly maxClientOverloadedRatio;
112
- private readonly snapshotter;
113
- constructor(options?: SystemStatusOptions);
114
- /**
115
- * Returns an {@link SystemInfo} object with the following structure:
116
- *
117
- * ```javascript
118
- * {
119
- * isSystemIdle: Boolean,
120
- * memInfo: Object,
121
- * eventLoopInfo: Object,
122
- * cpuInfo: Object
123
- * }
124
- * ```
125
- *
126
- * Where the `isSystemIdle` property is set to `false` if the system
127
- * has been overloaded in the last `options.currentHistorySecs` seconds,
128
- * and `true` otherwise.
129
- */
130
- getCurrentStatus(): SystemInfo;
131
- /**
132
- * Returns an {@link SystemInfo} object with the following structure:
133
- *
134
- * ```javascript
135
- * {
136
- * isSystemIdle: Boolean,
137
- * memInfo: Object,
138
- * eventLoopInfo: Object,
139
- * cpuInfo: Object
140
- * }
141
- * ```
142
- *
143
- * Where the `isSystemIdle` property is set to `false` if the system
144
- * has been overloaded in the full history of the {@link Snapshotter}
145
- * (which is configurable in the {@link Snapshotter}) and `true` otherwise.
146
- */
147
- getHistoricalStatus(): SystemInfo;
148
- /**
149
- * Returns a system status object.
150
- */
151
- protected _isSystemIdle(sampleDurationMillis?: number): SystemInfo;
152
- /**
153
- * Returns an object with an isOverloaded property set to true
154
- * if the memory has been overloaded in the last sampleDurationMillis.
155
- */
156
- protected _isMemoryOverloaded(sampleDurationMillis?: number): ClientInfo;
157
- /**
158
- * Returns an object with an isOverloaded property set to true
159
- * if the event loop has been overloaded in the last sampleDurationMillis.
160
- */
161
- protected _isEventLoopOverloaded(sampleDurationMillis?: number): ClientInfo;
162
- /**
163
- * Returns an object with an isOverloaded property set to true
164
- * if the CPU has been overloaded in the last sampleDurationMillis.
165
- */
166
- protected _isCpuOverloaded(sampleDurationMillis?: number): ClientInfo;
167
- /**
168
- * Returns an object with an isOverloaded property set to true
169
- * if the client has been overloaded in the last sampleDurationMillis.
170
- */
171
- protected _isClientOverloaded(sampleDurationMillis?: number): ClientInfo;
172
- /**
173
- * Returns an object with sample information and an isOverloaded property
174
- * set to true if at least the ratio of snapshots in the sample are overloaded.
175
- */
176
- protected _isSampleOverloaded<T extends {
177
- createdAt: Date;
178
- isOverloaded: boolean;
179
- }>(sample: T[], ratio: number): ClientInfo;
180
- }
181
- //# sourceMappingURL=system_status.d.ts.map