@@ -135,6 +135,7 @@ export class HyperionMaster {
135
135
private wsRouterWorker : cluster . Worker ;
136
136
private liveBlockQueue : AsyncQueue < any > ;
137
137
private readingPaused = false ;
138
+ private readingLimited = false ;
138
139
139
140
// Hyperion Hub Socket
140
141
private hub : SocketIOClient . Socket ;
@@ -1178,74 +1179,80 @@ export class HyperionMaster {
1178
1179
queue = `${ this . chain } :ds_pool:${ worker . local_id } ` ;
1179
1180
}
1180
1181
1181
- if ( queue ) {
1182
- if ( ! testedQueues . has ( queue ) ) {
1183
- testedQueues . add ( queue ) ;
1182
+ if ( queue && ! testedQueues . has ( queue ) ) {
1184
1183
1185
- const size = await this . manager . checkQueueSize ( queue ) ;
1184
+ const size = await this . manager . checkQueueSize ( queue ) ;
1186
1185
1186
+ // pause readers if queues are above the max_limit
1187
+ if ( size >= this . conf . scaling . max_queue_limit ) {
1188
+ this . readingPaused = true ;
1189
+ for ( const worker of this . workerMap ) {
1190
+ if ( worker . worker_role === 'reader' ) {
1191
+ worker . wref . send ( { event : 'pause' } ) ;
1192
+ }
1193
+ }
1194
+ }
1195
+
1196
+ // resume readers if the queues are below the trigger point
1197
+ if ( size <= this . conf . scaling . resume_trigger ) {
1187
1198
1188
- // pause readers if queues are above the max_limit
1189
- if ( size >= this . conf . scaling . max_queue_limit ) {
1190
- this . readingPaused = true ;
1199
+ // remove flow limiter
1200
+ if ( this . readingLimited ) {
1201
+ this . readingLimited = false ;
1191
1202
for ( const worker of this . workerMap ) {
1192
1203
if ( worker . worker_role === 'reader' ) {
1193
- worker . wref . send ( { event : 'pause' } ) ;
1204
+ worker . wref . send ( { event : 'set_delay' , data : { state : false , delay : 0 } } ) ;
1194
1205
}
1195
1206
}
1196
1207
}
1197
1208
1198
- // resume readers if the queues are below the trigger point
1199
- if ( ( this . readingPaused && size <= this . conf . scaling . resume_trigger ) ) {
1209
+ // fully unpause
1210
+ if ( this . readingPaused ) {
1200
1211
this . readingPaused = false ;
1201
1212
for ( const worker of this . workerMap ) {
1202
1213
if ( worker . worker_role === 'reader' ) {
1203
1214
worker . wref . send ( { event : 'pause' } ) ;
1204
- worker . wref . send ( {
1205
- event : 'set_delay' ,
1206
- data : {
1207
- state : false ,
1208
- delay : 0
1209
- }
1210
- } ) ;
1211
1215
}
1212
1216
}
1213
1217
}
1218
+ }
1214
1219
1215
- // apply block processing delay if 20% below max
1216
- if ( size >= this . conf . scaling . max_queue_limit * 0.8 ) {
1217
- for ( const worker of this . workerMap ) {
1218
- if ( worker . worker_role === 'reader' ) {
1219
- worker . wref . send ( {
1220
- event : 'set_delay' ,
1221
- data : {
1222
- state : true ,
1223
- delay : 250
1224
- }
1225
- } ) ;
1226
- }
1220
+ // apply block processing delay on 80% usage
1221
+ if ( size >= this . conf . scaling . max_queue_limit * 0.8 ) {
1222
+ this . readingLimited = true ;
1223
+ for ( const worker of this . workerMap ) {
1224
+ if ( worker . worker_role === 'reader' ) {
1225
+ worker . wref . send ( {
1226
+ event : 'set_delay' ,
1227
+ data : {
1228
+ state : true ,
1229
+ delay : 250
1230
+ }
1231
+ } ) ;
1227
1232
}
1228
1233
}
1234
+ }
1229
1235
1230
1236
1231
- if ( worker . worker_role === 'ingestor' ) {
1232
- if ( size > limit ) {
1233
- if ( ! autoscaleConsumers [ queue ] ) {
1234
- autoscaleConsumers [ queue ] = 0 ;
1235
- }
1236
- if ( autoscaleConsumers [ queue ] < this . conf . scaling . max_autoscale ) {
1237
- hLog ( `${ queue } is above the limit (${ size } /${ limit } ). Launching consumer...` ) ;
1238
- this . addWorker ( {
1239
- queue : queue ,
1240
- type : worker . type ,
1241
- worker_role : 'ingestor'
1242
- } ) ;
1243
- this . launchWorkers ( ) ;
1244
- autoscaleConsumers [ queue ] ++ ;
1245
- }
1237
+ if ( worker . worker_role === 'ingestor' ) {
1238
+ if ( size > limit ) {
1239
+ if ( ! autoscaleConsumers [ queue ] ) {
1240
+ autoscaleConsumers [ queue ] = 0 ;
1241
+ }
1242
+ if ( autoscaleConsumers [ queue ] < this . conf . scaling . max_autoscale ) {
1243
+ hLog ( `${ queue } is above the limit (${ size } /${ limit } ). Launching consumer...` ) ;
1244
+ this . addWorker ( {
1245
+ queue : queue ,
1246
+ type : worker . type ,
1247
+ worker_role : 'ingestor'
1248
+ } ) ;
1249
+ this . launchWorkers ( ) ;
1250
+ autoscaleConsumers [ queue ] ++ ;
1246
1251
}
1247
1252
}
1248
1253
}
1254
+
1255
+ testedQueues . add ( queue ) ;
1249
1256
}
1250
1257
}
1251
1258
}
0 commit comments