]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
[MINOR] add the "nolinger" option to disable data lingering
authorAlexandre Cassen <acassen@freebox.fr>
Thu, 11 Oct 2007 18:48:58 +0000 (20:48 +0200)
committerWilly Tarreau <w@1wt.eu>
Mon, 15 Oct 2007 07:33:06 +0000 (09:33 +0200)
The following patch will give the ability to tweak socket linger mode.
You can use this option with "option nolinger" inside fronted or backend
configuration declaration.

This will help in environments where lots of FIN_WAIT sockets are
encountered.

doc/configuration.txt
doc/haproxy-en.txt
doc/haproxy-fr.txt
include/types/backend.h
include/types/global.h
src/backend.c
src/cfgparse.c
src/client.c
src/haproxy.c
src/proxy.c

index 12a7eb76dc131c9cbbc9bfc36c836cb7008fcb37..86f3f3325c161de8860297445fc38317a28d459e 100644 (file)
@@ -2,9 +2,9 @@
                                  HAProxy
                           Configuration Manual
                          ----------------------
-                             version 1.3.12.1
+                             version 1.3.12.3
                              willy tarreau
-                               2007/07/25
+                               2007/09/11
 
 
 This document covers the configuration language as implemented in the version
@@ -247,6 +247,7 @@ option httpchk              X          -         X         X
 option httpclose            X          X         X         X
 option httplog              X          X         X         X
 option logasap              X          X         X         -
+option nolinger             X          X         X         X
 option persist              X          -         X         X
 option redispatch           X          -         X         X
 option smtpchk              X          -         X         X
index d18f59a0d5a26f4a3c82b691710e39029e850320..09d311e52e6ca3669f9eb861e6f2d68398aae97a 100644 (file)
@@ -1525,6 +1525,17 @@ options to enable TCP keep-alive :
        option clitcpka # enables keep-alive only on client side
        option srvtcpka # enables keep-alive only on server side
 
+4.1.4) TCP lingering
+--------------------
+It is possible to disable the system's lingering of data unacked by the client
+at the end of a session. This is sometimes required when haproxy is used as a
+front-end with lots of unreliable clients, and you observe thousands of sockets
+in the FIN_WAIT state on the machine. This may be used in a frontend to affect
+the client-side connection, as well as in a backend for the server-side
+connection :
+
+       option nolinger # disables data lingering
+
 
 4.2) Event logging
 ------------------
index eafe4365ae3feaa12845ec33b1df9fcaa6cbd1ae..d29259fc7c71dc18070e6fc2ad676366a7a7ada5 100644 (file)
@@ -1562,6 +1562,17 @@ pour activer le maintien de session TCP :
        option clitcpka # active le keep-alive côté client
        option srvtcpka # active le keep-alive côté serveur
 
+4.1.4) Rémanence des données TCP (lingering)
+--------------------------------------------
+Il est possible de désactiver la conservation de données non acquittées par un
+client à la fin d'une session. Cela peut parfois s'avérer nécessaire lorsque
+haproxy est utilisé en face d'un grand nombre de clients non fiables et qu'un
+nombre élevé de sockets en état FIN_WAIT est observé sur la machine. L'option
+peut être utilisée dans un frontend pour ajuster les connexions vers les
+clients, et dans un backend pour ajuster les connexions vers les serveurs :
+
+       option nolinger # désactive la conservation de données
+
 
 4.2) Journalisation des connexions
 ----------------------------------
index 57a8cb053ab0787a993dd7b1a86de290e8ea126f..921eaed89ed451149f49c6496ddb9fb9c408b720 100644 (file)
@@ -60,6 +60,7 @@
 #define PR_O_BALANCE_UH 0x10000000      /* balance on URI hash */
 #define PR_O_BALANCE    (PR_O_BALANCE_RR | PR_O_BALANCE_SH | PR_O_BALANCE_UH)
 #define PR_O_SMTP_CHK   0x20000000      /* use SMTP EHLO check for server health - pvandijk@vision6.com.au */
+#define PR_O_TCP_NOLING 0x40000000      /* disable lingering on client and server connections */
 
 
 #endif /* _TYPES_BACKEND_H */
