From: phk Date: Wed, 11 Jun 2008 21:12:26 +0000 (+0000) Subject: Add an optional shortcut: X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=01801156ffb7d374a2e864158bd3b2a7725af08c;p=varnish Add an optional shortcut: 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 --- diff --git a/varnish-cache/bin/varnishd/cache_center.c b/varnish-cache/bin/varnishd/cache_center.c index 0f2e45b9..d549ebdc 100644 --- a/varnish-cache/bin/varnishd/cache_center.c +++ b/varnish-cache/bin/varnishd/cache_center.c @@ -61,6 +61,7 @@ DOT acceptor -> start [style=bold,color=green,weight=4] #include #include #include +#include #include #include #include @@ -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)); diff --git a/varnish-cache/bin/varnishd/heritage.h b/varnish-cache/bin/varnishd/heritage.h index bf9832a2..694b5ebb 100644 --- a/varnish-cache/bin/varnishd/heritage.h +++ b/varnish-cache/bin/varnishd/heritage.h @@ -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; diff --git a/varnish-cache/bin/varnishd/mgt_param.c b/varnish-cache/bin/varnishd/mgt_param.c index e8dbda43..e6e13f85 100644 --- a/varnish-cache/bin/varnishd/mgt_param.c +++ b/varnish-cache/bin/varnishd/mgt_param.c @@ -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 " diff --git a/varnish-cache/include/stat_field.h b/varnish-cache/include/stat_field.h index 3cba00fa..5a4bdea8 100644 --- a/varnish-cache/include/stat_field.h +++ b/varnish-cache/include/stat_field.h @@ -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")