UNPKG

@naturalcycles/nodejs-lib

Version:
44 lines (43 loc) 1.68 kB
import type { Integer, NumberOfMilliseconds } from '@naturalcycles/js-lib/types'; import type { TransformOptions, TransformTyped } from '../stream.model.js'; export interface TransformThrottleByRSSOptions extends TransformOptions { /** * Maximum RSS (Resident Set Size) in megabytes. * When process RSS exceeds this value, the stream will pause * until RSS drops below the threshold. */ maxRSS: Integer; /** * How often to re-check RSS (in milliseconds) while paused. * * @default 5000 */ pollInterval?: NumberOfMilliseconds; /** * If this timeout is reached while RSS is above the limit - * the transform will "give up", log the bold warning, and "open the gateways". * Things will likely OOM after that, but at least it will not "hang forever". * * @default 30 minutes */ pollTimeout?: NumberOfMilliseconds; /** * What to do if pollTimeout is reached. * 'open-the-floodgates' will disable this throttle completely (YOLO). * 'throw' will throw an error, which will destroy the stream/Pipeline. * * @default 'open-the-floodgates' */ onPollTimeout?: 'open-the-floodgates' | 'throw'; } /** * Throttles the stream based on process memory (RSS) usage. * When RSS exceeds `maxRSS` (in megabytes), the stream pauses * and periodically re-checks until RSS drops below the threshold. * * Useful for pipelines that process large amounts of data and * may cause memory pressure (e.g. database imports, file processing). * * @experimental */ export declare function transformThrottleByRSS<T>(opt: TransformThrottleByRSSOptions): TransformTyped<T, T>;