d4e835
diff -up bind-9.8.2rc1/bin/named/include/named/lwresd.h.lwres_tasks_clients bind-9.8.2rc1/bin/named/include/named/lwresd.h
d4e835
--- bind-9.8.2rc1/bin/named/include/named/lwresd.h.lwres_tasks_clients	2007-06-20 01:46:59.000000000 +0200
d4e835
+++ bind-9.8.2rc1/bin/named/include/named/lwresd.h	2014-05-19 09:41:56.792427201 +0200
d4e835
@@ -36,6 +36,8 @@ struct ns_lwresd {
d4e835
 	dns_view_t *view;
d4e835
 	ns_lwsearchlist_t *search;
d4e835
 	unsigned int ndots;
d4e835
+	unsigned int ntasks;
d4e835
+	unsigned int nclients;
d4e835
 	isc_mem_t *mctx;
d4e835
 	isc_boolean_t shutting_down;
d4e835
 	unsigned int refs;
d4e835
diff -up bind-9.8.2rc1/bin/named/lwresd.c.lwres_tasks_clients bind-9.8.2rc1/bin/named/lwresd.c
d4e835
--- bind-9.8.2rc1/bin/named/lwresd.c.lwres_tasks_clients	2009-09-03 01:48:01.000000000 +0200
d4e835
+++ bind-9.8.2rc1/bin/named/lwresd.c	2014-05-19 09:41:56.793427201 +0200
d4e835
@@ -60,11 +60,7 @@
d4e835
 #define LWRESLISTENER_MAGIC	ISC_MAGIC('L', 'W', 'R', 'L')
d4e835
 #define VALID_LWRESLISTENER(l)	ISC_MAGIC_VALID(l, LWRESLISTENER_MAGIC)
d4e835
 
d4e835
-/*!
d4e835
- * The total number of clients we can handle will be NTASKS * NRECVS.
d4e835
- */
d4e835
-#define NTASKS		2	/*%< tasks to create to handle lwres queries */
d4e835
-#define NRECVS		2	/*%< max clients per task */
d4e835
+#define LWRESD_NCLIENTS_MAX		32768	/*%< max clients per task */
d4e835
 
d4e835
 typedef ISC_LIST(ns_lwreslistener_t) ns_lwreslistenerlist_t;
d4e835
 
d4e835
@@ -395,6 +391,24 @@ ns_lwdmanager_create(isc_mem_t *mctx, co
d4e835
 		}
d4e835
 	}
d4e835
 
d4e835
+	obj = NULL;
d4e835
+	(void)cfg_map_get(lwres, "lwres-tasks", &obj);
d4e835
+	if (obj != NULL)
d4e835
+		lwresd->ntasks = cfg_obj_asuint32(obj);
d4e835
+	else
d4e835
+		lwresd->ntasks = ns_g_cpus;
d4e835
+
d4e835
+	obj = NULL;
d4e835
+	(void)cfg_map_get(lwres, "lwres-clients", &obj);
d4e835
+	if (obj != NULL) {
d4e835
+		lwresd->nclients = cfg_obj_asuint32(obj);
d4e835
+		if (lwresd->nclients > LWRESD_NCLIENTS_MAX)
d4e835
+			lwresd->nclients = LWRESD_NCLIENTS_MAX;
d4e835
+	} else if (ns_g_lwresdonly)
d4e835
+		lwresd->nclients = 1024;
d4e835
+	else
d4e835
+		lwresd->nclients = 256;
d4e835
+
d4e835
 	lwresd->magic = LWRESD_MAGIC;
d4e835
 
d4e835
 	*lwresdp = lwresd;
d4e835
@@ -604,15 +618,24 @@ static isc_result_t
d4e835
 listener_startclients(ns_lwreslistener_t *listener) {
d4e835
 	ns_lwdclientmgr_t *cm;
d4e835
 	unsigned int i;
d4e835
-	isc_result_t result;
d4e835
+	isc_result_t result = ISC_R_SUCCESS;
d4e835
+
d4e835
+	isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
d4e835
+		      NS_LOGMODULE_LWRESD, ISC_LOG_DEBUG(6),
d4e835
+		      "listener_startclients: creating %d "
d4e835
+		      "managers with %d clients each",
d4e835
+		      listener->manager->ntasks, listener->manager->nclients);
d4e835
 
d4e835
 	/*
d4e835
 	 * Create the client managers.
d4e835
 	 */
d4e835
-	result = ISC_R_SUCCESS;
d4e835
-	for (i = 0; i < NTASKS && result == ISC_R_SUCCESS; i++)
d4e835
-		result = ns_lwdclientmgr_create(listener, NRECVS,
d4e835
+	for (i = 0; i < listener->manager->ntasks; i++) {
d4e835
+		result = ns_lwdclientmgr_create(listener,
d4e835
+						listener->manager->nclients,
d4e835
 						ns_g_taskmgr);
d4e835
+		if (result != ISC_R_SUCCESS)
d4e835
+			break;
d4e835
+	}
d4e835
 
d4e835
 	/*
d4e835
 	 * Ensure that we have created at least one.
d4e835
diff -up bind-9.8.2rc1/bin/named/named.conf.docbook.lwres_tasks_clients bind-9.8.2rc1/bin/named/named.conf.docbook
d4e835
--- bind-9.8.2rc1/bin/named/named.conf.docbook.lwres_tasks_clients	2011-11-07 01:31:47.000000000 +0100
d4e835
+++ bind-9.8.2rc1/bin/named/named.conf.docbook	2014-05-19 09:41:56.793427201 +0200
d4e835
@@ -185,6 +185,8 @@ lwres {
d4e835
 	view <replaceable>string</replaceable> <replaceable>optional_class</replaceable>;
d4e835
 	search { <replaceable>string</replaceable>; ... };
d4e835
 	ndots <replaceable>integer</replaceable>;
d4e835
+	lwres-tasks <replaceable>integer</replaceable>;
d4e835
+	lwres-clients <replaceable>integer</replaceable>;
d4e835
 };
d4e835
 </literallayout>
d4e835
   </refsect1>
d4e835
diff -up bind-9.8.2rc1/doc/arm/Bv9ARM-book.xml.lwres_tasks_clients bind-9.8.2rc1/doc/arm/Bv9ARM-book.xml
d4e835
--- bind-9.8.2rc1/doc/arm/Bv9ARM-book.xml.lwres_tasks_clients	2014-05-19 09:41:56.770427201 +0200
d4e835
+++ bind-9.8.2rc1/doc/arm/Bv9ARM-book.xml	2014-05-19 10:26:40.147380836 +0200
d4e835
@@ -2964,7 +2964,12 @@ $ORIGIN 0.0.0.0.0.0.0.0.8.b.d.0.1.0.0.2.
d4e835
         be configured to act as a lightweight resolver daemon using the
d4e835
         <command>lwres</command> statement in <filename>named.conf</filename>.
d4e835
       </para>
d4e835
-
d4e835
+      <para>
d4e835
+        The number of client queries that the <command>lwresd</command>
d4e835
+        daemon is able to serve can be set using the
d4e835
+        <option>lwres-tasks</option> and <option>lwres-clients</option> 
d4e835
+        statements in the configuration.
d4e835
+      </para>
d4e835
     </sect1>
d4e835
   </chapter>
d4e835
 
d4e835
@@ -4959,6 +4964,8 @@ badresp:1,adberr:0,findfail:0,valfail:0]
d4e835
     <optional> view <replaceable>view_name</replaceable>; </optional>
d4e835
     <optional> search { <replaceable>domain_name</replaceable> ; <optional> <replaceable>domain_name</replaceable> ; ... </optional> }; </optional>
d4e835
     <optional> ndots <replaceable>number</replaceable>; </optional>
d4e835
+    <optional> lwres-tasks <replaceable>number</replaceable>; </optional>
d4e835
+    <optional> lwres-clients <replaceable>number</replaceable>; </optional>
d4e835
 };
d4e835
 </programlisting>
d4e835
 
d4e835
@@ -5017,6 +5024,31 @@ badresp:1,adberr:0,findfail:0,valfail:0]
d4e835
           number of dots in a relative domain name that should result in an
d4e835
           exact match lookup before search path elements are appended.
d4e835
         </para>
d4e835
+        <para>
d4e835
+          The <option>lwres-tasks</option> statement specifies the number
d4e835
+          of worker threads the lightweight resolver will dedicate to serving
d4e835
+          clients.  By default the number is the same as the number of CPUs on
d4e835
+          the system; this can be overridden using the <option>-n</option>
d4e835
+          command line option when starting the server. 
d4e835
+        </para>
d4e835
+        <para>
d4e835
+          The <option>lwres-clients</option> specifies
d4e835
+          the number of client objects per thread the lightweight
d4e835
+          resolver should create to serve client queries.
d4e835
+          By default, if the lightweight resolver runs as a part
d4e835
+          of <command>named</command>, 256 client objects are
d4e835
+          created for each task; if it runs as <command>lwresd</command>,
d4e835
+          1024 client objects are created for each thread. The maximum
d4e835
+          value is 32768; higher values will be silently ignored and
d4e835
+          the maximum will be used instead.
d4e835
+          Note that setting too high a value may overconsume
d4e835
+          system resources.
d4e835
+        </para>
d4e835
+        <para>
d4e835
+          The maximum number of client queries that the lightweight
d4e835
+          resolver can handle at any one time equals
d4e835
+          <option>lwres-tasks</option> times <option>lwres-clients</option>.
d4e835
+        </para>
d4e835
       </sect2>
d4e835
       <sect2>
d4e835
         <title><command>masters</command> Statement Grammar</title>
d4e835
diff -up bind-9.8.2rc1/lib/isccfg/namedconf.c.lwres_tasks_clients bind-9.8.2rc1/lib/isccfg/namedconf.c
d4e835
--- bind-9.8.2rc1/lib/isccfg/namedconf.c.lwres_tasks_clients	2014-05-19 09:41:56.771427201 +0200
d4e835
+++ bind-9.8.2rc1/lib/isccfg/namedconf.c	2014-05-19 09:41:56.797427201 +0200
d4e835
@@ -2563,6 +2563,8 @@ lwres_clauses[] = {
d4e835
 	{ "view", &cfg_type_lwres_view, 0 },
d4e835
 	{ "search", &cfg_type_lwres_searchlist, 0 },
d4e835
 	{ "ndots", &cfg_type_uint32, 0 },
d4e835
+	{ "lwres-tasks", &cfg_type_uint32, 0},
d4e835
+	{ "lwres-clients", &cfg_type_uint32, 0},
d4e835
 	{ NULL, NULL, 0 }
d4e835
 };
d4e835