@@ -49,6 +49,7 @@ using namespace std;
49
49
50
50
extern SrsPps* _srs_pps_rloss;
51
51
extern SrsPps* _srs_pps_aloss;
52
+ extern SrsPps* _srs_pps_aloss2;
52
53
53
54
extern SrsPps* _srs_pps_snack2;
54
55
extern SrsPps* _srs_pps_snack3;
@@ -155,13 +156,16 @@ SrsThreadPool::SrsThreadPool()
155
156
hybrid_ = NULL ;
156
157
hybrid_high_water_level_ = 0 ;
157
158
hybrid_critical_water_level_ = 0 ;
159
+ hybrid_dying_water_level_ = 0 ;
158
160
159
161
trd_ = new SrsFastCoroutine (" pool" , this );
160
162
161
163
high_threshold_ = 0 ;
162
164
high_pulse_ = 0 ;
163
165
critical_threshold_ = 0 ;
164
166
critical_pulse_ = 0 ;
167
+ dying_threshold_ = 0 ;
168
+ dying_pulse_ = 0 ;
165
169
166
170
// Add primordial thread, current thread itself.
167
171
SrsThreadEntry* entry = new SrsThreadEntry ();
@@ -191,12 +195,17 @@ SrsThreadPool::~SrsThreadPool()
191
195
192
196
bool SrsThreadPool::hybrid_high_water_level ()
193
197
{
194
- return hybrid_critical_water_level_ || hybrid_high_water_level_;
198
+ return hybrid_critical_water_level () || hybrid_high_water_level_;
195
199
}
196
200
197
201
bool SrsThreadPool::hybrid_critical_water_level ()
198
202
{
199
- return hybrid_critical_water_level_;
203
+ return hybrid_dying_water_level () || hybrid_critical_water_level_;
204
+ }
205
+
206
+ bool SrsThreadPool::hybrid_dying_water_level ()
207
+ {
208
+ return dying_pulse_ && hybrid_dying_water_level_ >= dying_pulse_;
200
209
}
201
210
202
211
// Thread local objects.
@@ -243,6 +252,8 @@ srs_error_t SrsThreadPool::initialize()
243
252
high_pulse_ = _srs_config->get_high_pulse ();
244
253
critical_threshold_ = _srs_config->get_critical_threshold ();
245
254
critical_pulse_ = _srs_config->get_critical_pulse ();
255
+ dying_threshold_ = _srs_config->get_dying_threshold ();
256
+ dying_pulse_ = _srs_config->get_dying_pulse ();
246
257
bool async_srtp = _srs_config->get_threads_async_srtp ();
247
258
248
259
int recv_queue = _srs_config->get_threads_max_recv_queue ();
@@ -255,10 +266,10 @@ srs_error_t SrsThreadPool::initialize()
255
266
_srs_async_recv->set_tunnel_enabled (async_tunnel);
256
267
_srs_async_srtp->set_tunnel_enabled (async_tunnel);
257
268
258
- srs_trace (" Thread #%d(%s): init name=%s, interval=%dms, async_srtp=%d, cpuset=%d/%d-0x%" PRIx64 " /%d-0x%" PRIx64 " , water_level=%dx%d,%dx%d, recvQ=%d, aSend=%d, tunnel=%d" ,
269
+ srs_trace (" Thread #%d(%s): init name=%s, interval=%dms, async_srtp=%d, cpuset=%d/%d-0x%" PRIx64 " /%d-0x%" PRIx64 " , water_level=%dx%d,%dx%d,%dx%d recvQ=%d, aSend=%d, tunnel=%d" ,
259
270
entry->num , entry->label .c_str (), entry->name .c_str (), srsu2msi (interval_), async_srtp,
260
271
entry->cpuset_ok , r0, srs_covert_cpuset (entry->cpuset ), r1, srs_covert_cpuset (entry->cpuset2 ),
261
- high_pulse_, high_threshold_, critical_pulse_, critical_threshold_,
272
+ high_pulse_, high_threshold_, critical_pulse_, critical_threshold_, dying_pulse_, dying_threshold_,
262
273
recv_queue, async_send, async_tunnel);
263
274
264
275
return err;
@@ -368,6 +379,13 @@ srs_error_t SrsThreadPool::run()
368
379
} else if (hybrid_critical_water_level_ > 0 ) {
369
380
hybrid_critical_water_level_--;
370
381
}
382
+
383
+ // Reset the dying water-level when CPU is low for N times.
384
+ if (hybrid_->stat ->percent * 100 > dying_threshold_) {
385
+ hybrid_dying_water_level_ = srs_min (dying_pulse_ + 1 , hybrid_dying_water_level_ + 1 );
386
+ } else if (hybrid_dying_water_level_ > 0 ) {
387
+ hybrid_dying_water_level_ = 0 ;
388
+ }
371
389
}
372
390
373
391
sleep (1 );
@@ -419,8 +437,8 @@ srs_error_t SrsThreadPool::run()
419
437
420
438
string circuit_breaker;
421
439
if (hybrid_high_water_level () || hybrid_critical_water_level () || _srs_pps_aloss->r1s () || _srs_pps_rloss->r1s () || _srs_pps_snack2->r10s ()) {
422
- snprintf (buf, sizeof (buf), " , break=%d,%d, cond=%d,%d,%.2f%%, snk=%d,%d,%d" ,
423
- hybrid_high_water_level (), hybrid_critical_water_level (), // Whether Circuit-Break is enable.
440
+ snprintf (buf, sizeof (buf), " , break=%d,%d,%d, cond=%d,%d,%.2f%%, snk=%d,%d,%d" ,
441
+ hybrid_high_water_level (), hybrid_critical_water_level (), hybrid_dying_water_level (), // Whether Circuit-Break is enable.
424
442
_srs_pps_rloss->r1s (), _srs_pps_aloss->r1s (), thread_percent, // The conditions to enable Circuit-Breaker.
425
443
_srs_pps_snack2->r10s (), _srs_pps_snack3->r10s (), // NACK packet,seqs sent.
426
444
_srs_pps_snack4->r10s () // NACK drop by Circuit-Break.
0 commit comments