index b25995491ec132adf5dd345e882eb1ed375cf443..f2de0d94683990e7d363841d2a2ab7aacf695291 100644 (file)
@@ -73,6 +73,7 @@ extern int listeners;
 extern char trash[BUFSIZE];
 extern const int zero;
 extern const int one;
+extern const struct linger nolinger;
 extern int stopping;   /* non zero means stopping in progress */
 
 #endif /* _TYPES_GLOBAL_H */
index da8b8ac36a92e0811d92124466300ee550f68bb2..91c0b34b2942f51260b56931fe759ab3d84c1e00 100644 (file)
@@ -408,6 +408,9 @@ int connect_server(struct session *s)
        if (s->be->options & PR_O_TCP_SRV_KA)
                setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, (char *) &one, sizeof(one));
 
+       if (s->be->options & PR_O_TCP_NOLING)
+               setsockopt(fd, SOL_SOCKET, SO_LINGER, (struct linger *) &nolinger, sizeof(struct linger));
+
        /* allow specific binding :
         * - server-specific at first
         * - proxy-specific next
index e361356bdffa5d85f92acf3f4b56dab879c4f29c..19b2ee71adf53aecdcd843067329f0592ad21766 100644 (file)
@@ -92,6 +92,7 @@ static const struct {
        { "redispatch",   PR_O_REDISP,     PR_CAP_BE, 0 },
        { "keepalive",    PR_O_KEEPALIVE,  PR_CAP_NONE, 0 },
        { "httpclose",    PR_O_HTTP_CLOSE, PR_CAP_FE | PR_CAP_BE, 0 },
+       { "nolinger",     PR_O_TCP_NOLING, PR_CAP_FE | PR_CAP_BE, 0 },
        { "logasap",      PR_O_LOGASAP,    PR_CAP_FE, 0 },
        { "abortonclose", PR_O_ABRT_CLOSE, PR_CAP_BE, 0 },
        { "checkcache",   PR_O_CHK_CACHE,  PR_CAP_BE, 0 },
index 87495a4a59ea21621e6e65c00860b2b9d75beddb..1f58154c2f4eb42868850b245cffc80be1e46588 100644 (file)
@@ -165,6 +165,9 @@ int event_accept(int fd) {
                if (p->options & PR_O_TCP_CLI_KA)
                        setsockopt(cfd, SOL_SOCKET, SO_KEEPALIVE, (char *) &one, sizeof(one));
 
+               if (p->options & PR_O_TCP_NOLING)
+                       setsockopt(cfd, SOL_SOCKET, SO_LINGER, (struct linger *) &nolinger, sizeof(struct linger));
+
                t->wq = NULL;
                t->qlist.p = NULL;
                t->state = TASK_IDLE;
index fc0cda14eaf59283441ef8a7f9fcfab17cc45562..4437d45b019f5184b5288158a137839db52addcd 100644 (file)
@@ -135,6 +135,7 @@ char trash[BUFSIZE];
 
 const int zero = 0;
 const int one = 1;
+const struct linger nolinger = { .l_onoff = 1, .l_linger = 0 };
 
 /*
  * Syslog facilities and levels. Conforming to RFC3164.
index 7d4b2ec08bde3c43eb50fd9c86b4e94cced85c2c..bd33c84e0bafbc507bcc1c77193339a1c55beb2b 100644 (file)
@@ -26,6 +26,7 @@
 #include <types/polling.h>
 
 #include <proto/client.h>
+#include <proto/backend.h>
 #include <proto/fd.h>
 #include <proto/log.h>
 #include <proto/proxy.h>
@@ -113,6 +114,9 @@ int start_proxies(int verbose)
                                Alert("cannot do so_reuseaddr for proxy %s. Continuing.\n",
                                      curproxy->id);
                        }
+
+                       if (curproxy->options & PR_O_TCP_NOLING)
+                               setsockopt(fd, SOL_SOCKET, SO_LINGER, (struct linger *) &nolinger, sizeof(struct linger));
        
 #ifdef SO_REUSEPORT
                        /* OpenBSD supports this. As it's present in old libc versions of Linux,