From: Sebastian Harl Date: Fri, 20 Dec 2013 08:18:34 +0000 (+0100) Subject: frontend: Make the number of handler threads configurable. X-Git-Tag: sysdb-0.1.0~302 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=60543045787cbf8f55d5a44a6e7e64ce0ba682e8;p=sysdb.git frontend: Make the number of handler threads configurable. The number is passed to listen_and_serve() as part of sdb_fe_loop_t. --- diff --git a/src/frontend/sock.c b/src/frontend/sock.c index b5a3dcd..0c4829e 100644 --- a/src/frontend/sock.c +++ b/src/frontend/sock.c @@ -452,11 +452,11 @@ sdb_fe_sock_listen_and_serve(sdb_fe_socket_t *sock, sdb_fe_loop_t *loop) int max_listen_fd = 0; size_t i; - /* XXX: make the number of threads configurable */ - pthread_t handler_threads[5]; + pthread_t handler_threads[loop->num_threads]; size_t num_threads; - if ((! sock) || (! sock->listeners_num) || (! loop) || sock->chan) + if ((! sock) || (! sock->listeners_num) || sock->chan + || (! loop) || (loop->num_threads <= 0)) return -1; if (! loop->do_loop) @@ -482,7 +482,12 @@ sdb_fe_sock_listen_and_serve(sdb_fe_socket_t *sock, sdb_fe_loop_t *loop) return -1; } - num_threads = SDB_STATIC_ARRAY_LEN(handler_threads); + sdb_log(SDB_LOG_INFO, "frontend: Starting %d connection " + "handler thread%s managing %d listener%s", + loop->num_threads, loop->num_threads == 1 ? "" : "s", + sock->listeners_num, sock->listeners_num == 1 ? "" : "s"); + + num_threads = loop->num_threads; memset(&handler_threads, 0, sizeof(handler_threads)); for (i = 0; i < num_threads; ++i) { errno = 0; diff --git a/src/include/frontend/sock.h b/src/include/frontend/sock.h index 6ab8cca..7d1fd7a 100644 --- a/src/include/frontend/sock.h +++ b/src/include/frontend/sock.h @@ -25,6 +25,8 @@ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include + #ifndef SDB_FRONTEND_SOCK_H #define SDB_FRONTEND_SOCK_H 1 @@ -34,9 +36,13 @@ extern "C" { /* manage a front-end listener loop */ typedef struct { + /* number of handler threads to create */ + size_t num_threads; + + /* front-end listener shuts down when this is set to false */ _Bool do_loop; } sdb_fe_loop_t; -#define SDB_FE_LOOP_INIT { 1 } +#define SDB_FE_LOOP_INIT { 5, 1 } /* * sdb_fe_socket_t: