]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
[MEDIUM] implement tcp-smart-connect option at the backend
authorWilly Tarreau <w@1wt.eu>
Sun, 14 Jun 2009 13:48:17 +0000 (15:48 +0200)
committerWilly Tarreau <w@1wt.eu>
Sun, 14 Jun 2009 13:48:17 +0000 (15:48 +0200)
This new option enables combining of request buffer data with
the initial ACK of an outgoing TCP connection. Doing so saves
one packet per connection which is quite noticeable on workloads
mostly consisting in small objects. The option is not enabled by
default.

doc/configuration.txt
include/types/proxy.h
src/backend.c
src/cfgparse.c

index 3266a4448132e9ca6324fdf19d76398c9738b240..ce2a02b52aefd011dac50ef613cf046a2bd7fe3b 100644 (file)
@@ -2789,6 +2789,35 @@ no option tcp-smart-accept
   of doubt, consider setting it back to automatic values by prepending the
   "default" keyword before it, or disabling it using the "no" keyword.
 
+  See also : "option tcp-smart-connect"
+
+
+option tcp-smart-connect
+no option tcp-smart-connect
+  Enable or disable the saving of one ACK packet during the connect sequence
+  May be used in sections :   defaults | frontend | listen | backend
+                                 yes   |    no    |   yes  |   yes
+  Arguments : none
+
+  On certain systems (at least Linux), HAProxy can ask the kernel not to
+  immediately send an empty ACK upon a connection request, but to directly
+  send the buffer request instead. This saves one packet on the network and
+  thus boosts performance. It can also be useful for some servers, because they
+  immediately get the request along with the incoming connection.
+
+  This feature is enabled when "option tcp-smart-connect" is set in a backend.
+  It is not enabled by default because it makes network troubleshooting more
+  complex.
+
+  It only makes sense to enable it with protocols where the client speaks first
+  such as HTTP. In other situations, if there is no data to send in place of
+  the ACK, a normal ACK is sent.
+
+  If this option has been enabled in a "defaults" section, it can be disabled
+  in a specific instance by prepending the "no" keyword before it.
+
+  See also : "option tcp-smart-accept"
+
 
 option tcpka
   Enable or disable the sending of TCP keepalive packets on both sides
index 7664618f047ecaf3bed9d8f0df5fbbb2f70fe637..715f21d1525c3259594344a31279738be3f7b565 100644 (file)
 #define PR_O2_NOLOGNORM        0x00000020      /* don't log normal traffic, only errors and retries */
 #define PR_O2_LOGERRORS        0x00000040      /* log errors and retries at level LOG_ERR */
 #define PR_O2_SMARTACC         0x00000080      /* don't immediately ACK request after accept */
+#define PR_O2_SMARTCON         0x00000100      /* don't immediately send empty ACK after connect */
 
 /* This structure is used to apply fast weighted round robin on a server group */
 struct fwrr_group {
index 5e78fd8df5a522ffb6e7965b9653b16cf190b630..58de35e54cfc9feb18a4a419b870e89dae40575b 100644 (file)
@@ -18,6 +18,8 @@
 #include <string.h>
 #include <ctype.h>
 
+#include <netinet/tcp.h>
+
 #include <common/compat.h>
 #include <common/config.h>
 #include <common/debug.h>
@@ -1912,6 +1914,15 @@ int connect_server(struct session *s)
                }
        }
 
+#ifdef TCP_QUICKACK
+       /* disabling tcp quick ack now allows the first request to leave the
+        * machine with the first ACK. We only do this if there are pending
+        * data in the buffer.
+        */
+       if ((s->be->options2 & PR_O2_SMARTCON) && s->req->send_max)
+                setsockopt(fd, SOL_TCP, TCP_QUICKACK, (char *) &zero, sizeof(zero));
+#endif
+
        if ((connect(fd, (struct sockaddr *)&s->srv_addr, sizeof(s->srv_addr)) == -1) &&
            (errno != EINPROGRESS) && (errno != EALREADY) && (errno != EISCONN)) {
 
index 03a5303f5106ac419491100bd2eb9e70b0bb034f..9ec869e11c067730c2c836c6213a463dd8b11382 100644 (file)
@@ -136,6 +136,7 @@ static const struct cfg_opt cfg_opts2[] =
        { "dontlog-normal",               PR_O2_NOLOGNORM, PR_CAP_FE, 0 },
        { "log-separate-errors",          PR_O2_LOGERRORS, PR_CAP_FE, 0 },
        { "tcp-smart-accept",             PR_O2_SMARTACC,  PR_CAP_FE, 0 },
+       { "tcp-smart-connect",            PR_O2_SMARTCON,  PR_CAP_BE, 0 },
        { NULL, 0, 0, 0 }
 };