diff options
author | Florian Obser <florian@cvs.openbsd.org> | 2015-07-16 16:29:26 +0000 |
---|---|---|
committer | Florian Obser <florian@cvs.openbsd.org> | 2015-07-16 16:29:26 +0000 |
commit | 025e538c3ec5af10cc81aae13f2680194b7320ff (patch) | |
tree | 3d2cc5a2f6a1119a8cb397f2c4ce8c9b6109c8f2 /usr.sbin | |
parent | 96c7e2683bd59830d2aaebfd2956afa3bce9323d (diff) |
If we can read faster from disk than send data to the client stop
reading from disk when we hold a certain amount of data in
RAM. Re-enable reading once we send enough data to the
client. Otherwise we might end up with the whole file (which can be
huge) in RAM.
Reported by Matthew Martin ( matt.a.martin AT gmail ) on bugs@,
thanks!
OK reyk@, benno@
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/httpd/httpd.h | 4 | ||||
-rw-r--r-- | usr.sbin/httpd/server.c | 13 |
2 files changed, 14 insertions, 3 deletions
diff --git a/usr.sbin/httpd/httpd.h b/usr.sbin/httpd/httpd.h index 40408ba9ecb..2cb7934b536 100644 --- a/usr.sbin/httpd/httpd.h +++ b/usr.sbin/httpd/httpd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: httpd.h,v 1.87 2015/07/16 04:46:07 reyk Exp $ */ +/* $OpenBSD: httpd.h,v 1.88 2015/07/16 16:29:25 florian Exp $ */ /* * Copyright (c) 2006 - 2015 Reyk Floeter <reyk@openbsd.org> @@ -66,6 +66,8 @@ #define SERVER_MAXREQUESTBODY 1048576 /* 1M */ #define SERVER_BACKLOG 10 #define SERVER_OUTOF_FD_RETRIES 5 +#define SERVER_MAX_PREFETCH 256 +#define SERVER_MIN_PREFETCHED 32 #define MEDIATYPE_NAMEMAX 128 /* file name extension */ #define MEDIATYPE_TYPEMAX 64 /* length of type/subtype */ diff --git a/usr.sbin/httpd/server.c b/usr.sbin/httpd/server.c index 91a9fa9e6a7..86d0dca25e5 100644 --- a/usr.sbin/httpd/server.c +++ b/usr.sbin/httpd/server.c @@ -1,4 +1,4 @@ -/* $OpenBSD: server.c,v 1.69 2015/07/15 23:16:38 reyk Exp $ */ +/* $OpenBSD: server.c,v 1.70 2015/07/16 16:29:25 florian Exp $ */ /* * Copyright (c) 2006 - 2015 Reyk Floeter <reyk@openbsd.org> @@ -721,7 +721,7 @@ server_input(struct client *clt) /* Adjust write watermark to the socket buffer output size */ bufferevent_setwatermark(clt->clt_bev, EV_WRITE, - clt->clt_sndbufsiz, 0); + SERVER_MIN_PREFETCHED * clt->clt_sndbufsiz, 0); /* Read at most amount of data that fits in one fcgi record. */ bufferevent_setwatermark(clt->clt_bev, EV_READ, 0, FCGI_CONTENT_SIZE); @@ -746,6 +746,10 @@ server_write(struct bufferevent *bev, void *arg) goto done; bufferevent_enable(bev, EV_READ); + + if (clt->clt_srvbev && !(clt->clt_srvbev->enabled & EV_READ)) + bufferevent_enable(clt->clt_srvbev, EV_READ); + return; done: (*bev->errorcb)(bev, EVBUFFER_WRITE|EVBUFFER_EOF, bev->cbarg); @@ -786,6 +790,11 @@ server_read(struct bufferevent *bev, void *arg) goto fail; if (clt->clt_done) goto done; + + if (EVBUFFER_LENGTH(EVBUFFER_OUTPUT(clt->clt_bev)) > (size_t) + SERVER_MAX_PREFETCH * clt->clt_sndbufsiz) + bufferevent_disable(bev, EV_READ); + return; done: (*bev->errorcb)(bev, EVBUFFER_READ|EVBUFFER_EOF, bev->cbarg); |