mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
RTC: Support circuit breaker. 4.0.103
This commit is contained in:
parent
46c980c70a
commit
92fc0af8f4
13 changed files with 434 additions and 9 deletions
67
trunk/src/app/srs_app_threads.hpp
Normal file
67
trunk/src/app/srs_app_threads.hpp
Normal file
|
@ -0,0 +1,67 @@
|
|||
/**
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2013-2020 Winlin
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
* this software and associated documentation files (the "Software"), to deal in
|
||||
* the Software without restriction, including without limitation the rights to
|
||||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
* the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
* subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef SRS_APP_THREADS_HPP
|
||||
#define SRS_APP_THREADS_HPP
|
||||
|
||||
#include <srs_core.hpp>
|
||||
|
||||
#include <srs_app_hourglass.hpp>
|
||||
|
||||
// Protect server in high load.
|
||||
class SrsCircuitBreaker : public ISrsFastTimer
|
||||
{
|
||||
private:
|
||||
// The config for high/critical water level.
|
||||
bool enabled_;
|
||||
int high_threshold_;
|
||||
int high_pulse_;
|
||||
int critical_threshold_;
|
||||
int critical_pulse_;
|
||||
int dying_threshold_;
|
||||
int dying_pulse_;
|
||||
private:
|
||||
// Reset the water-level when CPU is low for N times.
|
||||
// @note To avoid the CPU change rapidly.
|
||||
int hybrid_high_water_level_;
|
||||
int hybrid_critical_water_level_;
|
||||
int hybrid_dying_water_level_;
|
||||
public:
|
||||
SrsCircuitBreaker();
|
||||
virtual ~SrsCircuitBreaker();
|
||||
public:
|
||||
srs_error_t initialize();
|
||||
public:
|
||||
// Whether hybrid server water-level is high.
|
||||
bool hybrid_high_water_level();
|
||||
bool hybrid_critical_water_level();
|
||||
bool hybrid_dying_water_level();
|
||||
// interface ISrsFastTimer
|
||||
private:
|
||||
srs_error_t on_timer(srs_utime_t interval);
|
||||
};
|
||||
|
||||
extern SrsCircuitBreaker* _srs_circuit_breaker;
|
||||
|
||||
#endif
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue