Commit 3541f089 authored by TousakaRin's avatar TousakaRin

fix unit-test

parent 78534f7a
...@@ -160,7 +160,7 @@ void StatusService::default_method(::google::protobuf::RpcController* cntl_base, ...@@ -160,7 +160,7 @@ void StatusService::default_method(::google::protobuf::RpcController* cntl_base,
} }
const MethodStatus* mp_status = mp->status; const MethodStatus* mp_status = mp->status;
if (NULL != mp_status && mp_status->max_concurrency() > 0) { if (NULL != mp_status && mp_status->max_concurrency() > 0) {
os << " max_concurrency=" << mp->status->max_concurrency(); os << " max_concurrency=" << mp_status->max_concurrency();
} }
} }
os << "</h4>\n"; os << "</h4>\n";
......
...@@ -29,7 +29,18 @@ MethodStatus::MethodStatus() ...@@ -29,7 +29,18 @@ MethodStatus::MethodStatus()
: _cl(NULL) : _cl(NULL)
, _nprocessing_bvar(cast_nprocessing, &_nprocessing) , _nprocessing_bvar(cast_nprocessing, &_nprocessing)
, _nrefused_per_second(&_nrefused_bvar, 1) , _nrefused_per_second(&_nrefused_bvar, 1)
, _nprocessing(0) {} , _nprocessing(0) {
const ConcurrencyLimiter* cl
= ConcurrencyLimiterExtension()->Find("constant");
if (NULL == cl) {
LOG(FATAL) << "Fail to find ConcurrentLimiter by `constant`";
}
ConcurrencyLimiter* cl_copy = cl->New();
if (NULL == cl_copy) {
LOG(FATAL) << "Fail to new ConcurrencyLimiter";
}
_cl = cl_copy;
}
MethodStatus::~MethodStatus() { MethodStatus::~MethodStatus() {
if (_cl) { if (_cl) {
......
...@@ -25,7 +25,6 @@ ...@@ -25,7 +25,6 @@
namespace brpc { namespace brpc {
class Server;
class Controller; class Controller;
// Record accessing stats of a method. // Record accessing stats of a method.
class MethodStatus : public Describable { class MethodStatus : public Describable {
...@@ -58,10 +57,16 @@ public: ...@@ -58,10 +57,16 @@ public:
} }
int& max_concurrency() { return _cl->MaxConcurrency(); } int& max_concurrency() { return _cl->MaxConcurrency(); }
void ResetConcurrencyLimiter(ConcurrencyLimiter* cl) {
if (_cl) {
_cl->Destroy();
}
_cl = cl;
}
private: private:
friend class ScopedMethodStatus; friend class ScopedMethodStatus;
friend class Server;
DISALLOW_COPY_AND_ASSIGN(MethodStatus); DISALLOW_COPY_AND_ASSIGN(MethodStatus);
void OnError(); void OnError();
......
...@@ -38,7 +38,7 @@ DEFINE_int32(gradient_cl_min_sample_count, 100, ...@@ -38,7 +38,7 @@ DEFINE_int32(gradient_cl_min_sample_count, 100,
DEFINE_int32(gradient_cl_adjust_smooth, 50, DEFINE_int32(gradient_cl_adjust_smooth, 50,
"Smooth coefficient for adjust the max concurrency, the value is 0-99," "Smooth coefficient for adjust the max concurrency, the value is 0-99,"
"the larger the value, the smaller the amount of each change"); "the larger the value, the smaller the amount of each change");
DEFINE_int32(gradient_cl_initial_max_concurrency, 600, DEFINE_int32(gradient_cl_initial_max_concurrency, 400,
"Initial max concurrency for grandient concurrency limiter"); "Initial max concurrency for grandient concurrency limiter");
DEFINE_bool(gradient_cl_enable_error_punish, true, DEFINE_bool(gradient_cl_enable_error_punish, true,
"Whether to consider failed requests when calculating maximum concurrency"); "Whether to consider failed requests when calculating maximum concurrency");
......
...@@ -889,33 +889,32 @@ int Server::StartInternal(const butil::ip_t& ip, ...@@ -889,33 +889,32 @@ int Server::StartInternal(const butil::ip_t& ip,
LOG(FATAL) << "Fail to new ConcurrencyLimiter"; LOG(FATAL) << "Fail to new ConcurrencyLimiter";
} }
_cl = cl_copy; _cl = cl_copy;
if (_options.max_concurrency == "constant") { if (_options.max_concurrency == "constant") {
_cl->MaxConcurrency() = _options.max_concurrency; _cl->MaxConcurrency() = _options.max_concurrency;
} else { } else {
_cl->MaxConcurrency() = 0; _cl->MaxConcurrency() = 0;
} for (MethodMap::iterator it = _method_map.begin();
it != _method_map.end(); ++it) {
for (MethodMap::iterator it = _method_map.begin(); if (it->second.is_builtin_service) {
it != _method_map.end(); ++it) { continue;
if (NULL != it->second.status->_cl) { }
continue; const ConcurrencyLimiter* cl = NULL;
} cl = ConcurrencyLimiterExtension()->Find(
const ConcurrencyLimiter* cl = NULL; _options.max_concurrency.name().c_str());
const std::string cl_name = it->second.is_builtin_service ? if (NULL == cl) {
"constant" : _options.max_concurrency.name(); LOG(FATAL) << "Fail to find ConcurrencyLimiter by `"
cl = ConcurrencyLimiterExtension()->Find(cl_name.c_str()); << _options.max_concurrency.name() << '`';
if (NULL == cl) { return -1;
LOG(FATAL) << "Fail to find ConcurrencyLimiter by `" }
<< _options.max_concurrency.name() << '`'; ConcurrencyLimiter* cl_copy = cl->New();
return -1; if (NULL == cl_copy) {
} LOG(FATAL) << "Fail to find ConcurrencyLimiter by `"
ConcurrencyLimiter* cl_copy = cl->New(); << _options.max_concurrency.name() << '`';
if (NULL == cl_copy) { return -1;
LOG(FATAL) << "Fail to find ConcurrencyLimiter by `" }
<< _options.max_concurrency.name() << '`'; it->second.status->ResetConcurrencyLimiter(cl_copy);
return -1;
} }
it->second.status->_cl = cl_copy;
} }
// Create listening ports // Create listening ports
......
...@@ -119,8 +119,7 @@ struct ServerOptions { ...@@ -119,8 +119,7 @@ struct ServerOptions {
// NOTE: Once you have chosen the automatic concurrency limit strategy, brpc // NOTE: Once you have chosen the automatic concurrency limit strategy, brpc
// ONLY limits concurrency at the method level, And each method will use // ONLY limits concurrency at the method level, And each method will use
// the strategy you set in ServerOptions to limit the maximum concurrency, // the strategy you set in ServerOptions to limit the maximum concurrency,
// unless you have set a maximum concurrency for this method before starting // even if you have set a maximum concurrency through `SetMaxConcurrencyOf`.
// the server.
AdaptiveMaxConcurrency max_concurrency; AdaptiveMaxConcurrency max_concurrency;
......
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