On Thu, Mar 03, 2016 at 12:13:22AM -0800, Andy Zhou wrote: > Add the basic infrastructure to create and destroy threads that > will be used to handle jsonrpc sessions. > > This patch implements a simple logic to create thread on demand. > Using number of sessions a server services as an rough measure of > system load, A jsonrpc server creates more threads as the number of > sessions exceeds a pre defined number of session per thread, Until > a user specified maximum is reached. > > The threading model is simple. OVSDB server starts up with no threads > (This is required to handle the --run option). Once created, > a thread is never destroyed until the OVSDB server is shut down. > > Session thread does not do anything useful. In fact, the threads > won't even be created because the max number threads is hard coded > to zero. Later patch will create and make use of those threads. > > Signed-off-by: Andy Zhou <az...@ovn.org>
Seems like a good start! I'm going to ack this but I'd prefer to get more functionality reviewed before you push it. Acked-by: Ben Pfaff <b...@ovn.org> Some style suggestions: diff --git a/ovsdb/jsonrpc-server.c b/ovsdb/jsonrpc-server.c index 7c674ba..b890a88 100644 --- a/ovsdb/jsonrpc-server.c +++ b/ovsdb/jsonrpc-server.c @@ -129,7 +129,7 @@ struct ovsdb_jsonrpc_server { struct ovs_list all_sessions; /* All 'ovsdb_jsonrpc_session's managed by the main process. Those are sessions created before multithreading, or - connections of active remotes.. */ + connections of active remotes. */ /* Threads. */ size_t n_max_threads; @@ -147,7 +147,7 @@ ovsdb_jsonrpc_server_cast(struct ovsdb_server *s) { /* The minimal number of sessions per thread, before a new thread will be * added, until 'n_max_threads' is reached. Once created, the thread * will not destroyed. */ -#define N_SESSIONS_THREASHHOLD (2) +#define N_SESSIONS_THRESHOLD (2) static bool ovsdb_jsonrpc_server_use_threads(struct ovsdb_jsonrpc_server *); /* A configured remote. This is either a passive stream listener plus a list @@ -167,7 +167,7 @@ static void ovsdb_jsonrpc_server_del_remote(struct shash_node *); /* Creates and returns a new server to provide JSON-RPC access to an OVSDB. * - * 'max_threads' limits * the number of threads it can create. + * 'max_threads' limits the number of threads it can create. * * The caller must call ovsdb_jsonrpc_server_add_db() for each database to * which 'server' should provide access. */ @@ -224,13 +224,12 @@ void ovsdb_jsonrpc_server_destroy(struct ovsdb_jsonrpc_server *svr) { struct shash_node *node, *next; - size_t i; SHASH_FOR_EACH_SAFE (node, next, &svr->remotes) { ovsdb_jsonrpc_server_del_remote(node); } - for (i = 0; i < svr->n_active_threads; i++) { + for (size_t i = 0; i < svr->n_active_threads; i++) { struct sessions_thread *thread = &svr->threads[i]; sessions_thread_exit(thread); } @@ -446,11 +445,12 @@ ovsdb_jsonrpc_server_get_memory_usage(const struct ovsdb_jsonrpc_server *svr, } static bool -ovsdb_jsonrpc_server_use_threads(struct ovsdb_jsonrpc_server *svr) { +ovsdb_jsonrpc_server_use_threads(struct ovsdb_jsonrpc_server *svr) +{ if (svr->n_active_threads != svr->n_max_threads) { /* Look up the number of sessions to decide if there is a need * for a new thread. */ - size_t n_desired_threads = svr->n_sessions / N_SESSIONS_THREASHHOLD; + size_t n_desired_threads = svr->n_sessions / N_SESSIONS_THRESHOLD; if (n_desired_threads > svr->n_active_threads) { sessions_thread_init(&svr->threads[svr->n_active_threads++]); _______________________________________________ dev mailing list dev@openvswitch.org http://openvswitch.org/mailman/listinfo/dev