]> err.no Git - varnish/commitdiff
Add back sendfile support (under #ifdef HAVE_SENDFILE) but don't engage
authorphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Tue, 8 Aug 2006 07:36:00 +0000 (07:36 +0000)
committerphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Tue, 8 Aug 2006 07:36:00 +0000 (07:36 +0000)
it for small objects on the suspicion that it has highish setup cost.

git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@762 d4fa192b-c00b-0410-8231-f00ffab90ce4

varnish-cache/bin/varnishd/cache.h
varnish-cache/bin/varnishd/cache_pool.c
varnish-cache/bin/varnishd/cache_response.c

index 1558f374cd81235bb0d6b8f7c258c06ed23f5e80..3eea0c73d22ff842450d6a9ab6f4c676482c1296 100644 (file)
@@ -374,6 +374,9 @@ void WRK_Reset(struct worker *w, int *fd);
 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);
index 91e809acdbccc29dc53cead6fe275e873240cc73..4eccc6af25611ef9962ca0d119f8deac731f642a 100644 (file)
@@ -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 @@ WRK_Flush(struct worker *w)
        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 @@ WRK_Write(struct worker *w, const void *ptr, int len)
        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
index 0c15704c8ec80772933e450e6afbc4e5b32eb599..46f5c5d5fa6b4320ae1f6372a697670ee96d43ec 100644 (file)
@@ -161,6 +161,19 @@ RES_WriteObj(struct sess *sp)
                        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);