[systemd-devel] [PATCH 4/4] core: lazy distribute for Distribute pools

Shawn Landden shawn at churchofgit.com
Sat Nov 16 13:18:15 PST 2013


---
 man/systemd.socket.xml                | 9 +++++++++
 src/core/dbus-socket.c                | 2 ++
 src/core/load-fragment-gperf.gperf.m4 | 1 +
 src/core/socket.c                     | 7 ++++++-
 src/core/socket.h                     | 1 +
 5 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/man/systemd.socket.xml b/man/systemd.socket.xml
index 4a2189b..fd6ec69 100644
--- a/man/systemd.socket.xml
+++ b/man/systemd.socket.xml
@@ -530,6 +530,15 @@
                         </varlistentry>
 
                         <varlistentry>
+                                <term><varname>LazyDistribute=</varname></term>
+                                <listitem><para>Takes an boolean
+                                value. If true, Distribute=n workers will not be spawned
+                                simultameously, but one at a time while connections come it
+                                until n are running. Because of the nature of SO_REUSEPORT workers are
+                                spawned at an exponentially decreasing rate to the number of incoming connections.</para></listitem>
+                        </varlistentry>
+
+                        <varlistentry>
                                 <term><varname>SmackLabel=</varname></term>
                                 <term><varname>SmackLabelIPIn=</varname></term>
                                 <term><varname>SmackLabelIPOut=</varname></term>
diff --git a/src/core/dbus-socket.c b/src/core/dbus-socket.c
index 4644007..4e2a31d 100644
--- a/src/core/dbus-socket.c
+++ b/src/core/dbus-socket.c
@@ -69,6 +69,7 @@
         "  <property name=\"Result\" type=\"s\" access=\"read\"/>\n"    \
         "  <property name=\"ReusePort\" type=\"b\" access=\"read\"/>\n" \
         "  <property name=\"Distribute\" type=\"u\" access=\"read\"/>\n" \
+        "  <property name=\"LazyDistribute\" type=\"b\" access=\"read\"/>\n" \
         "  <property name=\"SmackLabel\" type=\"s\" access=\"read\"/>\n" \
         "  <property name=\"SmackLabelIPIn\" type=\"s\" access=\"read\"/>\n" \
         "  <property name=\"SmackLabelIPOut\" type=\"s\" access=\"read\"/>\n" \
@@ -198,6 +199,7 @@ static const BusProperty bus_socket_properties[] = {
         { "Result",         bus_socket_append_socket_result,   "s", offsetof(Socket, result)          },
         { "ReusePort",      bus_property_append_bool,          "b", offsetof(Socket, reuseport)       },
         { "Distribute",     bus_property_append_unsigned,      "u", offsetof(Socket, distribute)       },
+        { "LazyDistribute", bus_property_append_bool,          "b", offsetof(Socket, lazy_distribute)       },
         { "SmackLabel",     bus_property_append_string,        "s", offsetof(Socket, smack),          true },
         { "SmackLabelIPIn", bus_property_append_string,        "s", offsetof(Socket, smack_ip_in),    true },
         { "SmackLabelIPOut",bus_property_append_string,        "s", offsetof(Socket, smack_ip_out),   true },
diff --git a/src/core/load-fragment-gperf.gperf.m4 b/src/core/load-fragment-gperf.gperf.m4
index 4058a1f..a023b0e 100644
--- a/src/core/load-fragment-gperf.gperf.m4
+++ b/src/core/load-fragment-gperf.gperf.m4
@@ -212,6 +212,7 @@ Socket.PassSecurity,             config_parse_bool,                  0,
 Socket.TCPCongestion,            config_parse_string,                0,                             offsetof(Socket, tcp_congestion)
 Socket.ReusePort,                config_parse_bool,                  0,                             offsetof(Socket, reuseport)
 Socket.Distribute,               config_parse_unsigned,              0,                             offsetof(Socket, distribute)
+Socket.LazyDistribute,           config_parse_bool,                  0,                             offsetof(Socket, lazy_distribute)
 Socket.MessageQueueMaxMessages,  config_parse_long,                  0,                             offsetof(Socket, mq_maxmsg)
 Socket.MessageQueueMessageSize,  config_parse_long,                  0,                             offsetof(Socket, mq_msgsize)
 Socket.Service,                  config_parse_socket_service,        0,                             0
diff --git a/src/core/socket.c b/src/core/socket.c
index 4d4627a..a85ae88 100644
--- a/src/core/socket.c
+++ b/src/core/socket.c
@@ -514,6 +514,11 @@ static void socket_dump(Unit *u, FILE *f, const char *prefix) {
                         "%sDistribute: %d\n",
                          prefix, s->distribute);
 
+        if (s->lazy_distribute)
+                fprintf(f,
+                        "%sLazyDistribute: %s\n",
+                         prefix, yes_no(s->lazy_distribute));
+
         if (s->smack)
                 fprintf(f,
                         "%sSmackLabel: %s\n",
@@ -1545,7 +1550,7 @@ static void socket_enter_running(Socket *s, int cfd) {
 
                         if (s->n_connections < s->distribute)
                                 socket_enter_listening(s);
-                } while (s->n_connections < s->distribute);
+                } while (s->n_connections < s->distribute && !(s->lazy_distribute));
 
                 /* Notify clients about changed counters */
                 unit_add_to_dbus_queue(UNIT(s));
diff --git a/src/core/socket.h b/src/core/socket.h
index 5928356..98fe680 100644
--- a/src/core/socket.h
+++ b/src/core/socket.h
@@ -149,6 +149,7 @@ struct Socket {
         bool reuseport;
         /* implies reuseport */
         unsigned distribute;
+        bool lazy_distribute;
         long mq_maxmsg;
         long mq_msgsize;
 
-- 
1.8.4.3



More information about the systemd-devel mailing list