UNPKG

@pod-protocol/sdk

Version:

TypeScript SDK for PoD Protocol - AI agent communication on Solana

181 lines 5.17 kB
/** * Performance optimization utilities for PoD Protocol SDK * Provides benchmarking, connection pooling, and performance monitoring */ export interface PerformanceMetrics { /** Operation name */ operation: string; /** Duration in milliseconds */ duration: number; /** Success status */ success: boolean; /** Timestamp when operation started */ timestamp: number; /** Memory usage before operation (MB) */ memoryBefore?: number; /** Memory usage after operation (MB) */ memoryAfter?: number; /** Additional context data */ context?: Record<string, unknown>; } export interface ConnectionPoolStats { /** Total connections in pool */ totalConnections: number; /** Active connections currently in use */ activeConnections: number; /** Idle connections available for use */ idleConnections: number; /** Total requests served */ totalRequests: number; /** Average response time in ms */ averageResponseTime: number; /** Pool utilization percentage */ utilization: number; } export interface BenchmarkResult { /** Benchmark name */ name: string; /** Operations per second */ opsPerSecond: number; /** Average operation time in ms */ averageTime: number; /** Minimum operation time in ms */ minTime: number; /** Maximum operation time in ms */ maxTime: number; /** Standard deviation */ standardDeviation: number; /** Total operations completed */ totalOperations: number; /** Memory usage stats */ memoryStats: { initial: number; peak: number; final: number; growth: number; }; } /** * Performance monitor for tracking operation metrics */ export declare class PerformanceMonitor { private metrics; private maxMetrics; /** * Start timing an operation */ startTimer(operation: string, context?: Record<string, unknown>): PerformanceTimer; /** * Record a completed operation */ recordMetric(metric: PerformanceMetrics): void; /** * Get performance statistics for operations */ getStats(operation?: string, timeframe?: number): { count: number; averageDuration: number; successRate: number; minDuration: number; maxDuration: number; opsPerSecond: number; }; /** * Get recent operation trends */ getTrends(operation: string, buckets?: number): Array<{ timeRange: string; count: number; averageDuration: number; successRate: number; }>; /** * Clear all metrics */ clear(): void; /** * Get all operations being tracked */ getTrackedOperations(): string[]; } /** * Timer for measuring operation performance */ export declare class PerformanceTimer { private operation; private context; private monitor; private startTime; private startMemory?; constructor(operation: string, context: Record<string, unknown>, monitor: PerformanceMonitor); /** * End timing and record metric */ end(success?: boolean, additionalContext?: Record<string, unknown>): PerformanceMetrics; } /** * Connection pool for managing RPC connections */ export declare class ConnectionPool { private connections; private connectionStats; private maxConnections; private maxIdleTime; private cleanupInterval?; constructor(maxConnections?: number, maxIdleTimeMs?: number); /** * Get or create a connection for the given URL */ getConnection(url: string, createConnection: () => any): any; /** * Record request completion for performance tracking */ recordRequest(url: string, responseTime: number): void; /** * Get connection pool statistics */ getStats(): ConnectionPoolStats; /** * Clean up idle connections */ private cleanupIdleConnections; /** * Evict the oldest connection */ private evictOldestConnection; /** * Destroy the connection pool */ destroy(): void; } /** * Benchmarking utility for performance testing */ export declare class PerformanceBenchmark { /** * Run a benchmark on an async operation */ static benchmark<T>(name: string, operation: () => Promise<T>, iterations?: number, warmupIterations?: number): Promise<BenchmarkResult>; /** * Get current memory usage in MB */ private static getMemoryUsage; /** * Compare two benchmark results */ static compare(benchmark1: BenchmarkResult, benchmark2: BenchmarkResult): { speedImprovement: number; memoryImprovement: number; winner: string; summary: string; }; } /** * Performance decorator for automatic method timing */ export declare function measurePerformance(monitor: PerformanceMonitor, operation?: string): (target: any, propertyKey: string, descriptor: PropertyDescriptor) => PropertyDescriptor; /** * Global performance monitor instance */ export declare const globalPerformanceMonitor: PerformanceMonitor; //# sourceMappingURL=performance.d.ts.map