----- Original Message ----
> 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> > --- > ovsdb/jsonrpc-server.c | 100 +++++++++++++++++++++++++++++++++++++++++++ +++--- > ovsdb/jsonrpc-server.h | 4 +- > ovsdb/ovsdb-server.c | 4 +- > 3 files changed, 98 insertions(+), 10 deletions(-) > > diff --git a/ovsdb/jsonrpc-server.c b/ovsdb/jsonrpc-server.c > index 660250d..63788ec 100644 > --- a/ovsdb/jsonrpc-server.c > +++ b/ovsdb/jsonrpc-server.c > @@ -25,6 +25,8 @@ > #include "monitor.h" > #include "json.h" > #include "jsonrpc.h" > +#include "latch.h" > +#include "ovs-thread.h" > #include "ovsdb-error.h" > #include "ovsdb-parser.h" > #include "ovsdb.h" > @@ -107,13 +109,32 @@ static struct json *ovsdb_jsonrpc_monitor_compose_update( > struct ovsdb_jsonrpc_monitor *monitor, bool initial); > > > +struct sessions_thread { > + pthread_t thread; > + > + /* Controls thread exit. */ > + struct latch exit_latch; > +}; > + > +static void sessions_thread_init(struct sessions_thread *); > +static void sessions_thread_exit(struct sessions_thread *); > + > + > /* JSON-RPC database server. */ > > struct ovsdb_jsonrpc_server { > struct ovsdb_server up; > unsigned int n_sessions; > struct shash remotes; /* Contains "struct ovsdb_jsonrpc_remote *"s. */ > - struct ovs_list all_sessions; /* All 'ovsdb_jsonrpc_session's. */ > + 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.. */ Ah, this answers my previous concern about all_sessions - carry on... > + > + /* Threads. */ > + size_t n_max_threads; > + size_t n_active_threads; > + struct sessions_thread *threads; > }; > > /* Cast an 'ovsdb_server' pointer down into an ovsdb_jsonrpc_server pinter. > @@ -123,6 +144,12 @@ ovsdb_jsonrpc_server_cast(struct ovsdb_server *s) { > return CONTAINER_OF(s, struct ovsdb_jsonrpc_server, up); > } > > +/* 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) Typo here (and elsewhere) - I think you meant N_SESSIONS_THRESHHOLD? Other than the potential typo above, Acked-by: Ryan Moats <rmo...@us.ibm.com> _______________________________________________ dev mailing list dev@openvswitch.org http://openvswitch.org/mailman/listinfo/dev