Skip to content

Crawlee—A web scraping and browser automation library for Node.js to build reliable crawlers. In JavaScript and TypeScript. Extract data for AI, LLMs, RAG, or GPTs. Download HTML, PDF, JPG, PNG, and other files from websites. Works with Puppeteer, Playwright, Cheerio, JSDOM, and raw HTTP. Both headful and headless mode. With proxy rotation.

Feature/autoscaling fix (#90)

Marek Trunkátae2d681557be
diff --git a/src/basic_crawler.js b/src/basic_crawler.js
index 8f32532ab..e3bc74ddb 100644
--- a/src/basic_crawler.js
+++ b/src/basic_crawler.js
@@ -64,6 +64,10 @@ const DEFAULT_OPTIONS = {
* This function that is called every time there are no requests being processed.
* If it resolves to `true` then the crawler's run finishes.
* See `isFinishedFunction` parameter of `AutoscaledPool`.
+ * @param {Boolean} [options.ignoreMainProcess=false] If set to `true` then autoscaling doesn't consider memory consumption
+ * of the main NodeJS process when autoscaling the pool up/down. This is mainly useful when
+ * tasks are running as separate processes (for example web browser).
+ * See `ignoreMainProcess` parameter of `AutoscaledPool`.
*/
export default class BasicCrawler {
constructor(opts) {
@@ -80,6 +84,7 @@ export default class BasicCrawler {
minConcurrency,
minFreeMemoryRatio,
isFinishedFunction,
+ ignoreMainProcess,
} = _.defaults(opts, DEFAULT_OPTIONS);
checkParamPrototypeOrThrow(requestList, 'opts.requestList', RequestList, 'Apify.RequestList', true);
@@ -87,7 +92,6 @@ export default class BasicCrawler {
checkParamOrThrow(handleRequestFunction, 'opts.handleRequestFunction', 'Function');
checkParamOrThrow(handleFailedRequestFunction, 'opts.handleFailedRequestFunction', 'Function');
checkParamOrThrow(maxRequestRetries, 'opts.maxRequestRetries', 'Number');
- checkParamOrThrow(isFinishedFunction, 'opts.isFinishedFunction', 'Maybe Function');
if (!requestList && !requestQueue) {
throw new Error('At least one of the parameters "opts.requestList" and "opts.requestQueue" must be provided!');
@@ -111,7 +115,7 @@ export default class BasicCrawler {
? isFinishedFunction()
: this._defaultIsFinishedFunction()
),
- ignoreMainProcess: true,
+ ignoreMainProcess,
});
}
diff --git a/src/puppeteer_crawler.js b/src/puppeteer_crawler.js
index 2bcd09ea8..95d18e98d 100644
--- a/src/puppeteer_crawler.js
+++ b/src/puppeteer_crawler.js
@@ -162,6 +162,7 @@ export default class PuppeteerCrawler {
minConcurrency,
minFreeMemoryRatio,
isFinishedFunction,
+ ignoreMainProcess: true,
});
}