@@ -9,34 +9,34 @@ export interface PerformanceConfig {
9
9
deploymentConcurrency : number
10
10
networkQueryConcurrency : number
11
11
batchSize : number
12
-
12
+
13
13
// Cache settings
14
14
enableCache : boolean
15
15
cacheTTL : number
16
16
cacheMaxSize : number
17
17
cacheCleanupInterval : number
18
-
18
+
19
19
// Circuit breaker settings
20
20
enableCircuitBreaker : boolean
21
21
circuitBreakerFailureThreshold : number
22
22
circuitBreakerResetTimeout : number
23
23
circuitBreakerHalfOpenMaxAttempts : number
24
-
24
+
25
25
// Priority queue settings
26
26
enablePriorityQueue : boolean
27
27
priorityQueueSignalThreshold : string
28
28
priorityQueueStakeThreshold : string
29
-
29
+
30
30
// Network settings
31
31
enableParallelNetworkQueries : boolean
32
32
networkQueryBatchSize : number
33
33
networkQueryTimeout : number
34
-
34
+
35
35
// Retry settings
36
36
maxRetryAttempts : number
37
37
retryDelay : number
38
38
retryBackoffMultiplier : number
39
-
39
+
40
40
// Monitoring settings
41
41
enableMetrics : boolean
42
42
metricsInterval : number
@@ -49,34 +49,34 @@ export const DEFAULT_PERFORMANCE_CONFIG: PerformanceConfig = {
49
49
deploymentConcurrency : 15 ,
50
50
networkQueryConcurrency : 10 ,
51
51
batchSize : 10 ,
52
-
52
+
53
53
// Cache settings
54
54
enableCache : true ,
55
55
cacheTTL : 30000 , // 30 seconds
56
56
cacheMaxSize : 2000 ,
57
57
cacheCleanupInterval : 60000 , // 1 minute
58
-
58
+
59
59
// Circuit breaker settings
60
60
enableCircuitBreaker : true ,
61
61
circuitBreakerFailureThreshold : 5 ,
62
62
circuitBreakerResetTimeout : 60000 , // 1 minute
63
63
circuitBreakerHalfOpenMaxAttempts : 3 ,
64
-
64
+
65
65
// Priority queue settings
66
66
enablePriorityQueue : true ,
67
67
priorityQueueSignalThreshold : '1000000000000000000000' , // 1000 GRT
68
68
priorityQueueStakeThreshold : '10000000000000000000000' , // 10000 GRT
69
-
69
+
70
70
// Network settings
71
71
enableParallelNetworkQueries : true ,
72
72
networkQueryBatchSize : 50 ,
73
73
networkQueryTimeout : 30000 , // 30 seconds
74
-
74
+
75
75
// Retry settings
76
76
maxRetryAttempts : 3 ,
77
77
retryDelay : 1000 , // 1 second
78
78
retryBackoffMultiplier : 2 ,
79
-
79
+
80
80
// Monitoring settings
81
81
enableMetrics : true ,
82
82
metricsInterval : 60000 , // 1 minute
@@ -88,96 +88,96 @@ export const DEFAULT_PERFORMANCE_CONFIG: PerformanceConfig = {
88
88
*/
89
89
export function loadPerformanceConfig ( ) : PerformanceConfig {
90
90
const config = { ...DEFAULT_PERFORMANCE_CONFIG }
91
-
91
+
92
92
// Override with environment variables if present
93
93
if ( process . env . ALLOCATION_CONCURRENCY ) {
94
94
config . allocationConcurrency = parseInt ( process . env . ALLOCATION_CONCURRENCY )
95
95
}
96
-
96
+
97
97
if ( process . env . DEPLOYMENT_CONCURRENCY ) {
98
98
config . deploymentConcurrency = parseInt ( process . env . DEPLOYMENT_CONCURRENCY )
99
99
}
100
-
100
+
101
101
if ( process . env . NETWORK_QUERY_CONCURRENCY ) {
102
102
config . networkQueryConcurrency = parseInt ( process . env . NETWORK_QUERY_CONCURRENCY )
103
103
}
104
-
104
+
105
105
if ( process . env . BATCH_SIZE ) {
106
106
config . batchSize = parseInt ( process . env . BATCH_SIZE )
107
107
}
108
-
108
+
109
109
if ( process . env . ENABLE_CACHE !== undefined ) {
110
110
config . enableCache = process . env . ENABLE_CACHE !== 'false'
111
111
}
112
-
112
+
113
113
if ( process . env . CACHE_TTL ) {
114
114
config . cacheTTL = parseInt ( process . env . CACHE_TTL )
115
115
}
116
-
116
+
117
117
if ( process . env . CACHE_MAX_SIZE ) {
118
118
config . cacheMaxSize = parseInt ( process . env . CACHE_MAX_SIZE )
119
119
}
120
-
120
+
121
121
if ( process . env . ENABLE_CIRCUIT_BREAKER !== undefined ) {
122
122
config . enableCircuitBreaker = process . env . ENABLE_CIRCUIT_BREAKER !== 'false'
123
123
}
124
-
124
+
125
125
if ( process . env . CIRCUIT_BREAKER_FAILURE_THRESHOLD ) {
126
126
config . circuitBreakerFailureThreshold = parseInt ( process . env . CIRCUIT_BREAKER_FAILURE_THRESHOLD )
127
127
}
128
-
128
+
129
129
if ( process . env . CIRCUIT_BREAKER_RESET_TIMEOUT ) {
130
130
config . circuitBreakerResetTimeout = parseInt ( process . env . CIRCUIT_BREAKER_RESET_TIMEOUT )
131
131
}
132
-
132
+
133
133
if ( process . env . ENABLE_PRIORITY_QUEUE !== undefined ) {
134
134
config . enablePriorityQueue = process . env . ENABLE_PRIORITY_QUEUE !== 'false'
135
135
}
136
-
136
+
137
137
if ( process . env . PRIORITY_QUEUE_SIGNAL_THRESHOLD ) {
138
138
config . priorityQueueSignalThreshold = process . env . PRIORITY_QUEUE_SIGNAL_THRESHOLD
139
139
}
140
-
140
+
141
141
if ( process . env . PRIORITY_QUEUE_STAKE_THRESHOLD ) {
142
142
config . priorityQueueStakeThreshold = process . env . PRIORITY_QUEUE_STAKE_THRESHOLD
143
143
}
144
-
144
+
145
145
if ( process . env . ENABLE_PARALLEL_NETWORK_QUERIES !== undefined ) {
146
146
config . enableParallelNetworkQueries = process . env . ENABLE_PARALLEL_NETWORK_QUERIES !== 'false'
147
147
}
148
-
148
+
149
149
if ( process . env . NETWORK_QUERY_BATCH_SIZE ) {
150
150
config . networkQueryBatchSize = parseInt ( process . env . NETWORK_QUERY_BATCH_SIZE )
151
151
}
152
-
152
+
153
153
if ( process . env . NETWORK_QUERY_TIMEOUT ) {
154
154
config . networkQueryTimeout = parseInt ( process . env . NETWORK_QUERY_TIMEOUT )
155
155
}
156
-
156
+
157
157
if ( process . env . MAX_RETRY_ATTEMPTS ) {
158
158
config . maxRetryAttempts = parseInt ( process . env . MAX_RETRY_ATTEMPTS )
159
159
}
160
-
160
+
161
161
if ( process . env . RETRY_DELAY ) {
162
162
config . retryDelay = parseInt ( process . env . RETRY_DELAY )
163
163
}
164
-
164
+
165
165
if ( process . env . RETRY_BACKOFF_MULTIPLIER ) {
166
166
config . retryBackoffMultiplier = parseFloat ( process . env . RETRY_BACKOFF_MULTIPLIER )
167
167
}
168
-
168
+
169
169
if ( process . env . ENABLE_METRICS !== undefined ) {
170
170
config . enableMetrics = process . env . ENABLE_METRICS !== 'false'
171
171
}
172
-
172
+
173
173
if ( process . env . METRICS_INTERVAL ) {
174
174
config . metricsInterval = parseInt ( process . env . METRICS_INTERVAL )
175
175
}
176
-
176
+
177
177
if ( process . env . ENABLE_DETAILED_LOGGING !== undefined ) {
178
178
config . enableDetailedLogging = process . env . ENABLE_DETAILED_LOGGING === 'true'
179
179
}
180
-
180
+
181
181
return config
182
182
}
183
183
@@ -188,27 +188,27 @@ export function validatePerformanceConfig(config: PerformanceConfig): void {
188
188
if ( config . allocationConcurrency < 1 || config . allocationConcurrency > 100 ) {
189
189
throw new Error ( 'allocationConcurrency must be between 1 and 100' )
190
190
}
191
-
191
+
192
192
if ( config . deploymentConcurrency < 1 || config . deploymentConcurrency > 50 ) {
193
193
throw new Error ( 'deploymentConcurrency must be between 1 and 50' )
194
194
}
195
-
195
+
196
196
if ( config . batchSize < 1 || config . batchSize > 100 ) {
197
197
throw new Error ( 'batchSize must be between 1 and 100' )
198
198
}
199
-
199
+
200
200
if ( config . cacheTTL < 1000 || config . cacheTTL > 300000 ) {
201
201
throw new Error ( 'cacheTTL must be between 1000ms and 300000ms (5 minutes)' )
202
202
}
203
-
203
+
204
204
if ( config . cacheMaxSize < 100 || config . cacheMaxSize > 10000 ) {
205
205
throw new Error ( 'cacheMaxSize must be between 100 and 10000' )
206
206
}
207
-
207
+
208
208
if ( config . circuitBreakerFailureThreshold < 1 || config . circuitBreakerFailureThreshold > 20 ) {
209
209
throw new Error ( 'circuitBreakerFailureThreshold must be between 1 and 20' )
210
210
}
211
-
211
+
212
212
if ( config . maxRetryAttempts < 0 || config . maxRetryAttempts > 10 ) {
213
213
throw new Error ( 'maxRetryAttempts must be between 0 and 10' )
214
214
}
@@ -219,11 +219,11 @@ export function validatePerformanceConfig(config: PerformanceConfig): void {
219
219
*/
220
220
export function getOptimizedConfig ( ) : PerformanceConfig {
221
221
const config = loadPerformanceConfig ( )
222
-
222
+
223
223
// Adjust based on available system resources
224
224
const cpuCount = require ( 'os' ) . cpus ( ) . length
225
225
const totalMemory = require ( 'os' ) . totalmem ( )
226
-
226
+
227
227
// Adjust concurrency based on CPU cores
228
228
if ( cpuCount >= 8 ) {
229
229
config . allocationConcurrency = Math . min ( 30 , config . allocationConcurrency * 1.5 )
@@ -232,14 +232,14 @@ export function getOptimizedConfig(): PerformanceConfig {
232
232
config . allocationConcurrency = Math . max ( 5 , config . allocationConcurrency * 0.5 )
233
233
config . deploymentConcurrency = Math . max ( 5 , config . deploymentConcurrency * 0.5 )
234
234
}
235
-
235
+
236
236
// Adjust cache size based on available memory
237
237
const memoryGB = totalMemory / ( 1024 * 1024 * 1024 )
238
238
if ( memoryGB >= 16 ) {
239
239
config . cacheMaxSize = Math . min ( 5000 , config . cacheMaxSize * 2 )
240
240
} else if ( memoryGB <= 4 ) {
241
241
config . cacheMaxSize = Math . max ( 500 , config . cacheMaxSize * 0.5 )
242
242
}
243
-
243
+
244
244
return config
245
- }
245
+ }
0 commit comments