Number of worker-threads controlled by main config
authorAdam Dickmeiss <adam@indexdata.dk>
Wed, 3 Feb 2010 08:40:21 +0000 (09:40 +0100)
committerAdam Dickmeiss <adam@indexdata.dk>
Wed, 3 Feb 2010 08:40:21 +0000 (09:40 +0100)
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.

doc/pazpar2_conf.xml
src/eventl.c
src/eventl.h
src/logic.c
src/pazpar2.c
src/pazpar2_config.c
src/test_sel_thread.c

index 013b264..de76d9d 100644 (file)
    elements specific to Pazpar2 should belong to the namespace
    <literal>http://www.indexdata.com/pazpar2/1.0</literal> 
    (this is assumed in the
    elements specific to Pazpar2 should belong to the namespace
    <literal>http://www.indexdata.com/pazpar2/1.0</literal> 
    (this is assumed in the
-   following examples). The root element is named <literal>pazpar2</literal>.
+   following examples). The root element is named "<literal>pazpar2</literal>".
    Under the  root element are a number of elements which group categories of
    information. The categories are described below.
   </para>
   
    Under the  root element are a number of elements which group categories of
    information. The categories are described below.
   </para>
   
+  <refsect2 id="config-threads"><title>threads</title>
+    <para>
+      This section is optional and is supported for Pazpar2 version 1.3.1 and
+      later . It is identified by element "<literal>threads</literal>" which
+      may include one attribute "<literal>number</literal>" 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).
+    </para>
+  </refsect2>
   <refsect2 id="config-server"><title>server</title>
    <para>
   <refsect2 id="config-server"><title>server</title>
    <para>
-    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.
     by the element "server" which takes an optional attribute, "id", which
     identifies this particular Pazpar2 server. Any string value for "id"
     may be given.
     <?xml version="1.0" encoding="UTF-8"?>
     <pazpar2 xmlns="http://www.indexdata.com/pazpar2/1.0">
     
     <?xml version="1.0" encoding="UTF-8"?>
     <pazpar2 xmlns="http://www.indexdata.com/pazpar2/1.0">
     
+      <threads number="10"/>
       <server>
         <listen port="9004"/>
         <service>
       <server>
         <listen port="9004"/>
         <service>
index 3a74751..870d089 100644 (file)
@@ -59,16 +59,16 @@ struct iochan_man_s {
     IOCHAN channel_list;
     sel_thread_t sel_thread;
     int sel_fd;
     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;
 {
     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;
 }
 
     return man;
 }
 
@@ -275,11 +275,12 @@ static int event_loop(iochan_man_t man, IOCHAN *iochans)
 
 void iochan_man_events(iochan_man_t man)
 {
 
 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(
     {
         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);
 }
     }
     event_loop(man, &man->channel_list);
 }
index 442684e..e53776c 100644 (file)
@@ -55,7 +55,7 @@ typedef struct iochan
 } *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);
 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);
index d4db2e1..0180c27 100644 (file)
@@ -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 */
 
 // 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)
 }
 
 void pazpar2_add_channel(IOCHAN chan)
index 3a43ed5..4905399 100644 (file)
@@ -194,7 +194,6 @@ static int sc_main(
                     "mode");
             return 1;
         }
                     "mode");
             return 1;
         }
-        pazpar2_chan_man_start();
         ret = config_start_listeners(config, listener_override);
         if (ret)
             return ret; /* error starting http listener */
         ret = config_start_listeners(config, listener_override);
         if (ret)
             return ret; /* error starting http listener */
index 86f401a..fb62e99 100644 (file)
@@ -47,6 +47,7 @@ struct conf_config
 {
     NMEM nmem; /* for conf_config and servers memory */
     struct conf_server *servers;
 {
     NMEM nmem; /* for conf_config and servers memory */
     struct conf_server *servers;
+    int no_threads;
     WRBUF confdir;
 };
 
     WRBUF confdir;
 };
 
@@ -903,6 +904,15 @@ static int parse_config(struct conf_config *config, xmlNode *root)
             tmp->next = config->servers;
             config->servers = tmp;
         }
             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");
         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->nmem = nmem;
     config->servers = 0;
+    config->no_threads = 0;
 
     config->confdir = wrbuf_alloc();
     if ((p = strrchr(fname, 
 
     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;
                            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();
     for (ser = conf->servers; ser; ser = ser->next)
     {
         WRBUF w = wrbuf_alloc();
index d54059d..372af4e 100644 (file)
@@ -107,7 +107,7 @@ static void test_for_real_work(int no_threads)
     YAZ_CHECK(p);
     if (p)
     {
     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);
         IOCHAN chan = iochan_create(thread_fd, iochan_handler,
                                     EVENT_INPUT|EVENT_TIMEOUT);
         iochan_settimeout(chan, 1);