今天就跟大家聊聊有关如何用源码解读提高RGW最大并发数,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。
源码解读如何提高RGW最大并发数
以rgw服务的main()为入口,查看整个fastcgi的初始化过程,代码如下
#src/rgw/rgw_main.cc
int main(int argc, const char **argv)
if (framework == "fastcgi" || framework == "fcgi") {
RGWProcessEnv fcgi_pe = { store, &rest, olog, 0 };
fe = new RGWFCGXFrontend(fcgi_pe, config);
dout(0) << "starting handler: " << fiter->first << dendl;
int r = fe->init(); #调用RGWFCGXFrontend的init()方法
再看init()方法构建了一个RGWFCGXProcess,并将rgw_thread_pool_size作为实参传递进去。
#src/rgw/rgw_frontend.h
class RGWFCGXFrontend : public RGWProcessFrontend {
public:
RGWFCGXFrontend(RGWProcessEnv& pe, RGWFrontendConfig* _conf)
: RGWProcessFrontend(pe, _conf) {}
int init() {
pprocess = new RGWFCGXProcess(g_ceph_context, &env,
g_conf->rgw_thread_pool_size, conf);
return 0;
}
};
默认rgw_thread_pool_size为100,代码定义如下
#src/common/config_opts.h
OPTION(rgw_thread_pool_size, OPT_INT, 100)
通过RGWFCGXProcess的构造函数发现max_connections=num_threads + (num_threads >> 3),也就是说默认情况下max_connections=100+1=101,代码注释中也提到这是为了确保能够尽可能多的处理请求。
#src/rgw/rgw_process.h
class RGWFCGXProcess : public RGWProcess {
int max_connections;
public:
/* have a bit more connections than threads so that requests are
* still accepted even if we're still processing older requests */
RGWFCGXProcess(CephContext* cct, RGWProcessEnv* pe, int num_threads,
RGWFrontendConfig* _conf)
: RGWProcess(cct, pe, num_threads, _conf),
max_connections(num_threads + (num_threads >> 3))
{}
void run();
void handle_request(RGWRequest* req);
};
所以num_threads控制着max_connections的数量,如果你想提高单个rgw进程的最大并发数量,需要调高rgw_thread_pool_size。
看完上述内容,你们对如何用源码解读提高RGW最大并发数有进一步的了解吗?如果还想了解更多知识或者相关内容,请关注天达云行业资讯频道,感谢大家的支持。