On Sun, Mar 06, 2011 at 09:12:41AM +0100, Reyk Floeter wrote:
> this diff will break chunked encoding and keep-alive connections where
> we need to enable splicing for a specified amount of data only and
> return for the next HTTP header.
I don't think so. I only set F_SPLICE for RELAY_PROTO_TCP and not
for RELAY_PROTO_HTTP.
> the env variable should be replaced
> with a permanent config option in parse.y.
New diff with nosplice protocol option. The config looks like this:
tcp protocol "copy" { nosplice }
tcp protocol "splice"
relay "tcpbench" {
listen on 10.188.50.50 port 12345
forward to 10.188.50.10 port 12345
}
relay "slow" {
protocol "copy"
listen on 10.188.50.50 port 12346
forward to 10.188.50.10 port 12345
}
relay "fast" {
protocol "splice"
listen on 10.188.50.50 port 12347
forward to 10.188.50.10 port 12345
}
Note that the default tcp protocol comes with splicing enabled.
The option nosplice is useful for performance comparison and
debugging.
I have also tested with http connection keep-alive, client ssl and
server ssl. In these cases, socket splicing is not used.
ok?
bluhm
Index: usr.sbin/relayd/parse.y
===================================================================
RCS file: /data/mirror/openbsd/cvs/src/usr.sbin/relayd/parse.y,v
retrieving revision 1.149
diff -u -p -r1.149 parse.y
--- usr.sbin/relayd/parse.y 26 Oct 2010 15:04:37 -0000 1.149
+++ usr.sbin/relayd/parse.y 7 Mar 2011 21:03:34 -0000
@@ -145,7 +145,7 @@ typedef struct {
%token EXTERNAL FILENAME FILTER FORWARD FROM HASH HEADER HOST ICMP
%token INCLUDE INET INET6 INTERFACE INTERVAL IP LABEL LISTEN
%token LOADBALANCE LOG LOOKUP MARK MARKED MODE NAT NO
-%token NODELAY NOTHING ON PARENT PATH PORT PREFORK PROTO
+%token NODELAY NOSPLICE NOTHING ON PARENT PATH PORT PREFORK PROTO
%token QUERYSTR REAL REDIRECT RELAY REMOVE REQUEST RESPONSE RETRY
%token RETURN ROUNDROBIN ROUTE SACK SCRIPT SEND SESSION SOCKET
%token SSL STICKYADDR STYLE TABLE TAG TCP TIMEOUT TO ROUTER RTLABEL
@@ -796,6 +796,8 @@ proto : relay_proto PROTO STRING {
free($3);
p->id = ++last_proto_id;
p->type = $1;
+ if (p->type == RELAY_PROTO_TCP)
+ p->flags |= F_SPLICE;
p->cache = RELAY_CACHESIZE;
p->tcpflags = TCPFLAG_DEFAULT;
p->sslflags = SSLFLAG_DEFAULT;
@@ -835,6 +837,7 @@ protoptsl : SSL sslflags
| SSL '{' sslflags_l '}'
| TCP tcpflags
| TCP '{' tcpflags_l '}'
+ | NOSPLICE { proto->flags &= ~F_SPLICE; }
| RETURN ERROR opteflags { proto->flags |= F_RETURN; }
| RETURN ERROR '{' eflags_l '}' { proto->flags |= F_RETURN; }
| LABEL STRING {
@@ -1747,6 +1750,7 @@ lookup(char *s)
{ "nat", NAT },
{ "no", NO },
{ "nodelay", NODELAY },
+ { "nosplice", NOSPLICE },
{ "nothing", NOTHING },
{ "on", ON },
{ "parent", PARENT },
@@ -2162,7 +2166,7 @@ parse_config(const char *filename, int o
sizeof(conf->sc_empty_table.conf.name));
bzero(&conf->sc_proto_default, sizeof(conf->sc_proto_default));
- conf->sc_proto_default.flags = F_USED;
+ conf->sc_proto_default.flags = F_USED|F_SPLICE;
conf->sc_proto_default.cache = RELAY_CACHESIZE;
conf->sc_proto_default.tcpflags = TCPFLAG_DEFAULT;
conf->sc_proto_default.tcpbacklog = RELAY_BACKLOG;
Index: usr.sbin/relayd/relay.c
===================================================================
RCS file: /data/mirror/openbsd/cvs/src/usr.sbin/relayd/relay.c,v
retrieving revision 1.128
diff -u -p -r1.128 relay.c
--- usr.sbin/relayd/relay.c 20 Dec 2010 12:38:06 -0000 1.128
+++ usr.sbin/relayd/relay.c 22 Feb 2011 22:54:05 -0000
@@ -2328,6 +2328,22 @@ relay_connect(struct rsession *con)
return (-1);
}
+ if (rlay->rl_proto->flags & F_SPLICE &&
+ (rlay->rl_conf.flags & (F_SSL|F_SSLCLIENT)) == 0) {
+ if (setsockopt(con->se_in.s, SOL_SOCKET, SO_SPLICE,
+ &con->se_out.s, sizeof(int)) == -1) {
+ log_debug("relay_connect: session %d: splice forward "
+ "failed: %s", con->se_id, strerror(errno));
+ return (-1);
+ }
+ if (setsockopt(con->se_out.s, SOL_SOCKET, SO_SPLICE,
+ &con->se_in.s, sizeof(int)) == -1) {
+ log_debug("relay_connect: session %d: splice backward "
+ "failed: %s", con->se_id, strerror(errno));
+ return (-1);
+ }
+ }
+
if (errno == EINPROGRESS)
event_again(&con->se_ev, con->se_out.s, EV_WRITE|EV_TIMEOUT,
relay_connected, &con->se_tv_start, &env->sc_timeout, con);
Index: usr.sbin/relayd/relayd.conf.5
===================================================================
RCS file: /data/mirror/openbsd/cvs/src/usr.sbin/relayd/relayd.conf.5,v
retrieving revision 1.116
diff -u -p -r1.116 relayd.conf.5
--- usr.sbin/relayd/relayd.conf.5 26 Oct 2010 15:26:58 -0000 1.116
+++ usr.sbin/relayd/relayd.conf.5 7 Mar 2011 22:55:49 -0000
@@ -945,6 +945,10 @@ no label
.Ed
.It Ic no label
Do not set a label for subsequently added actions; this is the default.
+.It Ic nosplice
+Turn off socket splicing and copy the data in user-land instead.
+Socket splicing is used by default to speed up plain TCP connections
+without SSL.
.It Ic remove Ar key
Remove the entity with the selected name.
.It Ic remove file Ar path
Index: usr.sbin/relayd/relayd.h
===================================================================
RCS file: /data/mirror/openbsd/cvs/src/usr.sbin/relayd/relayd.h,v
retrieving revision 1.140
diff -u -p -r1.140 relayd.h
--- usr.sbin/relayd/relayd.h 31 Dec 2010 21:22:42 -0000 1.140
+++ usr.sbin/relayd/relayd.h 22 Feb 2011 22:54:05 -0000
@@ -249,6 +249,7 @@ TAILQ_HEAD(addresslist, address);
#define F_SSLCLIENT 0x00200000
#define F_NEEDRT 0x00400000
#define F_MATCH 0x00800000
+#define F_SPLICE 0x01000000
enum forwardmode {
FWD_NORMAL = 0,