Commit 6832de7e authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Make session_linger the default with 50msec timeout.

Change the session handling logic, so that we hand any session back to
the herder, if the session_linger timer fires.

This means that a new session, will get a worker thread, but if nothing
happens within session_linger, it disembarks and lets the herder handle
the assembly of the request.

This actually simplifies the state engine, because the "again" state
(now renamed "wait) can also be used both for the first request.



git-svn-id: http://www.varnish-cache.org/svn/trunk/varnish-cache@4079 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent 18ded813
......@@ -253,6 +253,7 @@ vca_acct(void *arg)
sp->fd = i;
sp->id = i;
sp->t_open = now;
sp->t_end = now;
sp->mylsock = ls;
sp->step = STP_FIRST;
......
......@@ -80,17 +80,15 @@ DOT acceptor -> start [style=bold,color=green,weight=4]
static unsigned xids;
/*--------------------------------------------------------------------
* AGAIN
* We come here when we just completed a request and already have
* received (part of) the next one. Instead taking the detour
* around the acceptor and then back to a worker, just stay in this
* worker and do what it takes.
* WAIT
* Wait until we have a full request in our htc.
*/
static int
cnt_again(struct sess *sp)
cnt_wait(struct sess *sp)
{
int i;
struct pollfd pfd[1];
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
AZ(sp->vcl);
......@@ -98,12 +96,32 @@ cnt_again(struct sess *sp)
assert(sp->xid == 0);
i = HTC_Complete(sp->htc);
while (i == 0)
while (i == 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) {
WSL(sp->wrk, SLT_Debug, sp->fd, "herding");
VSL_stats->sess_herd++;
sp->wrk = NULL;
vca_return_session(sp);
return (1);
}
}
i = HTC_Rx(sp->htc);
}
if (i == 1) {
sp->step = STP_START;
} else {
vca_close_session(sp, "overflow");
if (i == -2)
vca_close_session(sp, "overflow");
else if (i == -1 && Tlen(sp->htc->rxbuf) == 0 &&
(errno == 0 || errno == ECONNRESET)
vca_close_session(sp, "EOF");
else
vca_close_session(sp, "error");
sp->step = STP_DONE;
}
return (0);
......@@ -201,7 +219,6 @@ static int
cnt_done(struct sess *sp)
{
double dh, dp, da;
struct pollfd pfd[1];
int i;
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
......@@ -269,19 +286,13 @@ cnt_done(struct sess *sp)
}
if (Tlen(sp->htc->rxbuf)) {
VSL_stats->sess_readahead++;
sp->step = STP_AGAIN;
sp->step = STP_WAIT;
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_linger++;
sp->step = STP_WAIT;
return (0);
}
VSL_stats->sess_herd++;
SES_Charge(sp);
......@@ -590,7 +601,6 @@ cnt_fetch(struct sess *sp)
static int
cnt_first(struct sess *sp)
{
int i;
/*
* XXX: If we don't have acceptfilters we are somewhat subject
......@@ -610,25 +620,8 @@ cnt_first(struct sess *sp)
HTC_Init(sp->htc, sp->ws, sp->fd);
sp->wrk->lastused = sp->t_open;
sp->acct_req.sess++;
do
i = HTC_Rx(sp->htc);
while (i == 0);
switch (i) {
case 1:
sp->step = STP_START;
break;
case -1:
vca_close_session(sp, "error");
sp->step = STP_DONE;
break;
case -2:
vca_close_session(sp, "blast");
sp->step = STP_DONE;
break;
default:
WRONG("Illegal return from HTC_Rx");
}
sp->step = STP_WAIT;
return (0);
}
......
......@@ -93,6 +93,7 @@ HTC_Init(struct http_conn *htc, struct ws *ws, int fd)
(void)WS_Reserve(htc->ws, (htc->ws->e - htc->ws->s) / 2);
htc->rxbuf.b = ws->f;
htc->rxbuf.e = ws->f;
*htc->rxbuf.e = '\0';
htc->pipeline.b = NULL;
htc->pipeline.e = NULL;
}
......
......@@ -696,7 +696,7 @@ static const struct parspec input_parspec[] = {
"anything for their keep, setting it too low just means that "
"more sessions take a detour around the waiter.",
EXPERIMENTAL,
"0", "ms" },
"50", "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 "
......
......@@ -29,7 +29,7 @@
* $Id$
*/
STEP(again, AGAIN)
STEP(wait, WAIT)
STEP(first, FIRST)
STEP(recv, RECV)
STEP(start, START)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment