]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
Make thread pool size configurable & allow client connection limit
authorDaniel P. Berrange <berrange@redhat.com>
Thu, 4 Dec 2008 22:18:44 +0000 (22:18 +0000)
committerDaniel P. Berrange <berrange@redhat.com>
Thu, 4 Dec 2008 22:18:44 +0000 (22:18 +0000)
ChangeLog
qemud/libvirtd.aug
qemud/libvirtd.conf
qemud/qemud.c
qemud/test_libvirtd.aug

index 65a2c3273334744bbfd8871856c1a5afa431d679..be9147d51c36ffbff9a0227425dfb4c7c9da5d5f 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+Thu Dec  4 22:18:41 GMT 2008 Daniel P. Berrange <berrange@redhat.com>
+
+       * qemud/qemud.c: Read number of threads for RPC dispatch
+       from config. Allow a limit on total client connection
+       count.
+       * qemud/libvirtd.conf: Add max_clients and max_workers
+       and min_workers config vars
+       * qemud/libvirtd.aug, qemud/test_libvirtd.aug: Augeas
+       support for new config params
+
 Thu Dec  4 22:16:41 GMT 2008 Daniel P. Berrange <berrange@redhat.com>
 
        Make daemon use a thread pool for handling RPC calls
index 3cf21f68008f0d16aec25204edf7574d3add0e72..fdb25072ac1aca1e8b4032bbafe51553cb6c4a05 100644 (file)
@@ -13,11 +13,13 @@ module Libvirtd =
 
    let str_val = del /\"/ "\"" . store /[^\"]*/ . del /\"/ "\""
    let bool_val = store /0|1/
+   let int_val = store /[0-9]+/
    let str_array_element = [ seq "el" . str_val ] . del /[ \t\n]*/ ""
    let str_array_val = counter "el" . array_start . ( str_array_element . ( array_sep . str_array_element ) * ) ? . array_end
 
    let str_entry       (kw:string) = [ key kw . value_sep . str_val ]
    let bool_entry      (kw:string) = [ key kw . value_sep . bool_val ]
+   let int_entry      (kw:string) = [ key kw . value_sep . int_val ]
    let str_array_entry (kw:string) = [ key kw . value_sep . str_array_val ]
 
 
@@ -48,6 +50,9 @@ module Libvirtd =
                            | str_array_entry "tls_allowed_dn_list"
                            | str_array_entry "sasl_allowed_username_list"
 
+   let processing_entry = int_entry "min_workers"
+                        | int_entry "max_workers"
+                        | int_entry "max_clients"
 
    (* Each enty in the config is one of the following three ... *)
    let entry = network_entry
@@ -55,6 +60,7 @@ module Libvirtd =
              | authentication_entry
              | certificate_entry
              | authorization_entry
+             | processing_entry
    let comment = [ label "#comment" . del /#[ \t]*/ "# " .  store /([^ \t\n][^\n]*)?/ . del /\n/ "\n" ]
    let empty = [ label "#empty" . eol ]
 
index a12a897a1dcc3e294ee57d9987383ea4f14d5049..cd82e8bc4d1510ed543c737616b66eec454b7eef 100644 (file)
 #sasl_allowed_username_list = ["joe@EXAMPLE.COM", "fred@EXAMPLE.COM" ]
 
 
+
+#################################################################
+#
+# Processing controls
+#
+
+# The maximum number of concurrent client connections to allow
+# over all sockets combined.
+#max_clients = 20
+
+
+# The minimum limit sets the number of workers to start up
+# initially. If the number of active clients exceeds this,
+# then more threads are spawned, upto max_workers limit.
+# Typically you'd want max_workers to equal maximum number
+# of clients allowed
+#min_workers = 5
+#max_workers = 20
+
index 312abff0c8e7106e0636866f7e0f4dd650173fef..f35d0fdb05860fa6a25d78c68e7439d67cf75f24 100644 (file)
@@ -130,6 +130,10 @@ static char *crl_file = (char *) "";
 static gnutls_certificate_credentials_t x509_cred;
 static gnutls_dh_params_t dh_params;
 
+static int min_workers = 5;
+static int max_workers = 20;
+static int max_clients = 20;
+
 #define DH_BITS 1024
 
 static sig_atomic_t sig_errors = 0;
@@ -1174,6 +1178,12 @@ static int qemudDispatchServer(struct qemud_server *server, struct qemud_socket
         return -1;
     }
 
+    if (server->nclients >= max_clients) {
+        qemudLog(QEMUD_ERR, "%s", _("Too many active clients, dropping connection"));
+        close(fd);
+        return -1;
+    }
+
     if (VIR_REALLOC_N(server->clients, server->nclients+1) < 0) {
         qemudLog(QEMUD_ERR, "%s", _("Out of memory allocating clients"));
         close(fd);
@@ -1832,7 +1842,7 @@ static int qemudRunLoop(struct qemud_server *server) {
 
     pthread_mutex_lock(&server->lock);
 
-    server->nworkers = 10;
+    server->nworkers = min_workers;
     if (VIR_ALLOC_N(server->workers, server->nworkers) < 0) {
         qemudLog(QEMUD_ERR, "%s", _("Failed to allocate workers"));
         return -1;
@@ -2229,6 +2239,11 @@ remoteReadConfigFile (struct qemud_server *server, const char *filename)
     if (remoteReadSaslAllowedUsernameList (conf, server, filename) < 0)
         goto free_and_fail;
 
+
+    GET_CONF_INT (conf, filename, min_workers);
+    GET_CONF_INT (conf, filename, max_workers);
+    GET_CONF_INT (conf, filename, max_clients);
+
     virConfFree (conf);
     return 0;
 
index c05fb4c7495147edcfdaefee3eb7b89eee58e339..f3c00b7ff587e2d61a8b59166727453a7d7feec9 100644 (file)
@@ -227,6 +227,25 @@ sasl_allowed_username_list = [
   \"joe@EXAMPLE.COM\",
   \"fred@EXAMPLE.COM\"
 ]
+
+
+#################################################################
+#
+# Processing controls
+#
+
+# The maximum number of concurrent client connections to allow
+# over all sockets combined.
+max_clients = 20
+
+
+# The minimum limit sets the number of workers to start up
+# initially. If the number of active clients exceeds this,
+# then more threads are spawned, upto max_workers limit.
+# Typically you'd want max_workers to equal maximum number
+# of clients allowed
+min_workers = 5
+max_workers = 20
 "
 
    test Libvirtd.lns get conf =
@@ -461,3 +480,22 @@ sasl_allowed_username_list = [
              { "1" = "joe@EXAMPLE.COM" }
              { "2" = "fred@EXAMPLE.COM" }
         }
+        { "#empty" }
+        { "#empty" }
+        { "#comment" = "################################################################"}
+        { "#comment" = ""}
+        { "#comment" = "Processing controls"}
+        { "#comment" = ""}
+        { "#empty" }
+        { "#comment" = "The maximum number of concurrent client connections to allow"}
+        { "#comment" = "over all sockets combined."}
+        { "max_clients" = "20" }
+        { "#empty" }
+        { "#empty" }
+        { "#comment" = "The minimum limit sets the number of workers to start up"}
+        { "#comment" = "initially. If the number of active clients exceeds this,"}
+        { "#comment" = "then more threads are spawned, upto max_workers limit."}
+        { "#comment" = "Typically you'd want max_workers to equal maximum number"}
+        { "#comment" = "of clients allowed"}
+        { "min_workers" = "5" }
+        { "max_workers" = "20" }