]> err.no Git - varnish/commitdiff
Try to avoid sending EOF'ed or ready sessions to the herder.
authorphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Fri, 15 Sep 2006 09:43:56 +0000 (09:43 +0000)
committerphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Fri, 15 Sep 2006 09:43:56 +0000 (09:43 +0000)
git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@987 d4fa192b-c00b-0410-8231-f00ffab90ce4

varnish-cache/bin/varnishd/cache_center.c
varnish-cache/bin/varnishd/heritage.h
varnish-cache/bin/varnishd/mgt_param.c
varnish-cache/include/stat_field.h

index 047890dc0c852b6175a7ec23678e5fea9d06431b..4260f540936cc9445aa7691acac81fa70dfac3d7 100644 (file)
@@ -33,8 +33,10 @@ DOT start -> RECV
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
+#include <poll.h>
 
 #include "shmlog.h"
+#include "heritage.h"
 #include "vcl.h"
 #include "cache.h"
 
@@ -122,6 +124,8 @@ static int
 cnt_done(struct sess *sp)
 {
        double dh, dp, da;
+       struct pollfd fds[1];
+       int i;
 
        AZ(sp->obj);
        AZ(sp->vbc);
@@ -150,25 +154,47 @@ cnt_done(struct sess *sp)
        sp->xid = 0;
        sp->t_open = sp->t_end;
        SES_Charge(sp);
-       if (sp->fd > 0) {
-               VSL(SLT_SessionReuse, sp->fd, "%s %s", sp->addr, sp->port);
-
-               /* If we have anything in the input buffer, start over */
-               /*
-                * XXX: we might even want to do a short timed read (poll)
-                * XXX: here to see if something is pending in the kernel
-                */
-               
-               if (http_RecvPrepAgain(sp->http)) {
-                       sp->step = STP_RECV;
-                       return (0);
-               }
-               if (sp->http->t < sp->http->v) {
-                       sp->step = STP_AGAIN;
-                       return (0);
-               }
+       if (sp->fd < 0) {
+               VSL_stats->sess_closed++;
+               sp->wrk->idle = sp->t_open.tv_sec;
+               vca_return_session(sp);
+               return (1);
        }
 
+       if (http_RecvPrepAgain(sp->http)) {
+               VSL_stats->sess_pipeline++;
+               VSL(SLT_SessionReuse, sp->fd, "%s %s", sp->addr, sp->port);
+               sp->step = STP_RECV;
+               return (0);
+       }
+       if (sp->http->t < sp->http->v) {
+               VSL_stats->sess_readahead++;
+               VSL(SLT_SessionReuse, sp->fd, "%s %s", sp->addr, sp->port);
+               sp->step = STP_AGAIN;
+               return (0);
+       }
+       if (params->session_grace == 0) {
+               VSL_stats->sess_herd++;
+               sp->wrk->idle = sp->t_open.tv_sec;
+               vca_return_session(sp);
+               return (1);
+       }
+       fds[0].fd = sp->fd;
+       fds[0].events = POLLIN;
+       fds[0].revents = 0;
+       i = poll(fds, 1, params->session_grace);
+       if (i == 1 && (fds[0].revents & POLLHUP)) {
+               VSL_stats->sess_EOF++;
+               vca_close_session(sp, "EOF");
+       } else if (i == 1 && (fds[0].revents & POLLIN)) {
+               VSL_stats->sess_ready++;
+               VSL(SLT_SessionReuse, sp->fd, "%s %s",
+                   sp->addr, sp->port);
+               sp->step = STP_AGAIN;
+               return (0);
+       } else {
+               VSL_stats->sess_herd++;
+       }
        sp->wrk->idle = sp->t_open.tv_sec;
        vca_return_session(sp);
        return (1);
index 1997118b27309b695114157d03cf11f62dca983f..d16f172d0e864d3664745b72763bdd1f86c6fd89 100644 (file)
@@ -53,6 +53,9 @@ struct params {
 
        /* Sendfile object minimum size */
        unsigned                sendfile_threshold;
+
+       /* Session dispostion grace period */
+       unsigned                session_grace;
 };
 
 extern struct params *params;
index ff3879f12e64dc456369fe04fb55ffd3735851cc..675013899341a2407b0686e2824bf64f51a5e499 100644 (file)
@@ -168,6 +168,28 @@ tweak_send_timeout(struct cli *cli, struct parspec *par, const char *arg)
 
 /*--------------------------------------------------------------------*/
 
+static void
+tweak_session_grace(struct cli *cli, struct parspec *par, const char *arg)
+{
+       unsigned u;
+
+       (void)par;
+       if (arg != NULL) {
+               u = strtoul(arg, NULL, 0);
+               if (u == 0) {
+                       cli_out(cli, "Timeout must be greater than zero\n");
+                       cli_result(cli, CLIS_PARAM);
+                       return;
+               }
+               params->session_grace = u;
+       }
+       if (cli == NULL)
+               return;
+       cli_out(cli, "%u [milliseconds]\n", params->session_grace);
+}
+
+/*--------------------------------------------------------------------*/
+
 static void
 tweak_auto_restart(struct cli *cli, struct parspec *par, const char *arg)
 {
@@ -301,6 +323,10 @@ static struct parspec parspec[] = {
                "The minimum size of objects transmitted with sendfile.\n"
                "Default is 8192 bytes.", "8192" },
 #endif /* HAVE_SENDFILE */
+       { "session_grace", tweak_session_grace,
+               "How long a workerthread waits for a new request to arrive "
+               "before sending the session to the herder.\n"
+               "Default is 10 msec.", "10" },
        { NULL, NULL, NULL }
 };
 
index e59365c3cafe484f3020801737e08c469223ad21..8a171df19e85a25091556a18fe59077eccfb34d8 100644 (file)
@@ -43,3 +43,10 @@ MAC_STAT(s_pass,             uint64_t, "u", "Total pass")
 MAC_STAT(s_fetch,              uint64_t, "u", "Total fetch")
 MAC_STAT(s_hdrbytes,           uint64_t, "u", "Total header bytes")
 MAC_STAT(s_bodybytes,          uint64_t, "u", "Total body bytes")
+
+MAC_STAT(sess_closed,          uint64_t, "u", "Session Closed")
+MAC_STAT(sess_pipeline,                uint64_t, "u", "Session Pipeline")
+MAC_STAT(sess_readahead,       uint64_t, "u", "Session Read Ahead")
+MAC_STAT(sess_EOF,             uint64_t, "u", "Session EOF")
+MAC_STAT(sess_ready,           uint64_t, "u", "Session Ready")
+MAC_STAT(sess_herd,            uint64_t, "u", "Session herd")