Commit 74929cfc authored by TousakaRin's avatar TousakaRin

Modify the naming, move health_score and isolated_times to DebugSocket

parent fa91ba42
...@@ -122,9 +122,7 @@ void ConnectionsService::PrintConnections( ...@@ -122,9 +122,7 @@ void ConnectionsService::PrintConnections(
os << "<th>SSL</th>" os << "<th>SSL</th>"
"<th>Protocol</th>" "<th>Protocol</th>"
"<th>fd</th>" "<th>fd</th>"
"<th>error_count</th>" "<th>acc_errors</th>"
"<th>health_index</th>"
"<th>broken_times</th>"
"<th>InBytes/s</th>" "<th>InBytes/s</th>"
"<th>In/s</th>" "<th>In/s</th>"
"<th>InBytes/m</th>" "<th>InBytes/m</th>"
...@@ -141,8 +139,7 @@ void ConnectionsService::PrintConnections( ...@@ -141,8 +139,7 @@ void ConnectionsService::PrintConnections(
if (need_local) { if (need_local) {
os << "Local|"; os << "Local|";
} }
os << "SSL|Protocol |fd |" os << "SSL|Protocol |fd |acc_errors|"
"error_count|health_index|broken_times|"
"InBytes/s|In/s |InBytes/m |In/m |" "InBytes/s|In/s |InBytes/m |In/m |"
"OutBytes/s|Out/s |OutBytes/m|Out/m |" "OutBytes/s|Out/s |OutBytes/m|Out/m |"
"Rtt/Var(ms)|SocketId\n"; "Rtt/Var(ms)|SocketId\n";
...@@ -181,9 +178,7 @@ void ConnectionsService::PrintConnections( ...@@ -181,9 +178,7 @@ void ConnectionsService::PrintConnections(
os << min_width("-", 3) << bar os << min_width("-", 3) << bar
<< min_width("-", 12) << bar << min_width("-", 12) << bar
<< min_width("-", 5) << bar << min_width("-", 5) << bar
<< min_width(ptr->error_count(), 11) << bar << min_width(ptr->acc_errors(), 10) << bar
<< min_width("0", 12) << bar
<< min_width(ptr->broken_times(), 12) << bar
<< min_width("-", 9) << bar << min_width("-", 9) << bar
<< min_width("-", 6) << bar << min_width("-", 6) << bar
<< min_width("-", 10) << bar << min_width("-", 10) << bar
...@@ -295,9 +290,7 @@ void ConnectionsService::PrintConnections( ...@@ -295,9 +290,7 @@ void ConnectionsService::PrintConnections(
} else { } else {
os << min_width("-", 5) << bar; os << min_width("-", 5) << bar;
} }
os << min_width(ptr->error_count(), 11) << bar os << min_width(ptr->acc_errors(), 10) << bar
<< min_width(ptr->health_index_in_percent(), 12) << bar
<< min_width(ptr->broken_times(), 12) << bar
<< min_width(stat.in_size_s, 9) << bar << min_width(stat.in_size_s, 9) << bar
<< min_width(stat.in_num_messages_s, 6) << bar << min_width(stat.in_num_messages_s, 6) << bar
<< min_width(stat.in_size_m, 10) << bar << min_width(stat.in_size_m, 10) << bar
......
...@@ -94,7 +94,7 @@ int64_t CircuitBreaker::EmaErrorRecorder::max_error_cost() const { ...@@ -94,7 +94,7 @@ int64_t CircuitBreaker::EmaErrorRecorder::max_error_cost() const {
return ema_latency * _window_size * (_max_error_percent / 100.0) * (1.0 + EPSILON); return ema_latency * _window_size * (_max_error_percent / 100.0) * (1.0 + EPSILON);
} }
int CircuitBreaker::EmaErrorRecorder::health_index_in_percent() const { int CircuitBreaker::EmaErrorRecorder::health_score() const {
const int64_t current_error_cost = _ema_error_cost.load(butil::memory_order_relaxed); const int64_t current_error_cost = _ema_error_cost.load(butil::memory_order_relaxed);
const int64_t error_cost_threshold = max_error_cost(); const int64_t error_cost_threshold = max_error_cost();
if (error_cost_threshold == 0) { if (error_cost_threshold == 0) {
...@@ -160,7 +160,7 @@ CircuitBreaker::CircuitBreaker() ...@@ -160,7 +160,7 @@ CircuitBreaker::CircuitBreaker()
FLAGS_circuit_breaker_short_window_error_percent) FLAGS_circuit_breaker_short_window_error_percent)
, _last_reset_time_ms(butil::cpuwide_time_ms()) , _last_reset_time_ms(butil::cpuwide_time_ms())
, _isolation_duration_ms(FLAGS_circuit_breaker_min_isolation_duration_ms) , _isolation_duration_ms(FLAGS_circuit_breaker_min_isolation_duration_ms)
, _broken_times(0) { , _isolated_times(0) {
} }
bool CircuitBreaker::OnCallEnd(int error_code, int64_t latency) { bool CircuitBreaker::OnCallEnd(int error_code, int64_t latency) {
...@@ -175,13 +175,12 @@ void CircuitBreaker::Reset() { ...@@ -175,13 +175,12 @@ void CircuitBreaker::Reset() {
} }
void CircuitBreaker::MarkAsBroken() { void CircuitBreaker::MarkAsBroken() {
++_broken_times; ++_isolated_times;
UpdateIsolationDuration(); UpdateIsolationDuration();
} }
int CircuitBreaker::health_index_in_percent() const { int CircuitBreaker::health_score() const {
return std::min(_long_window.health_index_in_percent(), return std::min(_long_window.health_score(), _short_window.health_score());
_short_window.health_index_in_percent());
} }
void CircuitBreaker::UpdateIsolationDuration() { void CircuitBreaker::UpdateIsolationDuration() {
......
...@@ -44,11 +44,11 @@ public: ...@@ -44,11 +44,11 @@ public:
// The closer to 100, the less recent errors occurred, and 0 means that // The closer to 100, the less recent errors occurred, and 0 means that
// it should be isolated. // it should be isolated.
int health_index_in_percent() const; int health_score() const;
// Number of times marked as broken // Number of times marked as broken
int broken_times() const { int isolated_times() const {
return _broken_times; return _isolated_times;
} }
// The duration that should be isolated when the socket fails in milliseconds. // The duration that should be isolated when the socket fails in milliseconds.
...@@ -67,7 +67,7 @@ private: ...@@ -67,7 +67,7 @@ private:
void Reset(); void Reset();
int64_t max_error_cost() const; int64_t max_error_cost() const;
int health_index_in_percent() const; int health_score() const;
private: private:
int64_t UpdateLatency(int64_t latency); int64_t UpdateLatency(int64_t latency);
...@@ -86,7 +86,7 @@ private: ...@@ -86,7 +86,7 @@ private:
EmaErrorRecorder _short_window; EmaErrorRecorder _short_window;
int64_t _last_reset_time_ms; int64_t _last_reset_time_ms;
int _isolation_duration_ms; int _isolation_duration_ms;
int _broken_times; int _isolated_times;
}; };
} // namespace brpc } // namespace brpc
......
...@@ -178,7 +178,7 @@ public: ...@@ -178,7 +178,7 @@ public:
CircuitBreaker circuit_breaker; CircuitBreaker circuit_breaker;
butil::atomic<uint64_t> error_count; butil::atomic<uint64_t> acc_errors;
explicit SharedPart(SocketId creator_socket_id); explicit SharedPart(SocketId creator_socket_id);
~SharedPart(); ~SharedPart();
...@@ -196,7 +196,7 @@ Socket::SharedPart::SharedPart(SocketId creator_socket_id2) ...@@ -196,7 +196,7 @@ Socket::SharedPart::SharedPart(SocketId creator_socket_id2)
, out_size(0) , out_size(0)
, out_num_messages(0) , out_num_messages(0)
, extended_stat(NULL) , extended_stat(NULL)
, error_count(0) { , acc_errors(0) {
} }
Socket::SharedPart::~SharedPart() { Socket::SharedPart::~SharedPart() {
...@@ -806,33 +806,17 @@ int Socket::ReleaseAdditionalReference() { ...@@ -806,33 +806,17 @@ int Socket::ReleaseAdditionalReference() {
} }
void Socket::AddErrorCount() { void Socket::AddErrorCount() {
GetOrNewSharedPart()->error_count.fetch_add(1, butil::memory_order_relaxed); GetOrNewSharedPart()->acc_errors.fetch_add(1, butil::memory_order_relaxed);
} }
int Socket::broken_times() const { uint64_t Socket::acc_errors() const {
SharedPart* sp = GetSharedPart(); SharedPart* sp = GetSharedPart();
if (sp) { if (sp) {
return sp->circuit_breaker.broken_times(); return sp->acc_errors.load(butil::memory_order_relaxed);
} }
return 0; return 0;
} }
uint64_t Socket::error_count() const {
SharedPart* sp = GetSharedPart();
if (sp) {
return sp->error_count.load(butil::memory_order_relaxed);
}
return 0;
}
int Socket::health_index_in_percent() const {
SharedPart* sp = GetSharedPart();
if (sp) {
return sp->circuit_breaker.health_index_in_percent();
}
return 100;
}
int Socket::SetFailed(int error_code, const char* error_fmt, ...) { int Socket::SetFailed(int error_code, const char* error_fmt, ...) {
if (error_code == 0) { if (error_code == 0) {
CHECK(false) << "error_code is 0"; CHECK(false) << "error_code is 0";
...@@ -2151,6 +2135,9 @@ void Socket::DebugSocket(std::ostream& os, SocketId id) { ...@@ -2151,6 +2135,9 @@ void Socket::DebugSocket(std::ostream& os, SocketId id) {
<< "\n in_num_messages=" << sp->in_num_messages.load(butil::memory_order_relaxed) << "\n in_num_messages=" << sp->in_num_messages.load(butil::memory_order_relaxed)
<< "\n out_size=" << sp->out_size.load(butil::memory_order_relaxed) << "\n out_size=" << sp->out_size.load(butil::memory_order_relaxed)
<< "\n out_num_messages=" << sp->out_num_messages.load(butil::memory_order_relaxed) << "\n out_num_messages=" << sp->out_num_messages.load(butil::memory_order_relaxed)
<< "\n health_score=" << sp->circuit_breaker.health_score()
<< "\n isolated_times=" << sp->circuit_breaker.isolated_times()
<< "\n acc_errors=" << sp->acc_errors.load(butil::memory_order_relaxed)
<< "\n}"; << "\n}";
} }
const int fd = ptr->_fd.load(butil::memory_order_relaxed); const int fd = ptr->_fd.load(butil::memory_order_relaxed);
......
...@@ -319,11 +319,7 @@ public: ...@@ -319,11 +319,7 @@ public:
void AddErrorCount(); void AddErrorCount();
uint64_t error_count() const; uint64_t acc_errors() const;
int broken_times() const;
int health_index_in_percent() const;
void FeedbackCircuitBreaker(int error_code, int64_t latency_us); void FeedbackCircuitBreaker(int error_code, int64_t latency_us);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment