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