@crawlee/http 4.0.0-beta.87 → 4.0.0-beta.89

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.
@@ -68,7 +68,7 @@ export declare function ByteCounterStream({ logTransferredBytes, loggingInterval
68
68
  * ]
69
69
  * ```
70
70
  *
71
- * New requests are only dispatched when there is enough free CPU and memory available, using the functionality provided by the {@link AutoscaledPool} class. All {@link AutoscaledPool} configuration options can be passed to the `autoscaledPoolOptions` parameter of the `FileCrawler` constructor. For user convenience, the `minConcurrency` and `maxConcurrency` {@link AutoscaledPool} options are available directly in the `FileCrawler` constructor.
71
+ * New requests are only dispatched when there is enough free CPU and memory available, using the functionality provided by the {@link AutoscaledPool} class. Concurrency is tuned via the `minConcurrency`, `maxConcurrency` and `maxRequestsPerMinute` options of the `FileCrawler` constructor, or, for finer control, by injecting a pre-configured {@link ConcurrencySystem|`concurrencySystem`}.
72
72
  *
73
73
  * ## Example usage
74
74
  *
@@ -87,7 +87,7 @@ export function ByteCounterStream({ logTransferredBytes, loggingInterval = 5000,
87
87
  * ]
88
88
  * ```
89
89
  *
90
- * New requests are only dispatched when there is enough free CPU and memory available, using the functionality provided by the {@link AutoscaledPool} class. All {@link AutoscaledPool} configuration options can be passed to the `autoscaledPoolOptions` parameter of the `FileCrawler` constructor. For user convenience, the `minConcurrency` and `maxConcurrency` {@link AutoscaledPool} options are available directly in the `FileCrawler` constructor.
90
+ * New requests are only dispatched when there is enough free CPU and memory available, using the functionality provided by the {@link AutoscaledPool} class. Concurrency is tuned via the `minConcurrency`, `maxConcurrency` and `maxRequestsPerMinute` options of the `FileCrawler` constructor, or, for finer control, by injecting a pre-configured {@link ConcurrencySystem|`concurrencySystem`}.
91
91
  *
92
92
  * ## Example usage
93
93
  *
@@ -1,9 +1,21 @@
1
- import type { BasicCrawlerOptions, CrawlingContext, ErrorHandler, GetUserDataFromRequest, Request as CrawleeRequest, RequestHandler, RequireContextPipeline, RouterHandler, RouterRoutes, RouteSchemas, RoutesFromSchemas } from '@crawlee/basic';
1
+ import type { BasicCrawlerOptions, ConcurrencySystem, ConcurrencySystemOptions, CrawlingContext, ErrorHandler, GetUserDataFromRequest, Request as CrawleeRequest, RequestHandler, RequireContextPipeline, RouterHandler, RouterRoutes, RouteSchemas, RoutesFromSchemas } from '@crawlee/basic';
2
2
  import { BasicCrawler, ContextPipeline } from '@crawlee/basic';
3
3
  import { type LoadedRequest } from '@crawlee/core';
4
4
  import type { Awaitable, Dictionary } from '@crawlee/types';
5
5
  import { type CheerioRoot } from '@crawlee/utils';
6
6
  import type { JsonValue } from 'type-fest';
7
+ /**
8
+ * A higher starting concurrency and a relaxed event loop signal, since HTTP-only crawling barely touches the event
9
+ * loop. {@link HttpCrawler} folds these into the {@link ConcurrencySystem} it builds by default.
10
+ *
11
+ * A {@link BasicCrawlerOptions.concurrencySystem|`concurrencySystem`} you supply yourself replaces that default
12
+ * wholesale, tuning included, so spread these options in if you want to keep it:
13
+ *
14
+ * ```typescript
15
+ * new ConcurrencySystem({ ...HTTP_OPTIMIZED_CONCURRENCY_SYSTEM_OPTIONS, maxConcurrency: 50 });
16
+ * ```
17
+ */
18
+ export declare const HTTP_OPTIMIZED_CONCURRENCY_SYSTEM_OPTIONS: ConcurrencySystemOptions;
7
19
  export type HttpErrorHandler<UserData extends Dictionary = any, // with default to Dictionary we cant use a typed router in untyped crawler
8
20
  JSONData extends JsonValue = any, // with default to Dictionary we cant use a typed router in untyped crawler
9
21
  ContextExtension = Dictionary<never>> = ErrorHandler<CrawlingContext, HttpCrawlingContext<UserData, JSONData> & ContextExtension>;
@@ -204,9 +216,9 @@ JSONData extends JsonValue = any> = RequestHandler<HttpCrawlingContext<UserData,
204
216
  *
205
217
  * New requests are only dispatched when there is enough free CPU and memory available,
206
218
  * using the functionality provided by the {@link AutoscaledPool} class.
207
- * All {@link AutoscaledPool} configuration options can be passed to the `autoscaledPoolOptions`
208
- * parameter of the constructor. For user convenience, the `minConcurrency` and `maxConcurrency`
209
- * {@link AutoscaledPool} options are available directly in the constructor.
219
+ * Concurrency is tuned via the `minConcurrency`, `maxConcurrency` and `maxRequestsPerMinute` options of the
220
+ * constructor, or, for finer control, by injecting a pre-configured
221
+ * {@link ConcurrencySystem|`concurrencySystem`}.
210
222
  *
211
223
  * **Example usage:**
212
224
  *
@@ -283,6 +295,8 @@ export declare class HttpCrawler<Context extends InternalHttpCrawlingContext<any
283
295
  maxCrawlDepth: import("ow").NumberPredicate & import("ow").BasePredicate<number | undefined>;
284
296
  // @ts-ignore optional peer dependency or compatibility with es2022
285
297
  autoscaledPoolOptions: import("ow").ObjectPredicate<object> & import("ow").BasePredicate<object | undefined>;
298
+ // @ts-ignore optional peer dependency or compatibility with es2022
299
+ concurrencySystem: import("ow").ObjectPredicate<object> & import("ow").BasePredicate<object | undefined>;
286
300
  // @ts-ignore optional peer dependency or compatibility with es2022
287
301
  sessionPool: import("ow").ObjectPredicate<object> & import("ow").BasePredicate<object | undefined>;
288
302
  // @ts-ignore optional peer dependency or compatibility with es2022
@@ -330,6 +344,13 @@ export declare class HttpCrawler<Context extends InternalHttpCrawlingContext<any
330
344
  * All `HttpCrawlerOptions` parameters are passed via an options object.
331
345
  */
332
346
  constructor(options?: HttpCrawlerOptions<Context, ContextExtension, ExtendedContext> & RequireContextPipeline<InternalHttpCrawlingContext, Context>);
347
+ /**
348
+ * Folds {@link HTTP_OPTIMIZED_CONCURRENCY_SYSTEM_OPTIONS} into the default system, keeping the user's
349
+ * concurrency shortcuts on top. Not called for a supplied
350
+ * {@link BasicCrawlerOptions.concurrencySystem|`concurrencySystem`} — spread the constant into it yourself to
351
+ * keep the tuning.
352
+ */
353
+ protected createDefaultConcurrencySystem(options: ConcurrencySystemOptions): ConcurrencySystem;
333
354
  protected buildContextPipeline(): ContextPipeline<CrawlingContext, InternalHttpCrawlingContext>;
334
355
  private prepareHttpRequest;
335
356
  private makeHttpRequest;
@@ -14,14 +14,25 @@ import { extractCharsetFromHtmlBytes, parseContentTypeFromResponse, processHttpR
14
14
  */
15
15
  const HTML_AND_XML_MIME_TYPES = ['text/html', 'text/xml', 'application/xhtml+xml', 'application/xml'];
16
16
  const APPLICATION_JSON_MIME_TYPE = 'application/json';
17
- const HTTP_OPTIMIZED_AUTOSCALED_POOL_OPTIONS = {
17
+ /**
18
+ * A higher starting concurrency and a relaxed event loop signal, since HTTP-only crawling barely touches the event
19
+ * loop. {@link HttpCrawler} folds these into the {@link ConcurrencySystem} it builds by default.
20
+ *
21
+ * A {@link BasicCrawlerOptions.concurrencySystem|`concurrencySystem`} you supply yourself replaces that default
22
+ * wholesale, tuning included, so spread these options in if you want to keep it:
23
+ *
24
+ * ```typescript
25
+ * new ConcurrencySystem({ ...HTTP_OPTIMIZED_CONCURRENCY_SYSTEM_OPTIONS, maxConcurrency: 50 });
26
+ * ```
27
+ */
28
+ export const HTTP_OPTIMIZED_CONCURRENCY_SYSTEM_OPTIONS = {
18
29
  desiredConcurrency: 10,
19
- snapshotterOptions: {
20
- eventLoopSnapshotIntervalSecs: 2,
21
- maxBlockedMillis: 100,
22
- },
23
- systemStatusOptions: {
24
- maxEventLoopOverloadedRatio: 0.7,
30
+ loadSignals: {
31
+ eventLoop: {
32
+ snapshotIntervalSecs: 2,
33
+ maxBlockedMillis: 100,
34
+ overloadedRatio: 0.7,
35
+ },
25
36
  },
26
37
  };
27
38
  /**
@@ -66,9 +77,9 @@ const HTTP_OPTIMIZED_AUTOSCALED_POOL_OPTIONS = {
66
77
  *
67
78
  * New requests are only dispatched when there is enough free CPU and memory available,
68
79
  * using the functionality provided by the {@link AutoscaledPool} class.
69
- * All {@link AutoscaledPool} configuration options can be passed to the `autoscaledPoolOptions`
70
- * parameter of the constructor. For user convenience, the `minConcurrency` and `maxConcurrency`
71
- * {@link AutoscaledPool} options are available directly in the constructor.
80
+ * Concurrency is tuned via the `minConcurrency`, `maxConcurrency` and `maxRequestsPerMinute` options of the
81
+ * constructor, or, for finer control, by injecting a pre-configured
82
+ * {@link ConcurrencySystem|`concurrencySystem`}.
72
83
  *
73
84
  * **Example usage:**
74
85
  *
@@ -124,10 +135,9 @@ export class HttpCrawler extends BasicCrawler {
124
135
  ow(options, 'HttpCrawlerOptions', ow.object.exactShape(HttpCrawler.optionsShape));
125
136
  const { navigationTimeoutSecs = 30, ignoreSslErrors = true, additionalMimeTypes = [], suggestResponseEncoding, forceResponseEncoding, saveResponseCookies = true, preNavigationHooks = [], postNavigationHooks = [],
126
137
  // BasicCrawler
127
- autoscaledPoolOptions = HTTP_OPTIMIZED_AUTOSCALED_POOL_OPTIONS, contextPipelineBuilder, ...basicCrawlerOptions } = options;
138
+ contextPipelineBuilder, ...basicCrawlerOptions } = options;
128
139
  super({
129
140
  ...basicCrawlerOptions,
130
- autoscaledPoolOptions,
131
141
  contextPipelineBuilder: contextPipelineBuilder ??
132
142
  (() => this.buildContextPipeline()),
133
143
  });
@@ -151,6 +161,18 @@ export class HttpCrawler extends BasicCrawler {
151
161
  ];
152
162
  this.saveResponseCookies = saveResponseCookies;
153
163
  }
164
+ /**
165
+ * Folds {@link HTTP_OPTIMIZED_CONCURRENCY_SYSTEM_OPTIONS} into the default system, keeping the user's
166
+ * concurrency shortcuts on top. Not called for a supplied
167
+ * {@link BasicCrawlerOptions.concurrencySystem|`concurrencySystem`} — spread the constant into it yourself to
168
+ * keep the tuning.
169
+ */
170
+ createDefaultConcurrencySystem(options) {
171
+ return super.createDefaultConcurrencySystem({
172
+ ...HTTP_OPTIMIZED_CONCURRENCY_SYSTEM_OPTIONS,
173
+ ...options,
174
+ });
175
+ }
154
176
  buildContextPipeline() {
155
177
  // When navigation is skipped, `prepareHttpRequest` has already installed throwing getters for
156
178
  // the response-derived members, so the guarded action is bypassed and the context left untouched.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crawlee/http",
3
- "version": "4.0.0-beta.87",
3
+ "version": "4.0.0-beta.89",
4
4
  "description": "The scalable web crawling and scraping library for JavaScript/Node.js. Enables development of data extraction and web automation jobs (not only) with headless Chrome and Puppeteer.",
5
5
  "engines": {
6
6
  "node": ">=22.0.0"
@@ -49,11 +49,11 @@
49
49
  "dependencies": {
50
50
  "@apify/timeout": "^0.3.2",
51
51
  "@apify/utilities": "^2.15.5",
52
- "@crawlee/basic": "4.0.0-beta.87",
53
- "@crawlee/core": "4.0.0-beta.87",
54
- "@crawlee/http-client": "4.0.0-beta.87",
55
- "@crawlee/types": "4.0.0-beta.87",
56
- "@crawlee/utils": "4.0.0-beta.87",
52
+ "@crawlee/basic": "4.0.0-beta.89",
53
+ "@crawlee/core": "4.0.0-beta.89",
54
+ "@crawlee/http-client": "4.0.0-beta.89",
55
+ "@crawlee/types": "4.0.0-beta.89",
56
+ "@crawlee/utils": "4.0.0-beta.89",
57
57
  "@types/content-type": "^1.1.8",
58
58
  "cheerio": "^1.0.0",
59
59
  "content-type": "^1.0.5",
@@ -70,5 +70,5 @@
70
70
  }
71
71
  }
72
72
  },
73
- "gitHead": "1b7604cd77b694460aac4448b4555444fa1b2bdb"
73
+ "gitHead": "9279941162eb4be0a9113f768b5bd79d27e66eba"
74
74
  }