From: Yehuda Sadeh Date: Tue, 29 Oct 2013 21:09:29 +0000 (-0700) Subject: rgw: more flexible frotnend handler config X-Git-Tag: v0.75~60^2~6 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=abc2177fe7597739f684bf99f0db7fc740e8f222;p=ceph.git rgw: more flexible frotnend handler config Signed-off-by: Yehuda Sadeh --- diff --git a/src/common/config_opts.h b/src/common/config_opts.h index ef9d4bd0746b..05a04a7ffee8 100644 --- a/src/common/config_opts.h +++ b/src/common/config_opts.h @@ -727,7 +727,7 @@ OPTION(rgw_bucket_quota_ttl, OPT_INT, 600) // time for cached bucket stats to be OPTION(rgw_bucket_quota_soft_threshold, OPT_DOUBLE, 0.95) // threshold from which we don't rely on cached info for quota decisions OPTION(rgw_bucket_quota_cache_size, OPT_INT, 10000) // number of entries in bucket quota cache -OPTION(rgw_standalone_server_port, OPT_INT, 0) // 0 means disabled +OPTION(rgw_frontends, OPT_STR, "") // alternative front ends OPTION(mutex_perf_counter, OPT_BOOL, false) // enable/disable mutex perf counter diff --git a/src/rgw/rgw_main.cc b/src/rgw/rgw_main.cc index adfadc907893..40fd3c5985fe 100644 --- a/src/rgw/rgw_main.cc +++ b/src/rgw/rgw_main.cc @@ -134,6 +134,7 @@ struct RGWProcessEnv { RGWRados *store; RGWREST *rest; OpsLogSocket *olog; + int port; }; class RGWProcess { @@ -459,7 +460,7 @@ static int mongoose_callback(struct mg_connection *conn) { OpsLogSocket *olog = pe->olog; RGWRequest *req = new RGWRequest; - RGWMongoose client_io(conn); + RGWMongoose client_io(conn, pe->port); client_io.init(g_ceph_context); @@ -642,39 +643,78 @@ int main(int argc, const char **argv) olog->init(g_conf->rgw_ops_log_socket_path); } - bool use_mongoose = (g_conf->rgw_standalone_server_port != 0); - struct mg_context *ctx = NULL; - RGWProcessEnv pe = { store, &rest, olog }; - - if (use_mongoose) { - char port_buf[32]; - snprintf(port_buf, sizeof(port_buf), "%d", (int)g_conf->rgw_standalone_server_port); - - char thread_pool_buf[32]; - snprintf(thread_pool_buf, sizeof(thread_pool_buf), "%d", (int)g_conf->rgw_thread_pool_size); - const char *options[] = {"listening_ports", port_buf, "enable_keep_alive", "yes", "num_threads", thread_pool_buf, NULL}; - - struct mg_callbacks cb; - memset((void *)&cb, 0, sizeof(cb)); - cb.begin_request = mongoose_callback; - ctx = mg_start(&cb, &pe, (const char **)&options); - assert(ctx); - } - - RGWProcess *pprocess = new RGWProcess(g_ceph_context, &pe, g_conf->rgw_thread_pool_size); - init_async_signal_handler(); register_async_signal_handler(SIGHUP, sighup_handler); register_async_signal_handler(SIGTERM, handle_sigterm); register_async_signal_handler(SIGINT, handle_sigterm); register_async_signal_handler(SIGUSR1, handle_sigterm); - sighandler_alrm = signal(SIGALRM, godown_alarm); + string frontend_frameworks = g_conf->rgw_frontends; + + list frontends; + + get_str_list(g_conf->rgw_frontends, frontends); + + map fe_map; + + for (list::iterator iter = frontends.begin(); iter != frontends.end(); ++iter) { + string& f = *iter; + string framework; + int port; + int pos = f.find (':'); + if (pos >= 0) { + framework = f.substr(0, pos); + string port_str = f.substr(pos + 1); + string err; + port = strict_strtol(port_str.c_str(), 10, &err); + if (!err.empty()) { + cerr << "error parsing frontend config for framework " << framework << ": " << err << std::endl; + return EINVAL; + } + } else { + framework = f; + port = 0; + } + + fe_map[framework] = port; + } + + struct mg_context *mongoose_ctx = NULL; + RGWProcessEnv *mongoose_pe = NULL; + + RGWProcessEnv fcgi_pe = { store, &rest, olog, 0 }; + + RGWProcess *pprocess = new RGWProcess(g_ceph_context, &fcgi_pe, g_conf->rgw_thread_pool_size); + + for (map::iterator fiter = fe_map.begin(); fiter != fe_map.end(); ++fiter) { + int port = fiter->second; + dout(0) << "handler: " << fiter->first << ":" << port << dendl; + if (fiter->first == "fastcgi" || fiter->first == "fcgi") { + // later + } else if (fiter->first == "mongoose") { + mongoose_pe = new RGWProcessEnv; + *mongoose_pe = { store, &rest, olog, port }; + char port_buf[32]; + snprintf(port_buf, sizeof(port_buf), "%d", port); + + char thread_pool_buf[32]; + snprintf(thread_pool_buf, sizeof(thread_pool_buf), "%d", (int)g_conf->rgw_thread_pool_size); + const char *options[] = {"listening_ports", port_buf, "enable_keep_alive", "yes", "num_threads", thread_pool_buf, NULL}; + + struct mg_callbacks cb; + memset((void *)&cb, 0, sizeof(cb)); + cb.begin_request = mongoose_callback; + mongoose_ctx = mg_start(&cb, mongoose_pe, (const char **)&options); + assert(mongoose_ctx); + } + } + + pprocess->run(); - if (use_mongoose) { - mg_stop(ctx); + if (mongoose_ctx) { + mg_stop(mongoose_ctx); } derr << "shutting down" << dendl; @@ -686,6 +726,7 @@ int main(int argc, const char **argv) shutdown_async_signal_handler(); delete pprocess; + delete mongoose_pe; if (do_swift) { swift_finalize(); diff --git a/src/rgw/rgw_mongoose.cc b/src/rgw/rgw_mongoose.cc index 416cde03a3bc..3aa493fec794 100644 --- a/src/rgw/rgw_mongoose.cc +++ b/src/rgw/rgw_mongoose.cc @@ -20,7 +20,7 @@ int RGWMongoose::write_data(const char *buf, int len) return mg_write(conn, buf, len); } -RGWMongoose::RGWMongoose(mg_connection *_conn) : conn(_conn), header_done(false), sent_header(false), has_content_length(false), +RGWMongoose::RGWMongoose(mg_connection *_conn, int _port) : conn(_conn), port(_port), header_done(false), sent_header(false), has_content_length(false), explicit_keepalive(false) { } @@ -116,9 +116,9 @@ void RGWMongoose::init_env(CephContext *cct) env.set("REMOTE_USER", info->remote_user); env.set("SCRIPT_URI", info->uri); /* FIXME */ - char port[16]; - snprintf(port, sizeof(port), "%d", cct->_conf->rgw_standalone_server_port); - env.set("SERVER_PORT", port); + char port_buf[16]; + snprintf(port_buf, sizeof(port_buf), "%d", port); + env.set("SERVER_PORT", port_buf); } int RGWMongoose::send_status(const char *status, const char *status_name) diff --git a/src/rgw/rgw_mongoose.h b/src/rgw/rgw_mongoose.h index 09bfa38156bb..c1df9f08a5bb 100644 --- a/src/rgw/rgw_mongoose.h +++ b/src/rgw/rgw_mongoose.h @@ -14,6 +14,8 @@ class RGWMongoose : public RGWClientIO bufferlist header_data; bufferlist data; + int port; + bool header_done; bool sent_header; bool has_content_length; @@ -31,7 +33,7 @@ public: int complete_request(); int send_content_length(uint64_t len); - RGWMongoose(mg_connection *_conn); + RGWMongoose(mg_connection *_conn, int _port); void flush(); };