@crawlee/core 4.0.0-beta.15 → 4.0.0-beta.150
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/README.md +14 -14
- package/autoscaling/autoscaled_pool.d.ts +73 -177
- package/autoscaling/autoscaled_pool.js +182 -329
- package/autoscaling/concurrency_system.d.ts +268 -0
- package/autoscaling/concurrency_system.js +364 -0
- package/autoscaling/cpu_load_signal.d.ts +43 -0
- package/autoscaling/cpu_load_signal.js +47 -0
- package/autoscaling/event_loop_load_signal.d.ts +51 -0
- package/autoscaling/event_loop_load_signal.js +60 -0
- package/autoscaling/index.d.ts +6 -1
- package/autoscaling/index.js +6 -1
- package/autoscaling/load_signal.d.ts +98 -0
- package/autoscaling/load_signal.js +103 -0
- package/autoscaling/memory_load_signal.d.ts +47 -0
- package/autoscaling/memory_load_signal.js +106 -0
- package/autoscaling/snapshotter.d.ts +58 -163
- package/autoscaling/snapshotter.js +45 -263
- package/autoscaling/storage_backend_load_signal.d.ts +56 -0
- package/autoscaling/storage_backend_load_signal.js +73 -0
- package/autoscaling/system_status.d.ts +67 -89
- package/autoscaling/system_status.js +92 -122
- package/autoscaling/weighted_avg.d.ts +5 -0
- package/autoscaling/weighted_avg.js +14 -0
- package/byte_utils.d.ts +17 -0
- package/byte_utils.js +42 -0
- package/configuration.d.ts +96 -223
- package/configuration.js +170 -222
- package/cookie_utils.d.ts +3 -2
- package/cookie_utils.js +18 -7
- package/crawlers/context_pipeline.d.ts +10 -1
- package/crawlers/context_pipeline.js +31 -8
- package/crawlers/crawler_commons.d.ts +90 -126
- package/crawlers/crawler_commons.js +1 -108
- package/crawlers/error_snapshotter.d.ts +2 -5
- package/crawlers/error_snapshotter.js +7 -8
- package/crawlers/error_tracker.d.ts +0 -1
- package/crawlers/error_tracker.js +0 -1
- package/crawlers/index.d.ts +1 -3
- package/crawlers/index.js +0 -3
- package/crawlers/internals/types.d.ts +0 -1
- package/crawlers/internals/types.js +0 -1
- package/crawlers/statistics.d.ts +187 -64
- package/crawlers/statistics.js +354 -165
- package/debug.d.ts +36 -0
- package/debug.js +70 -0
- package/enqueue_links/enqueue_links.d.ts +61 -154
- package/enqueue_links/enqueue_links.js +40 -232
- package/enqueue_links/index.d.ts +0 -1
- package/enqueue_links/index.js +0 -1
- package/enqueue_links/shared.d.ts +55 -28
- package/enqueue_links/shared.js +116 -69
- package/errors.d.ts +72 -4
- package/errors.js +89 -5
- package/events/event_manager.d.ts +35 -9
- package/events/event_manager.js +12 -13
- package/events/index.d.ts +0 -1
- package/events/index.js +0 -1
- package/events/local_event_manager.d.ts +15 -3
- package/events/local_event_manager.js +39 -13
- package/http.d.ts +9 -0
- package/http.js +28 -0
- package/index.d.ts +7 -5
- package/index.js +8 -4
- package/iterables.d.ts +79 -0
- package/iterables.js +134 -0
- package/log.d.ts +77 -1
- package/log.js +104 -1
- package/memory-storage/consts.d.ts +4 -0
- package/memory-storage/consts.js +4 -0
- package/memory-storage/index.d.ts +1 -0
- package/memory-storage/index.js +1 -0
- package/memory-storage/memory-storage.d.ts +44 -0
- package/memory-storage/memory-storage.js +160 -0
- package/memory-storage/resource-clients/common/base-client.d.ts +4 -0
- package/memory-storage/resource-clients/common/base-client.js +6 -0
- package/memory-storage/resource-clients/dataset.d.ts +40 -0
- package/memory-storage/resource-clients/dataset.js +106 -0
- package/memory-storage/resource-clients/key-value-store.d.ts +63 -0
- package/memory-storage/resource-clients/key-value-store.js +199 -0
- package/memory-storage/resource-clients/request-queue.d.ts +77 -0
- package/memory-storage/resource-clients/request-queue.js +407 -0
- package/memory-storage/utils.d.ts +16 -0
- package/memory-storage/utils.js +41 -0
- package/owned_or_injected.d.ts +58 -0
- package/owned_or_injected.js +98 -0
- package/package.json +13 -12
- package/proxy_configuration.d.ts +22 -128
- package/proxy_configuration.js +32 -144
- package/recoverable_state.d.ts +83 -51
- package/recoverable_state.js +163 -72
- package/request.d.ts +57 -16
- package/request.js +130 -69
- package/router.d.ts +193 -21
- package/router.js +188 -43
- package/serialization.d.ts +0 -1
- package/serialization.js +15 -15
- package/service_locator.d.ts +165 -0
- package/service_locator.js +253 -0
- package/session_pool/consts.d.ts +1 -2
- package/session_pool/consts.js +1 -2
- package/session_pool/errors.d.ts +0 -1
- package/session_pool/errors.js +0 -1
- package/session_pool/fingerprint.d.ts +9 -0
- package/session_pool/fingerprint.js +30 -0
- package/session_pool/index.d.ts +0 -2
- package/session_pool/index.js +0 -2
- package/session_pool/session.d.ts +39 -89
- package/session_pool/session.js +102 -159
- package/session_pool/session_pool.d.ts +67 -91
- package/session_pool/session_pool.js +196 -187
- package/storages/batched_adds.d.ts +37 -0
- package/storages/batched_adds.js +73 -0
- package/storages/dataset.d.ts +109 -56
- package/storages/dataset.js +284 -149
- package/storages/index.d.ts +9 -9
- package/storages/index.js +7 -9
- package/storages/key_value_store.d.ts +183 -48
- package/storages/key_value_store.js +444 -171
- package/storages/key_value_store_codec.d.ts +32 -0
- package/storages/key_value_store_codec.js +113 -0
- package/storages/request_dedup_cache.d.ts +22 -0
- package/storages/request_dedup_cache.js +48 -0
- package/storages/request_list.d.ts +53 -115
- package/storages/request_list.js +194 -167
- package/storages/request_loader.d.ts +133 -0
- package/storages/request_loader.js +36 -0
- package/storages/request_manager.d.ts +109 -0
- package/storages/request_manager.js +1 -0
- package/storages/request_manager_tandem.d.ts +55 -23
- package/storages/request_manager_tandem.js +139 -57
- package/storages/request_queue.d.ts +286 -48
- package/storages/request_queue.js +757 -218
- package/storages/{sitemap_request_list.d.ts → sitemap_request_loader.d.ts} +43 -91
- package/storages/sitemap_request_loader.js +439 -0
- package/storages/storage_instance_manager.d.ts +87 -0
- package/storages/storage_instance_manager.js +256 -0
- package/storages/storage_stats.d.ts +48 -0
- package/storages/storage_stats.js +29 -0
- package/storages/throttling_request_manager.d.ts +222 -0
- package/storages/throttling_request_manager.js +780 -0
- package/storages/transaction.d.ts +252 -0
- package/storages/transaction.js +251 -0
- package/storages/utils.d.ts +59 -11
- package/storages/utils.js +75 -15
- package/system-info/cpu-info.d.ts +67 -0
- package/system-info/cpu-info.js +216 -0
- package/system-info/memory-info.d.ts +31 -0
- package/system-info/memory-info.js +115 -0
- package/system-info/ps-tree.d.ts +17 -0
- package/system-info/ps-tree.js +144 -0
- package/system-info/runtime.d.ts +14 -0
- package/system-info/runtime.js +80 -0
- package/typedefs.d.ts +0 -6
- package/typedefs.js +0 -1
- package/url.d.ts +9 -0
- package/url.js +11 -0
- package/validators.d.ts +22 -18
- package/validators.js +13 -18
- package/autoscaling/autoscaled_pool.d.ts.map +0 -1
- package/autoscaling/autoscaled_pool.js.map +0 -1
- package/autoscaling/index.d.ts.map +0 -1
- package/autoscaling/index.js.map +0 -1
- package/autoscaling/snapshotter.d.ts.map +0 -1
- package/autoscaling/snapshotter.js.map +0 -1
- package/autoscaling/system_status.d.ts.map +0 -1
- package/autoscaling/system_status.js.map +0 -1
- package/configuration.d.ts.map +0 -1
- package/configuration.js.map +0 -1
- package/cookie_utils.d.ts.map +0 -1
- package/cookie_utils.js.map +0 -1
- package/crawlers/context_pipeline.d.ts.map +0 -1
- package/crawlers/context_pipeline.js.map +0 -1
- package/crawlers/crawler_commons.d.ts.map +0 -1
- package/crawlers/crawler_commons.js.map +0 -1
- package/crawlers/crawler_utils.d.ts +0 -10
- package/crawlers/crawler_utils.d.ts.map +0 -1
- package/crawlers/crawler_utils.js +0 -12
- package/crawlers/crawler_utils.js.map +0 -1
- package/crawlers/error_snapshotter.d.ts.map +0 -1
- package/crawlers/error_snapshotter.js.map +0 -1
- package/crawlers/error_tracker.d.ts.map +0 -1
- package/crawlers/error_tracker.js.map +0 -1
- package/crawlers/index.d.ts.map +0 -1
- package/crawlers/index.js.map +0 -1
- package/crawlers/internals/types.d.ts.map +0 -1
- package/crawlers/internals/types.js.map +0 -1
- package/crawlers/statistics.d.ts.map +0 -1
- package/crawlers/statistics.js.map +0 -1
- package/enqueue_links/enqueue_links.d.ts.map +0 -1
- package/enqueue_links/enqueue_links.js.map +0 -1
- package/enqueue_links/index.d.ts.map +0 -1
- package/enqueue_links/index.js.map +0 -1
- package/enqueue_links/shared.d.ts.map +0 -1
- package/enqueue_links/shared.js.map +0 -1
- package/errors.d.ts.map +0 -1
- package/errors.js.map +0 -1
- package/events/event_manager.d.ts.map +0 -1
- package/events/event_manager.js.map +0 -1
- package/events/index.d.ts.map +0 -1
- package/events/index.js.map +0 -1
- package/events/local_event_manager.d.ts.map +0 -1
- package/events/local_event_manager.js.map +0 -1
- package/http_clients/base-http-client.d.ts +0 -140
- package/http_clients/base-http-client.d.ts.map +0 -1
- package/http_clients/base-http-client.js +0 -40
- package/http_clients/base-http-client.js.map +0 -1
- package/http_clients/form-data-like.d.ts +0 -67
- package/http_clients/form-data-like.d.ts.map +0 -1
- package/http_clients/form-data-like.js +0 -5
- package/http_clients/form-data-like.js.map +0 -1
- package/http_clients/got-scraping-http-client.d.ts +0 -20
- package/http_clients/got-scraping-http-client.d.ts.map +0 -1
- package/http_clients/got-scraping-http-client.js +0 -85
- package/http_clients/got-scraping-http-client.js.map +0 -1
- package/http_clients/index.d.ts +0 -3
- package/http_clients/index.d.ts.map +0 -1
- package/http_clients/index.js +0 -3
- package/http_clients/index.js.map +0 -1
- package/index.d.ts.map +0 -1
- package/index.js.map +0 -1
- package/log.d.ts.map +0 -1
- package/log.js.map +0 -1
- package/proxy_configuration.d.ts.map +0 -1
- package/proxy_configuration.js.map +0 -1
- package/recoverable_state.d.ts.map +0 -1
- package/recoverable_state.js.map +0 -1
- package/request.d.ts.map +0 -1
- package/request.js.map +0 -1
- package/router.d.ts.map +0 -1
- package/router.js.map +0 -1
- package/serialization.d.ts.map +0 -1
- package/serialization.js.map +0 -1
- package/session_pool/consts.d.ts.map +0 -1
- package/session_pool/consts.js.map +0 -1
- package/session_pool/errors.d.ts.map +0 -1
- package/session_pool/errors.js.map +0 -1
- package/session_pool/events.d.ts +0 -3
- package/session_pool/events.d.ts.map +0 -1
- package/session_pool/events.js +0 -3
- package/session_pool/events.js.map +0 -1
- package/session_pool/index.d.ts.map +0 -1
- package/session_pool/index.js.map +0 -1
- package/session_pool/session.d.ts.map +0 -1
- package/session_pool/session.js.map +0 -1
- package/session_pool/session_pool.d.ts.map +0 -1
- package/session_pool/session_pool.js.map +0 -1
- package/storages/access_checking.d.ts +0 -13
- package/storages/access_checking.d.ts.map +0 -1
- package/storages/access_checking.js +0 -14
- package/storages/access_checking.js.map +0 -1
- package/storages/dataset.d.ts.map +0 -1
- package/storages/dataset.js.map +0 -1
- package/storages/index.d.ts.map +0 -1
- package/storages/index.js.map +0 -1
- package/storages/key_value_store.d.ts.map +0 -1
- package/storages/key_value_store.js.map +0 -1
- package/storages/request_list.d.ts.map +0 -1
- package/storages/request_list.js.map +0 -1
- package/storages/request_list_adapter.d.ts +0 -58
- package/storages/request_list_adapter.d.ts.map +0 -1
- package/storages/request_list_adapter.js +0 -81
- package/storages/request_list_adapter.js.map +0 -1
- package/storages/request_manager_tandem.d.ts.map +0 -1
- package/storages/request_manager_tandem.js.map +0 -1
- package/storages/request_provider.d.ts +0 -371
- package/storages/request_provider.d.ts.map +0 -1
- package/storages/request_provider.js +0 -585
- package/storages/request_provider.js.map +0 -1
- package/storages/request_queue.d.ts.map +0 -1
- package/storages/request_queue.js.map +0 -1
- package/storages/request_queue_v2.d.ts +0 -87
- package/storages/request_queue_v2.d.ts.map +0 -1
- package/storages/request_queue_v2.js +0 -438
- package/storages/request_queue_v2.js.map +0 -1
- package/storages/sitemap_request_list.d.ts.map +0 -1
- package/storages/sitemap_request_list.js +0 -430
- package/storages/sitemap_request_list.js.map +0 -1
- package/storages/storage_manager.d.ts +0 -58
- package/storages/storage_manager.d.ts.map +0 -1
- package/storages/storage_manager.js +0 -105
- package/storages/storage_manager.js.map +0 -1
- package/storages/utils.d.ts.map +0 -1
- package/storages/utils.js.map +0 -1
- package/typedefs.d.ts.map +0 -1
- package/typedefs.js.map +0 -1
- package/validators.d.ts.map +0 -1
- package/validators.js.map +0 -1
package/README.md
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
<h1 align="center">
|
|
2
2
|
<a href="https://crawlee.dev">
|
|
3
3
|
<picture>
|
|
4
|
-
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/apify/crawlee/master/website/static/img/crawlee-dark.svg?sanitize=true"
|
|
5
|
-
<img alt="Crawlee" src="https://raw.githubusercontent.com/apify/crawlee/master/website/static/img/crawlee-light.svg?sanitize=true" width="500"
|
|
4
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/apify/crawlee/master/website/static/img/crawlee-dark.svg?sanitize=true" />
|
|
5
|
+
<img alt="Crawlee" src="https://raw.githubusercontent.com/apify/crawlee/master/website/static/img/crawlee-light.svg?sanitize=true" width="500" />
|
|
6
6
|
</picture>
|
|
7
7
|
</a>
|
|
8
|
-
<br
|
|
8
|
+
<br />
|
|
9
9
|
<small>A web scraping and browser automation library</small>
|
|
10
10
|
</h1>
|
|
11
11
|
|
|
12
|
-
<p align=center>
|
|
13
|
-
<a href="https://trendshift.io/repositories/5179" target="_blank"><img src="https://trendshift.io/api/badge/repositories/5179" alt="apify%2Fcrawlee | Trendshift"
|
|
12
|
+
<p align="center">
|
|
13
|
+
<a href="https://trendshift.io/repositories/5179" target="_blank"><img src="https://trendshift.io/api/badge/repositories/5179" alt="apify%2Fcrawlee | Trendshift" width="250" height="55"/></a>
|
|
14
14
|
</p>
|
|
15
15
|
|
|
16
|
-
<p align=center>
|
|
17
|
-
<a href="https://www.npmjs.com/package/@crawlee/core" rel="nofollow"><img src="https://img.shields.io/npm/v/@crawlee/core.svg" alt="NPM latest version" data-canonical-src="https://img.shields.io/npm/v/@crawlee/core/next.svg"
|
|
18
|
-
<a href="https://www.npmjs.com/package/@crawlee/core" rel="nofollow"><img src="https://img.shields.io/npm/dm/@crawlee/core.svg" alt="Downloads" data-canonical-src="https://img.shields.io/npm/dm/@crawlee/core.svg"
|
|
19
|
-
<a href="https://discord.gg/jyEM2PRvMU" rel="nofollow"><img src="https://img.shields.io/discord/801163717915574323?label=discord" alt="Chat on discord" data-canonical-src="https://img.shields.io/discord/801163717915574323?label=discord"
|
|
20
|
-
<a href="https://github.com/apify/crawlee/actions/workflows/test-ci.yml"><img src="https://github.com/apify/crawlee/actions/workflows/test-ci.yml/badge.svg?branch=master" alt="Build Status"
|
|
16
|
+
<p align="center">
|
|
17
|
+
<a href="https://www.npmjs.com/package/@crawlee/core" rel="nofollow"><img src="https://img.shields.io/npm/v/@crawlee/core.svg" alt="NPM latest version" data-canonical-src="https://img.shields.io/npm/v/@crawlee/core/next.svg" /></a>
|
|
18
|
+
<a href="https://www.npmjs.com/package/@crawlee/core" rel="nofollow"><img src="https://img.shields.io/npm/dm/@crawlee/core.svg" alt="Downloads" data-canonical-src="https://img.shields.io/npm/dm/@crawlee/core.svg" /></a>
|
|
19
|
+
<a href="https://discord.gg/jyEM2PRvMU" rel="nofollow"><img src="https://img.shields.io/discord/801163717915574323?label=discord" alt="Chat on discord" data-canonical-src="https://img.shields.io/discord/801163717915574323?label=discord" /></a>
|
|
20
|
+
<a href="https://github.com/apify/crawlee/actions/workflows/test-ci.yml"><img src="https://github.com/apify/crawlee/actions/workflows/test-ci.yml/badge.svg?branch=master" alt="Build Status" /></a>
|
|
21
21
|
</p>
|
|
22
22
|
|
|
23
23
|
Crawlee covers your crawling and scraping end-to-end and **helps you build reliable scrapers. Fast.**
|
|
@@ -89,7 +89,7 @@ By default, Crawlee stores data to `./storage` in the current working directory.
|
|
|
89
89
|
We provide automated beta builds for every merged code change in Crawlee. You can find them in the npm [list of releases](https://www.npmjs.com/package/crawlee?activeTab=versions). If you want to test new features or bug fixes before we release them, feel free to install a beta build like this:
|
|
90
90
|
|
|
91
91
|
```bash
|
|
92
|
-
npm install crawlee@
|
|
92
|
+
npm install crawlee@next
|
|
93
93
|
```
|
|
94
94
|
|
|
95
95
|
If you also use the [Apify SDK](https://github.com/apify/apify-sdk-js), you need to specify dependency overrides in your `package.json` file so that you don't end up with multiple versions of Crawlee installed:
|
|
@@ -98,9 +98,9 @@ If you also use the [Apify SDK](https://github.com/apify/apify-sdk-js), you need
|
|
|
98
98
|
{
|
|
99
99
|
"overrides": {
|
|
100
100
|
"apify": {
|
|
101
|
-
"@crawlee/core": "
|
|
102
|
-
"@crawlee/types": "
|
|
103
|
-
"@crawlee/utils": "
|
|
101
|
+
"@crawlee/core": "$crawlee",
|
|
102
|
+
"@crawlee/types": "$crawlee",
|
|
103
|
+
"@crawlee/utils": "$crawlee"
|
|
104
104
|
}
|
|
105
105
|
}
|
|
106
106
|
}
|
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
* The function must either be labeled `async` or return a promise.
|
|
9
|
-
*/
|
|
10
|
-
runTaskFunction?: () => Promise<unknown>;
|
|
1
|
+
import type { ConcurrencyConsumer, IConcurrencySystem } from './concurrency_system.js';
|
|
2
|
+
import type { CrawleeLogger } from '../log.js';
|
|
3
|
+
/**
|
|
4
|
+
* The two predicates that steer a task loop: *is there work ready?* and *are we done?* These are the parts of the loop
|
|
5
|
+
* a caller legitimately overrides, as opposed to the task itself (`runTaskFunction`), which the loop's driver owns.
|
|
6
|
+
*/
|
|
7
|
+
export interface TaskLoopPredicates {
|
|
11
8
|
/**
|
|
12
9
|
* A function that indicates whether `runTaskFunction` should be called.
|
|
13
10
|
* This function is called every time there is free capacity for a new task and it should
|
|
@@ -17,110 +14,62 @@ export interface AutoscaledPoolOptions {
|
|
|
17
14
|
isTaskReadyFunction?: () => Promise<boolean>;
|
|
18
15
|
/**
|
|
19
16
|
* A function that is called only when there are no tasks to be processed.
|
|
20
|
-
* If it resolves to `true` then the
|
|
17
|
+
* If it resolves to `true` then the run finishes. Being called only
|
|
21
18
|
* when there are no tasks being processed means that as long as `isTaskReadyFunction()`
|
|
22
19
|
* keeps resolving to `true`, `isFinishedFunction()` will never be called.
|
|
23
|
-
* To abort a run, use the {@link AutoscaledPool.abort} method.
|
|
24
20
|
*/
|
|
25
21
|
isFinishedFunction?: () => Promise<boolean>;
|
|
22
|
+
}
|
|
23
|
+
export interface TaskLoopOptions extends TaskLoopPredicates {
|
|
26
24
|
/**
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
* *WARNING:* If you set this value too high with respect to the available system memory and CPU, your code might run extremely slow or crash.
|
|
30
|
-
* If you're not sure, just keep the default value and the concurrency will scale up automatically.
|
|
31
|
-
* @default 1
|
|
32
|
-
*/
|
|
33
|
-
minConcurrency?: number;
|
|
34
|
-
/**
|
|
35
|
-
* The maximum number of tasks running in parallel.
|
|
36
|
-
* @default 200
|
|
37
|
-
*/
|
|
38
|
-
maxConcurrency?: number;
|
|
39
|
-
/**
|
|
40
|
-
* The desired number of tasks that should be running parallel on the start of the pool,
|
|
41
|
-
* if there is a large enough supply of them.
|
|
42
|
-
* By default, it is `minConcurrency`.
|
|
43
|
-
*/
|
|
44
|
-
desiredConcurrency?: number;
|
|
45
|
-
/**
|
|
46
|
-
* Minimum level of desired concurrency to reach before more scaling up is allowed.
|
|
47
|
-
* @default 0.90
|
|
48
|
-
*/
|
|
49
|
-
desiredConcurrencyRatio?: number;
|
|
50
|
-
/**
|
|
51
|
-
* Defines the fractional amount of desired concurrency to be added with each scaling up.
|
|
52
|
-
* The minimum scaling step is one.
|
|
53
|
-
* @default 0.05
|
|
54
|
-
*/
|
|
55
|
-
scaleUpStepRatio?: number;
|
|
56
|
-
/**
|
|
57
|
-
* Defines the amount of desired concurrency to be subtracted with each scaling down.
|
|
58
|
-
* The minimum scaling step is one.
|
|
59
|
-
* @default 0.05
|
|
60
|
-
*/
|
|
61
|
-
scaleDownStepRatio?: number;
|
|
62
|
-
/**
|
|
63
|
-
* Indicates how often the pool should call the `runTaskFunction()` to start a new task, in seconds.
|
|
64
|
-
* This has no effect on starting new tasks immediately after a task completes.
|
|
25
|
+
* How often the pool should check if a new task is ready, in seconds.
|
|
65
26
|
* @default 0.5
|
|
66
27
|
*/
|
|
67
28
|
maybeRunIntervalSecs?: number;
|
|
29
|
+
}
|
|
30
|
+
/** @internal */
|
|
31
|
+
export interface AutoscaledPoolOptions extends TaskLoopOptions {
|
|
68
32
|
/**
|
|
69
|
-
*
|
|
70
|
-
*
|
|
71
|
-
*
|
|
33
|
+
* The governor that decides whether there is free compute for one more task. Typically a
|
|
34
|
+
* {@link ConcurrencySystem}, but any {@link IConcurrencySystem} works. Share a single instance across
|
|
35
|
+
* multiple pools (and therefore multiple crawlers) to cap their *combined* concurrency against one budget.
|
|
36
|
+
*
|
|
37
|
+
* All concurrency/scaling/snapshotter configuration lives on the governor — the pool only owns the task loop and
|
|
38
|
+
* its cadence.
|
|
72
39
|
*/
|
|
73
|
-
|
|
40
|
+
concurrencySystem: IConcurrencySystem;
|
|
74
41
|
/**
|
|
75
|
-
*
|
|
76
|
-
*
|
|
77
|
-
* We suggest using a value from 5 to 20.
|
|
78
|
-
* @default 10
|
|
42
|
+
* Who this pool is, presented to the governor on every capacity query and booking so that a shared one can tell
|
|
43
|
+
* several pools apart. Worth naming meaningfully — a governor that allocates per consumer reports this `id`.
|
|
79
44
|
*/
|
|
80
|
-
|
|
45
|
+
consumer: ConcurrencyConsumer;
|
|
46
|
+
/**
|
|
47
|
+
* A function that performs an asynchronous resource-intensive task.
|
|
48
|
+
* The function must either be labeled `async` or return a promise.
|
|
49
|
+
*/
|
|
50
|
+
runTaskFunction?: () => Promise<unknown>;
|
|
81
51
|
/**
|
|
82
52
|
* Timeout in which the `runTaskFunction` needs to finish, given in seconds.
|
|
83
53
|
* @default 0
|
|
84
54
|
*/
|
|
85
55
|
taskTimeoutSecs?: number;
|
|
86
|
-
|
|
87
|
-
* Options to be passed down to the {@link Snapshotter} constructor. This is useful for fine-tuning
|
|
88
|
-
* the snapshot intervals and history.
|
|
89
|
-
*/
|
|
90
|
-
snapshotterOptions?: SnapshotterOptions;
|
|
91
|
-
/**
|
|
92
|
-
* Options to be passed down to the {@link SystemStatus} constructor. This is useful for fine-tuning
|
|
93
|
-
* the system status reports. If a custom snapshotter is set in the options, it will be used
|
|
94
|
-
* by the pool.
|
|
95
|
-
*/
|
|
96
|
-
systemStatusOptions?: SystemStatusOptions;
|
|
97
|
-
/**
|
|
98
|
-
* The maximum number of tasks per minute the pool can run.
|
|
99
|
-
* By default, this is set to `Infinity`, but you can pass any positive, non-zero integer.
|
|
100
|
-
*/
|
|
101
|
-
maxTasksPerMinute?: number;
|
|
102
|
-
log?: Log;
|
|
56
|
+
log?: CrawleeLogger;
|
|
103
57
|
}
|
|
104
58
|
/**
|
|
105
59
|
* Manages a pool of asynchronous resource-intensive tasks that are executed in parallel.
|
|
106
|
-
* The pool only starts new tasks
|
|
107
|
-
*
|
|
108
|
-
*
|
|
109
|
-
* The information about the CPU and memory usage is obtained by the {@link Snapshotter} class,
|
|
110
|
-
* which makes regular snapshots of system resources that may be either local
|
|
111
|
-
* or from the Apify cloud infrastructure in case the process is running on the Apify platform.
|
|
112
|
-
* Meaningful data gathered from these snapshots is provided to `AutoscaledPool` by the {@link SystemStatus} class.
|
|
60
|
+
* The pool only starts new tasks while its {@link IConcurrencySystem|concurrency system} reports free capacity —
|
|
61
|
+
* that governor is what monitors CPU, memory and event loop load and autoscales the concurrency budget.
|
|
113
62
|
*
|
|
114
63
|
* Before running the pool, you need to implement the following three functions:
|
|
115
|
-
* {@link AutoscaledPoolOptions.runTaskFunction},
|
|
116
|
-
* {@link
|
|
117
|
-
* {@link
|
|
64
|
+
* {@link AutoscaledPoolOptions.runTaskFunction|`runTaskFunction`},
|
|
65
|
+
* {@link TaskLoopPredicates.isTaskReadyFunction|`isTaskReadyFunction`} and
|
|
66
|
+
* {@link TaskLoopPredicates.isFinishedFunction|`isFinishedFunction`}.
|
|
118
67
|
*
|
|
119
68
|
* The auto-scaled pool is started by calling the {@link AutoscaledPool.run} function.
|
|
120
|
-
* The pool periodically queries
|
|
121
|
-
*
|
|
122
|
-
*
|
|
123
|
-
*
|
|
69
|
+
* The pool periodically queries `isTaskReadyFunction` for more tasks, managing optimal concurrency, until the function
|
|
70
|
+
* resolves to `false`. The pool then queries `isFinishedFunction`. If it resolves to `true`, the run finishes after all
|
|
71
|
+
* running tasks complete. If it resolves to `false`, it assumes there will be more tasks available later and keeps
|
|
72
|
+
* periodically querying for tasks.
|
|
124
73
|
* If any of the tasks throws then the {@link AutoscaledPool.run} function rejects the promise with an error.
|
|
125
74
|
*
|
|
126
75
|
* The pool evaluates whether it should start a new task every time one of the tasks finishes
|
|
@@ -129,8 +78,12 @@ export interface AutoscaledPoolOptions {
|
|
|
129
78
|
* **Example usage:**
|
|
130
79
|
*
|
|
131
80
|
* ```javascript
|
|
81
|
+
* const concurrencySystem = new ConcurrencySystem({ maxConcurrency: 50 });
|
|
82
|
+
* await concurrencySystem.start();
|
|
83
|
+
*
|
|
132
84
|
* const pool = new AutoscaledPool({
|
|
133
|
-
*
|
|
85
|
+
* concurrencySystem,
|
|
86
|
+
* consumer: { id: 'my-pool' },
|
|
134
87
|
* runTaskFunction: async () => {
|
|
135
88
|
* // Run some resource-intensive asynchronous operation here.
|
|
136
89
|
* },
|
|
@@ -145,77 +98,39 @@ export interface AutoscaledPoolOptions {
|
|
|
145
98
|
* }
|
|
146
99
|
* });
|
|
147
100
|
*
|
|
148
|
-
*
|
|
101
|
+
* try {
|
|
102
|
+
* await pool.run();
|
|
103
|
+
* } finally {
|
|
104
|
+
* await concurrencySystem.stop();
|
|
105
|
+
* }
|
|
149
106
|
* ```
|
|
150
|
-
*
|
|
107
|
+
*
|
|
108
|
+
* @internal
|
|
151
109
|
*/
|
|
152
110
|
export declare class AutoscaledPool {
|
|
153
|
-
private
|
|
154
|
-
|
|
155
|
-
private readonly desiredConcurrencyRatio;
|
|
156
|
-
private readonly scaleUpStepRatio;
|
|
157
|
-
private readonly scaleDownStepRatio;
|
|
158
|
-
private readonly maybeRunIntervalMillis;
|
|
159
|
-
private readonly loggingIntervalMillis;
|
|
160
|
-
private readonly autoscaleIntervalMillis;
|
|
161
|
-
private readonly taskTimeoutMillis;
|
|
162
|
-
private readonly runTaskFunction;
|
|
163
|
-
private readonly isFinishedFunction;
|
|
164
|
-
private readonly isTaskReadyFunction;
|
|
165
|
-
private readonly maxTasksPerMinute;
|
|
166
|
-
private _minConcurrency;
|
|
167
|
-
private _maxConcurrency;
|
|
168
|
-
private _desiredConcurrency;
|
|
169
|
-
private _currentConcurrency;
|
|
170
|
-
private isStopped;
|
|
171
|
-
private lastLoggingTime?;
|
|
172
|
-
private resolve;
|
|
173
|
-
private reject;
|
|
174
|
-
private snapshotter;
|
|
175
|
-
private systemStatus;
|
|
176
|
-
private autoscaleInterval;
|
|
177
|
-
private maybeRunInterval;
|
|
178
|
-
private queryingIsTaskReady;
|
|
179
|
-
private queryingIsFinished;
|
|
180
|
-
private tasksDonePerSecondInterval?;
|
|
181
|
-
private _tasksPerMinute;
|
|
182
|
-
constructor(options: AutoscaledPoolOptions, config?: Configuration);
|
|
183
|
-
/**
|
|
184
|
-
* Gets the minimum number of tasks running in parallel.
|
|
185
|
-
*/
|
|
186
|
-
get minConcurrency(): number;
|
|
111
|
+
#private;
|
|
112
|
+
constructor(options: AutoscaledPoolOptions);
|
|
187
113
|
/**
|
|
188
|
-
*
|
|
114
|
+
* The governor backing this pool, as supplied to the constructor — exposed as the read-only
|
|
115
|
+
* {@link IConcurrencySystem} contract.
|
|
189
116
|
*
|
|
190
|
-
*
|
|
191
|
-
*
|
|
192
|
-
*/
|
|
193
|
-
set minConcurrency(value: number);
|
|
194
|
-
/**
|
|
195
|
-
* Gets the maximum number of tasks running in parallel.
|
|
196
|
-
*/
|
|
197
|
-
get maxConcurrency(): number;
|
|
198
|
-
/**
|
|
199
|
-
* Sets the maximum number of tasks running in parallel.
|
|
200
|
-
*/
|
|
201
|
-
set maxConcurrency(value: number);
|
|
202
|
-
/**
|
|
203
|
-
* Gets the desired concurrency for the pool,
|
|
204
|
-
* which is an estimated number of parallel tasks that the system can currently support.
|
|
117
|
+
* This and the two getters below are telemetry only: concurrency is configured and tuned on the concrete
|
|
118
|
+
* {@link ConcurrencySystem} its owner holds, never through the pool.
|
|
205
119
|
*/
|
|
120
|
+
get system(): IConcurrencySystem;
|
|
121
|
+
/** The estimated number of parallel tasks the governor can currently support. */
|
|
206
122
|
get desiredConcurrency(): number;
|
|
207
123
|
/**
|
|
208
|
-
*
|
|
209
|
-
*
|
|
210
|
-
*/
|
|
211
|
-
set desiredConcurrency(value: number);
|
|
212
|
-
/**
|
|
213
|
-
* Gets the number of parallel tasks currently running in the pool.
|
|
124
|
+
* The number of parallel tasks currently booked against the governor. When it is shared, this counts every
|
|
125
|
+
* borrowing pool's tasks, not just this one's.
|
|
214
126
|
*/
|
|
215
127
|
get currentConcurrency(): number;
|
|
216
128
|
/**
|
|
217
129
|
* Runs the auto-scaled pool. Returns a promise that gets resolved or rejected once
|
|
218
130
|
* all the tasks are finished or one of them fails.
|
|
131
|
+
*
|
|
132
|
+
* Throws if the {@link IConcurrencySystem|concurrency system} it borrows was never started — the pool assumes
|
|
133
|
+
* a running governor and cannot start one it does not own.
|
|
219
134
|
*/
|
|
220
135
|
run(): Promise<void>;
|
|
221
136
|
/**
|
|
@@ -240,6 +155,10 @@ export declare class AutoscaledPool {
|
|
|
240
155
|
*
|
|
241
156
|
* The promise returned from the {@link AutoscaledPool.run} function will not resolve
|
|
242
157
|
* when `.pause()` is invoked (unlike abort, which resolves it).
|
|
158
|
+
*
|
|
159
|
+
* > *NOTE:* Pausing the pool does not suspend the (possibly shared) {@link ConcurrencySystem} — its
|
|
160
|
+
* autoscaling and resource monitoring keep running, since other pools borrowing it may still be active. To silence
|
|
161
|
+
* it during a long pause, its owner can `stop()` and `start()` it again.
|
|
243
162
|
*/
|
|
244
163
|
pause(timeoutSecs?: number): Promise<void>;
|
|
245
164
|
/**
|
|
@@ -258,43 +177,20 @@ export declare class AutoscaledPool {
|
|
|
258
177
|
* Starts a new task
|
|
259
178
|
* if the number of running tasks (current concurrency) is lower than desired concurrency
|
|
260
179
|
* and the system is not currently overloaded
|
|
261
|
-
* and
|
|
180
|
+
* and `isTaskReadyFunction()` returns true.
|
|
262
181
|
*
|
|
263
182
|
* It doesn't allow multiple concurrent runs of this method.
|
|
264
183
|
*/
|
|
265
|
-
|
|
266
|
-
/**
|
|
267
|
-
* Gets called every autoScaleIntervalSecs and evaluates the current system status.
|
|
268
|
-
* If the system IS NOT overloaded and the settings allow it, it scales up.
|
|
269
|
-
* If the system IS overloaded and the settings allow it, it scales down.
|
|
270
|
-
*/
|
|
271
|
-
protected _autoscale(intervalCallback: () => void): void;
|
|
272
|
-
/**
|
|
273
|
-
* Scales the pool up by increasing
|
|
274
|
-
* the desired concurrency by the scaleUpStepRatio.
|
|
275
|
-
*
|
|
276
|
-
* @param systemStatus for logging
|
|
277
|
-
*/
|
|
278
|
-
protected _scaleUp(systemStatus: SystemInfo): void;
|
|
279
|
-
/**
|
|
280
|
-
* Scales the pool down by decreasing
|
|
281
|
-
* the desired concurrency by the scaleDownStepRatio.
|
|
282
|
-
*
|
|
283
|
-
* @param systemStatus for logging
|
|
284
|
-
*/
|
|
285
|
-
protected _scaleDown(systemStatus: SystemInfo): void;
|
|
184
|
+
private maybeRunTask;
|
|
286
185
|
/**
|
|
287
|
-
* If there are no running tasks and
|
|
186
|
+
* If there are no running tasks and `isFinishedFunction()` returns true then closes
|
|
288
187
|
* the pool and resolves the pool's promise returned by the run() method.
|
|
289
188
|
*
|
|
290
189
|
* It doesn't allow multiple concurrent runs of this method.
|
|
291
190
|
*/
|
|
292
|
-
|
|
191
|
+
private maybeFinish;
|
|
293
192
|
/**
|
|
294
193
|
* Cleans up resources.
|
|
295
194
|
*/
|
|
296
|
-
|
|
297
|
-
protected _incrementTasksDonePerSecond(intervalCallback: () => void): void;
|
|
298
|
-
protected get _isOverMaxRequestLimit(): boolean;
|
|
195
|
+
private destroy;
|
|
299
196
|
}
|
|
300
|
-
//# sourceMappingURL=autoscaled_pool.d.ts.map
|