datapilot-cli
Version:
Enterprise-grade streaming multi-format data analysis with comprehensive statistical insights and intelligent relationship detection - supports CSV, JSON, Excel, TSV, Parquet - memory-efficient, cross-platform
222 lines • 5.46 kB
TypeScript
/**
* Advanced Resource Pool Management
* Memory pooling, garbage collection optimization, and resource lifecycle management
*/
import { EventEmitter } from 'events';
export interface ResourcePoolOptions {
maxPoolSize?: number;
minPoolSize?: number;
maxResourceAge?: number;
cleanupInterval?: number;
enableGcOptimization?: boolean;
gcHeuristics?: GcHeuristics;
resourceTypes?: ResourceTypeConfig[];
}
export interface GcHeuristics {
memoryPressureThreshold?: number;
timeBetweenGcMin?: number;
timeBetweenGcMax?: number;
gcEfficiencyThreshold?: number;
adaptiveGcTiming?: boolean;
}
export interface ResourceTypeConfig {
name: string;
factory: () => any;
cleanup: (resource: any) => void;
validator: (resource: any) => boolean;
maxAge?: number;
maxPoolSize?: number;
}
export interface PooledResource<T = any> {
resource: T;
createdAt: number;
lastUsed: number;
useCount: number;
isHealthy: boolean;
}
export interface PoolStats {
totalCreated: number;
totalDestroyed: number;
totalReused: number;
currentPoolSize: number;
activeResources: number;
poolHitRate: number;
averageResourceAge: number;
memoryUsage: number;
}
export interface GcStats {
totalGcRuns: number;
totalGcTime: number;
averageGcTime: number;
memoryFreed: number;
lastGcTime: number;
gcEfficiency: number;
adaptiveTimingEnabled: boolean;
}
/**
* Generic resource pool with advanced lifecycle management
*/
export declare class ResourcePool<T = any> extends EventEmitter {
private pool;
private activeResources;
private options;
private stats;
private cleanupTimer?;
private factory;
private cleanup;
private validator;
constructor(factory: () => T, cleanup: (resource: T) => void, validator?: (resource: T) => boolean, options?: ResourcePoolOptions);
/**
* Acquire a resource from the pool
*/
acquire(): T;
/**
* Release a resource back to the pool
*/
release(resource: T): void;
/**
* Get resource from pool with health check
*/
private getFromPool;
/**
* Check if a pooled resource is still valid
*/
private isResourceValid;
/**
* Find active resource by reference
*/
private findActiveResource;
/**
* Destroy a resource and update stats
*/
private destroyResource;
/**
* Prewarm the pool with minimum resources
*/
private prewarmPool;
/**
* Cleanup expired resources
*/
private cleanupExpiredResources;
/**
* Start cleanup timer
*/
private startCleanupTimer;
/**
* Update pool statistics
*/
private updateStats;
/**
* Get current pool statistics
*/
getStats(): PoolStats;
/**
* Shutdown pool and cleanup all resources
*/
shutdown(): void;
}
/**
* Advanced garbage collection optimizer
*/
export declare class GcOptimizer extends EventEmitter {
private options;
private stats;
private lastGcTime;
private lastMemoryUsage;
private gcTimer?;
private isOptimizing;
constructor(options?: GcHeuristics);
/**
* Force garbage collection with optimization
*/
forceGc(): boolean;
/**
* Check if GC should be triggered
*/
shouldTriggerGc(): boolean;
/**
* Get current memory pressure (0-1)
*/
getCurrentMemoryPressure(): number;
/**
* Start adaptive GC timing
*/
private startAdaptiveGc;
/**
* Stop adaptive GC timing
*/
stopAdaptiveGc(): void;
/**
* Get GC statistics
*/
getStats(): GcStats;
/**
* Reset GC statistics
*/
resetStats(): void;
/**
* Shutdown GC optimizer
*/
shutdown(): void;
}
/**
* Multi-type resource pool manager
*/
export declare class ResourcePoolManager extends EventEmitter {
private pools;
private gcOptimizer;
private options;
constructor(options?: ResourcePoolOptions);
/**
* Add a new resource type
*/
addResourceType(config: ResourceTypeConfig): void;
/**
* Get resource pool by type
*/
getPool<T>(type: string): ResourcePool<T> | undefined;
/**
* Acquire resource of specific type
*/
acquire<T>(type: string): T | undefined;
/**
* Release resource of specific type
*/
release<T>(type: string, resource: T): void;
/**
* Get aggregated statistics for all pools
*/
getAllStats(): {
[type: string]: PoolStats;
} & {
gc: GcStats;
};
/**
* Force garbage collection
*/
forceGc(): boolean;
/**
* Shutdown all pools and GC optimizer
*/
shutdown(): void;
}
/**
* Get or create global resource pool manager
*/
export declare function getGlobalResourcePoolManager(options?: ResourcePoolOptions): ResourcePoolManager;
/**
* Shutdown global resource pool manager
*/
export declare function shutdownGlobalResourcePoolManager(): void;
/**
* Convenient buffer pool factory
*/
export declare function createBufferPool(options: {
maxSize?: number;
bufferSizes?: number[];
}): ResourcePool<Buffer>;
/**
* Convenient object pool factory
*/
export declare function createObjectPool<T>(factory: () => T, reset: (obj: T) => void, options?: ResourcePoolOptions): ResourcePool<T>;
//# sourceMappingURL=resource-pool.d.ts.map