From: Adam Dickmeiss Date: Wed, 3 Feb 2010 08:40:21 +0000 (+0100) Subject: Number of worker-threads controlled by main config X-Git-Tag: v1.4.0~148 X-Git-Url: http://lists.indexdata.com/cgi-bin?a=commitdiff_plain;h=43696f40bf1d08065a96a175d5b81ecfff78d507;p=pazpar2-moved-to-github.git Number of worker-threads controlled by main config The number of worker-threads may be controlled by threads@number in main config. A value of 0, disables worker-threads - and operates as older versions of Pazpar2. --- diff --git a/doc/pazpar2_conf.xml b/doc/pazpar2_conf.xml index 013b264..de76d9d 100644 --- a/doc/pazpar2_conf.xml +++ b/doc/pazpar2_conf.xml @@ -52,14 +52,24 @@ elements specific to Pazpar2 should belong to the namespace http://www.indexdata.com/pazpar2/1.0 (this is assumed in the - following examples). The root element is named pazpar2. + following examples). The root element is named "pazpar2". Under the root element are a number of elements which group categories of information. The categories are described below. + threads + + This section is optional and is supported for Pazpar2 version 1.3.1 and + later . It is identified by element "threads" which + may include one attribute "number" which specifies + the number of worker-threads that the Pazpar2 instance is to use. + A value of 0 (zero) disables worker-threads (all work is carried out + in main thread). + + server - This section governs overall behavior of the server. It is identified + This section governs overall behavior of a server endpoint. It is identified by the element "server" which takes an optional attribute, "id", which identifies this particular Pazpar2 server. Any string value for "id" may be given. @@ -450,6 +460,7 @@ + diff --git a/src/eventl.c b/src/eventl.c index 3a74751..870d089 100644 --- a/src/eventl.c +++ b/src/eventl.c @@ -59,16 +59,16 @@ struct iochan_man_s { IOCHAN channel_list; sel_thread_t sel_thread; int sel_fd; - int use_threads; + int no_threads; }; -iochan_man_t iochan_man_create(int use_threads) +iochan_man_t iochan_man_create(int no_threads) { iochan_man_t man = xmalloc(sizeof(*man)); man->channel_list = 0; man->sel_thread = 0; /* can't create sel_thread yet because we may fork */ man->sel_fd = -1; - man->use_threads = use_threads; + man->no_threads = no_threads; return man; } @@ -275,11 +275,12 @@ static int event_loop(iochan_man_t man, IOCHAN *iochans) void iochan_man_events(iochan_man_t man) { - if (man->use_threads && !man->sel_thread) + if (man->no_threads > 0 && !man->sel_thread) { man->sel_thread = sel_thread_create( - work_handler, 0 /*work_destroy */, &man->sel_fd, 10); - yaz_log(YLOG_LOG, "iochan_man_events. sel_thread started"); + work_handler, 0 /*work_destroy */, &man->sel_fd, man->no_threads); + yaz_log(YLOG_LOG, "iochan_man_events. Using %d threads", + man->no_threads); } event_loop(man, &man->channel_list); } diff --git a/src/eventl.h b/src/eventl.h index 442684e..e53776c 100644 --- a/src/eventl.h +++ b/src/eventl.h @@ -55,7 +55,7 @@ typedef struct iochan } *IOCHAN; -iochan_man_t iochan_man_create(int use_threads); +iochan_man_t iochan_man_create(int no_threads); void iochan_add(iochan_man_t man, IOCHAN chan); void iochan_man_events(iochan_man_t man); void iochan_man_destroy(iochan_man_t *mp); diff --git a/src/logic.c b/src/logic.c index d4db2e1..0180c27 100644 --- a/src/logic.c +++ b/src/logic.c @@ -810,9 +810,9 @@ void statistics(struct session *se, struct statistics *stat) // Master list of connections we're handling events to static iochan_man_t pazpar2_chan_man = 0; /* thread pr */ -void pazpar2_chan_man_start(void) +void pazpar2_chan_man_start(int no_threads) { - pazpar2_chan_man = iochan_man_create(0 /* use threads */); + pazpar2_chan_man = iochan_man_create(no_threads); } void pazpar2_add_channel(IOCHAN chan) diff --git a/src/pazpar2.c b/src/pazpar2.c index 3a43ed5..4905399 100644 --- a/src/pazpar2.c +++ b/src/pazpar2.c @@ -194,7 +194,6 @@ static int sc_main( "mode"); return 1; } - pazpar2_chan_man_start(); ret = config_start_listeners(config, listener_override); if (ret) return ret; /* error starting http listener */ diff --git a/src/pazpar2_config.c b/src/pazpar2_config.c index 86f401a..fb62e99 100644 --- a/src/pazpar2_config.c +++ b/src/pazpar2_config.c @@ -47,6 +47,7 @@ struct conf_config { NMEM nmem; /* for conf_config and servers memory */ struct conf_server *servers; + int no_threads; WRBUF confdir; }; @@ -903,6 +904,15 @@ static int parse_config(struct conf_config *config, xmlNode *root) tmp->next = config->servers; config->servers = tmp; } + else if (!strcmp((const char *) n->name, "threads")) + { + xmlChar *number = xmlGetProp(n, (xmlChar *) "number"); + if (number) + { + config->no_threads = atoi(number); + xmlFree(number); + } + } else if (!strcmp((const char *) n->name, "targetprofiles")) { yaz_log(YLOG_FATAL, "targetprofiles unsupported here. Must be part of service"); @@ -938,6 +948,7 @@ struct conf_config *config_create(const char *fname, int verbose) config->nmem = nmem; config->servers = 0; + config->no_threads = 0; config->confdir = wrbuf_alloc(); if ((p = strrchr(fname, @@ -1031,6 +1042,7 @@ int config_start_listeners(struct conf_config *conf, const char *listener_override) { struct conf_server *ser; + pazpar2_chan_man_start(conf->no_threads); for (ser = conf->servers; ser; ser = ser->next) { WRBUF w = wrbuf_alloc(); diff --git a/src/test_sel_thread.c b/src/test_sel_thread.c index d54059d..372af4e 100644 --- a/src/test_sel_thread.c +++ b/src/test_sel_thread.c @@ -107,7 +107,7 @@ static void test_for_real_work(int no_threads) YAZ_CHECK(p); if (p) { - iochan_man_t chan_man = iochan_man_create(1 /* use_threads */); + iochan_man_t chan_man = iochan_man_create(10); IOCHAN chan = iochan_create(thread_fd, iochan_handler, EVENT_INPUT|EVENT_TIMEOUT); iochan_settimeout(chan, 1);