]> err.no Git - varnish/commitdiff
Add an optional shortcut:
authorphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Wed, 11 Jun 2008 21:12:26 +0000 (21:12 +0000)
committerphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Wed, 11 Jun 2008 21:12:26 +0000 (21:12 +0000)
The parameter session_linger determines how many milliseconds the
workerthread waits to see if another request has arrived, before
handing the session over to the session herder.

If we manage to catch the next request this way, we save a number
of semi-expensive steps, if we hang around too long, the worker-thread
gets to goof off.

A relatively small sample of data from a live server, indicates
that 20% of all requests arrive within 50 msec of the previous
request and 50% within 100msec.

It is not clear at present how these timeintervals relate to client
RTT, or if they are systematically too high, due to the duration
of the detour over the herder.

There is a new line in varnishstat keeping track of how many times
this gamble succeeds.

Experimentation is encouraged.

git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@2663 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 0f2e45b9a8186553efbe6934c0355cd462507dde..d549ebdc956b18f24b37cf0a86f5ec19617c5d20 100644 (file)
@@ -61,6 +61,7 @@ DOT acceptor -> start [style=bold,color=green,weight=4]
 #include <stdio.h>
 #include <errno.h>
 #include <math.h>
+#include <poll.h>
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
@@ -198,6 +199,7 @@ static int
 cnt_done(struct sess *sp)
 {
        double dh, dp, da;
+       struct pollfd pfd[1];
        int i;
 
        CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
@@ -267,6 +269,17 @@ cnt_done(struct sess *sp)
                sp->step = STP_AGAIN;
                return (0);
        }
+       if (params->session_linger > 0) {
+               pfd[0].fd = sp->fd;
+               pfd[0].events = POLLIN;
+               pfd[0].revents = 0;
+               i = poll(pfd, 1, params->session_linger);
+               if (i > 0) {
+                       VSL_stats->sess_linger++;
+                       sp->step = STP_AGAIN;
+                       return (0);
+               }
+       }
        VSL_stats->sess_herd++;
        SES_Charge(sp);
        assert(!isnan(sp->wrk->used));
index bf9832a23011c9205d20585e9dfc33d90c686247..694b5ebba9e78fa10840806383cf4856da7202ec 100644 (file)
@@ -148,6 +148,9 @@ struct params {
        /* Default connection_timeout */
        unsigned                connect_timeout;
 
+       /* How long to linger on sessions */
+       unsigned                session_linger;
+
        /* CLI buffer size */
        unsigned                cli_buffer;
 
index e8dbda43d65b4cd2d2286339199d12422db786a5..e6e13f85825a4116baef8db67a1f1d3c0d3ebab2 100644 (file)
@@ -718,6 +718,18 @@ static const struct parspec parspec[] = {
                "VCL can override this default value for each backend.",
                0,
                "400", "ms" },
+       { "session_linger", tweak_uint,
+               &master.session_linger,0, UINT_MAX,
+               "How long time the workerthread lingers on the session "
+               "to see if a new request appears right away.\n"
+               "If sessions are reused, as much as half of all reuses "
+               "happen within the first 100 msec of the previous request "
+               "completing.\n"
+               "Setting this too high results in worker threads not doing "
+               "anything for their keep, setting it too low just means that "
+               "more sessions take a detour around the acceptor.",
+               EXPERIMENTAL,
+               "0", "ms" },
        { "cli_buffer", tweak_uint, &master.cli_buffer, 4096, UINT_MAX,
                "Size of buffer for CLI input."
                "\nYou may need to increase this if you have big VCL files "
index 3cba00fa150f04e0151f331b634b4629e3a186ab..5a4bdea88a9787e30bc71210f38effa881d0d750 100644 (file)
@@ -85,6 +85,7 @@ MAC_STAT(s_bodybytes,         uint64_t, 'a', "Total body bytes")
 MAC_STAT(sess_closed,          uint64_t, 'a', "Session Closed")
 MAC_STAT(sess_pipeline,                uint64_t, 'a', "Session Pipeline")
 MAC_STAT(sess_readahead,       uint64_t, 'a', "Session Read Ahead")
+MAC_STAT(sess_linger,          uint64_t, 'a', "Session Linger")
 MAC_STAT(sess_herd,            uint64_t, 'a', "Session herd")
 
 MAC_STAT(shm_records,          uint64_t, 'a', "SHM records")