r762 - trunk/varnish-cache/bin/varnishd

phk at projects.linpro.no phk at projects.linpro.no
Tue Aug 8 09:36:01 CEST 2006


Author: phk
Date: 2006-08-08 09:36:00 +0200 (Tue, 08 Aug 2006)
New Revision: 762

Modified:
   trunk/varnish-cache/bin/varnishd/cache.h
   trunk/varnish-cache/bin/varnishd/cache_pool.c
   trunk/varnish-cache/bin/varnishd/cache_response.c
Log:
Add back sendfile support (under #ifdef HAVE_SENDFILE) but don't engage
it for small objects on the suspicion that it has highish setup cost.


Modified: trunk/varnish-cache/bin/varnishd/cache.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache.h	2006-08-08 07:17:10 UTC (rev 761)
+++ trunk/varnish-cache/bin/varnishd/cache.h	2006-08-08 07:36:00 UTC (rev 762)
@@ -374,6 +374,9 @@
 int WRK_Flush(struct worker *w);
 unsigned WRK_Write(struct worker *w, const void *ptr, int len);
 unsigned WRK_WriteH(struct worker *w, struct http_hdr *hh, const char *suf);
+#ifdef HAVE_SENDFILE
+void WRK_Sendfile(struct worker *w, int fd, off_t off, unsigned len);
+#endif  /* HAVE_SENDFILE */
 
 /* cache_session.c [SES] */
 void SES_Init(void);

Modified: trunk/varnish-cache/bin/varnishd/cache_pool.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_pool.c	2006-08-08 07:17:10 UTC (rev 761)
+++ trunk/varnish-cache/bin/varnishd/cache_pool.c	2006-08-08 07:36:00 UTC (rev 762)
@@ -8,6 +8,10 @@
 #include <errno.h>
 #include <stdlib.h>
 #include <string.h>
+#ifdef HAVE_SENDFILE
+#include <sys/uio.h>
+#include <sys/socket.h>
+#endif /* HAVE_SENDFILE */
 #include <unistd.h>
 
 #include "heritage.h"
@@ -54,10 +58,8 @@
 	i = writev(*w->wfd, w->iov, w->niov);
 	if (i != w->liov)
 		w->werr++;
-	else {
-		w->liov = 0;
-		w->niov = 0;
-	}
+	w->liov = 0;
+	w->niov = 0;
 	return (w->werr);
 }
 
@@ -94,6 +96,30 @@
 	return (len);
 }
 
+#ifdef HAVE_SENDFILE
+void
+WRK_Sendfile(struct worker *w, int fd, off_t off, unsigned len)
+{
+	struct sf_hdtr sfh;
+	int i;
+
+	CHECK_OBJ_NOTNULL(w, WORKER_MAGIC);
+	assert(fd >= 0);
+	assert(len > 0);
+
+	memset(&sfh, 0, sizeof sfh);
+	if (w->niov > 0) {
+		sfh.headers = w->iov;
+		sfh.hdr_cnt = w->niov;
+	}
+	i = sendfile(fd, *w->wfd, off, len, &sfh, NULL, 0);
+	if (i != 0)
+		w->werr++;
+	w->liov = 0;
+	w->niov = 0;
+}
+#endif /* HAVE_SENDFILE */
+
 /*--------------------------------------------------------------------*/
 
 static void

Modified: trunk/varnish-cache/bin/varnishd/cache_response.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_response.c	2006-08-08 07:17:10 UTC (rev 761)
+++ trunk/varnish-cache/bin/varnishd/cache_response.c	2006-08-08 07:36:00 UTC (rev 762)
@@ -161,6 +161,19 @@
 			assert(st->stevedore != NULL);
 			u += st->len;
 			sp->wrk->acct.bodybytes += st->len;
+#ifdef HAVE_SENDFILE
+			/*
+			 * XXX: the overhead of setting up senddile is not
+			 * XXX: epsilon and maybe not even delta, so avoid
+			 * XXX: engaging sendfile for small objects.
+			 * XXX: Should use getpagesize() ?
+			 */
+			if (st->fd >= 0 && st->len >= 8192) {
+				WRK_Sendfile(sp->wrk, st->fd,
+				    st->where, st->len);
+				continue;
+			}
+#endif /* HAVE_SENDFILE */
 			WRK_Write(sp->wrk, st->ptr, st->len);
 		}
 		assert(u == sp->obj->len);




More information about the varnish-commit mailing list