UNPKG

@crawlee/core

Version:

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.

39 lines (38 loc) 1.53 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.createEventLoopLoadSignal = createEventLoopLoadSignal; const load_signal_1 = require("./load_signal"); /** * Periodically measures event loop delay and reports overload when the * delay exceeds a configured threshold. */ function createEventLoopLoadSignal(options = {}) { const intervalMillis = (options.eventLoopSnapshotIntervalSecs ?? 0.5) * 1000; const maxBlockedMillis = options.maxBlockedMillis ?? 50; const signal = load_signal_1.SnapshotStore.fromInterval({ name: 'eventLoopInfo', overloadedRatio: options.overloadedRatio ?? 0.6, intervalMillis, snapshotHistoryMillis: options.snapshotHistoryMillis, handler(store, intervalCallback) { const now = new Date(); const snapshot = { createdAt: now, isOverloaded: false, exceededMillis: 0, }; const all = store.getAll(); const previousSnapshot = all[all.length - 1]; if (previousSnapshot) { const { createdAt } = previousSnapshot; const delta = now.getTime() - +createdAt - intervalMillis; if (delta > maxBlockedMillis) snapshot.isOverloaded = true; snapshot.exceededMillis = Math.max(delta - maxBlockedMillis, 0); } store.push(snapshot, now); intervalCallback(); }, }); return signal; }