digital-samba-mcp-server
Version:
Digital Samba MCP Server - Model Context Protocol server for Digital Samba's video conferencing API
147 lines • 4.53 kB
TypeScript
/**
* Digital Samba MCP Server - Resource Optimizer Module
*
* This module provides optimization strategies for high-traffic scenarios,
* reducing resource usage and improving performance of the MCP server.
*
* Features include:
* - Request batching to reduce API calls
* - Resource prioritization
* - Response compression
* - Incremental data loading
* - Memory usage optimization
*
* @module resource-optimizer
* @author Digital Samba Team
* @version 0.1.0
*/
import { EventEmitter } from 'events';
/**
* Resource optimizer options
*/
export interface ResourceOptimizerOptions {
/** Maximum batch size for requests (default: 10) */
maxBatchSize?: number;
/** Batch delay in milliseconds (default: 50) */
batchDelayMs?: number;
/** Whether to enable response compression (default: true) */
enableCompression?: boolean;
/** Whether to enable incremental loading (default: true) */
enableIncrementalLoading?: boolean;
/** Cache TTL for optimized resources in milliseconds (default: 60000) */
cacheTtl?: number;
/** Maximum memory usage in bytes (default: 100MB) */
maxMemoryUsage?: number;
/** Memory check interval in milliseconds (default: 30000) */
memoryCheckIntervalMs?: number;
}
/**
* Callback for batch execution
*/
type BatchExecutor<T> = (keys: string[]) => Promise<Map<string, T>>;
/**
* Resource Optimizer class
*
* Optimizes resource usage for high-traffic scenarios by batching requests,
* compressing responses, and managing memory usage.
*/
export declare class ResourceOptimizer extends EventEmitter {
private options;
private batches;
private batchTimers;
private cache;
private memoryCheckTimer?;
/**
* Resource Optimizer constructor
* @param options Resource optimizer options
*/
constructor(options?: ResourceOptimizerOptions);
/**
* Start memory usage monitoring
*/
private startMemoryMonitoring;
/**
* Stop memory usage monitoring
*/
private stopMemoryMonitoring;
/**
* Check memory usage and take action if needed
*/
private checkMemoryUsage;
/**
* Batch a request
* @param batchId Batch identifier
* @param key Request key
* @param executor Function to execute the batch
* @returns Promise resolving to the result
*/
batchRequest<T>(batchId: string, key: string, executor: BatchExecutor<T>): Promise<T>;
/**
* Execute a batch
* @param batchId Batch identifier
* @param executor Function to execute the batch
*/
private executeBatch;
/**
* Check if a batch is in progress
* @param batchId Batch identifier
* @returns Whether the batch is in progress
*/
isBatchInProgress(batchId: string): boolean;
/**
* Cancel a batch
* @param batchId Batch identifier
* @returns Whether the batch was cancelled
*/
cancelBatch(batchId: string): boolean;
/**
* Compress a response if compression is enabled
* @param data Data to compress
* @returns Compressed data or original data if compression disabled
*/
compressResponse(data: any): any;
/**
* Load data incrementally
* @param dataLoader Function to load data
* @param pageSize Page size
* @param maxPages Maximum number of pages to load
* @returns Promise resolving to the loaded data
*/
loadIncrementally<T>(dataLoader: (page: number, pageSize: number) => Promise<{
data: T[];
total: number;
}>, pageSize?: number, maxPages?: number): Promise<T[]>;
/**
* Get statistics for the resource optimizer
* @returns Resource optimizer statistics
*/
getStats(): {
activeBatches: number;
cacheStats: {
totalItems: number;
validItems: number;
expiredItems: number;
maxItems: number;
};
memoryUsage: NodeJS.MemoryUsage;
};
/**
* Clean up resources
*/
destroy(): void;
}
/**
* Create a resource optimizer
* @param options Resource optimizer options
* @returns A new resource optimizer instance
*/
export declare function createResourceOptimizer(options?: ResourceOptimizerOptions): ResourceOptimizer;
/**
* Export default resource optimizer utilities
*/
declare const _default: {
ResourceOptimizer: typeof ResourceOptimizer;
createResourceOptimizer: typeof createResourceOptimizer;
};
export default _default;
//# sourceMappingURL=resource-optimizer.d.ts.map