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
#include <stdio.h>
#include <errno.h>
#include <math.h>
+#include <poll.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
cnt_done(struct sess *sp)
{
double dh, dp, da;
+ struct pollfd pfd[1];
int i;
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
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));
/* Default connection_timeout */
unsigned connect_timeout;
+ /* How long to linger on sessions */
+ unsigned session_linger;
+
/* CLI buffer size */
unsigned cli_buffer;
"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 "
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")