以rgw服务的main()为入口,查看整个fastcgi的初始化过程,代码如下
代码语言:javascript复制#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作为实参传递进去。
代码语言:javascript复制#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,代码定义如下
代码语言:javascript复制#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,代码注释中也提到这是为了确保能够尽可能多的处理请求。
代码语言:javascript复制#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。