/** * Memory Pressure Detection and Adaptive Scaling System * * Monitors system memory usage and automatically adjusts application behavior * to prevent out-of-memory errors and maintain optimal performance under * varying load conditions. */ import { EventEmitter } from 'events'; export interface MemoryPressureConfig { checkInterval?: number; lowMemoryThreshold?: number; highMemoryThreshold?: number; criticalMemoryThreshold?: number; enableAutoScaling?: boolean; enableGarbageCollection?: boolean; scalingFactor?: number; } export interface MemoryPressureEvent { level: 'low' | 'medium' | 'high' | 'critical'; usage: number; threshold: number; timestamp: number; recommendations: string[]; } export interface MemoryStats { used: number; total: number; usage: number; timestamp: number; } /** * Memory Pressure Monitor Class * * Provides real-time memory monitoring with adaptive scaling recommendations */ export declare class MemoryPressureMonitor extends EventEmitter { private config; private intervalId?; private lastStats?; private isMonitoring; constructor(config?: MemoryPressureConfig); /** * Start monitoring memory pressure */ start(): void; /** * Stop monitoring memory pressure */ stop(): void; /** * Get current memory statistics */ getCurrentStats(): MemoryStats; /** * Check memory pressure and emit events if thresholds are crossed * * This is the core monitoring function that: * 1. Collects current memory statistics * 2. Determines pressure level based on thresholds * 3. Emits appropriate events for listeners * 4. Applies automatic scaling if configured */ private checkMemoryPressure; /** * Determine pressure level based on usage * * Uses threshold comparison to categorize memory pressure. * The order is important - check highest threshold first * to ensure proper categorization. * * @param usage - Current memory usage ratio (0-1) * @returns Pressure level classification */ private getPressureLevel; /** * Get threshold value for pressure level */ private getThresholdForLevel; /** * Get recommendations for memory pressure level */ private getRecommendations; /** * Apply automatic scaling based on pressure level * * Implements adaptive scaling strategies to mitigate memory pressure. * Currently focuses on garbage collection, but can be extended * with additional scaling mechanisms. * * @param level - Current memory pressure level * @param stats - Current memory statistics */ private applyAutoScaling; /** * Get monitor configuration */ getConfig(): MemoryPressureConfig; /** * Update monitor configuration */ updateConfig(newConfig: Partial): void; /** * Get last recorded statistics */ getLastStats(): MemoryStats | undefined; /** * Check if monitoring is active */ isActive(): boolean; /** * Cleanup resources */ destroy(): void; } export declare const memoryMonitor: MemoryPressureMonitor; export default MemoryPressureMonitor; //# sourceMappingURL=memoryPressure.d.ts.map