From a69d2ff5abc827851b2aa841bb215f2ef005232b Mon Sep 17 00:00:00 2001 From: phk Date: Sat, 19 Aug 2006 21:48:30 +0000 Subject: [PATCH] Make the session timeout and send timeout tweakables. git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@839 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- varnish-cache/bin/varnishd/cache_acceptor.c | 9 ++-- varnish-cache/bin/varnishd/heritage.h | 4 ++ varnish-cache/bin/varnishd/mgt_param.c | 55 +++++++++++++++++++++ varnish-cache/bin/varnishd/varnishd.c | 3 ++ 4 files changed, 67 insertions(+), 4 deletions(-) diff --git a/varnish-cache/bin/varnishd/cache_acceptor.c b/varnish-cache/bin/varnishd/cache_acceptor.c index cb3a01a7..a547301d 100644 --- a/varnish-cache/bin/varnishd/cache_acceptor.c +++ b/varnish-cache/bin/varnishd/cache_acceptor.c @@ -79,7 +79,7 @@ vca_accept_sess(int fd) { struct timeval tv; - tv.tv_sec = 600; + tv.tv_sec = params->send_timeout; tv.tv_usec = 0; AZ(setsockopt(sp->fd, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof tv)); } @@ -233,7 +233,7 @@ vca_main(void *arg) vca_handover(sp, i); continue; } - if (sp->t_idle.tv_sec + 5 < t.tv_sec) { + if (sp->t_idle.tv_sec + params->sess_timeout < t.tv_sec) { TAILQ_REMOVE(&sesshead, sp, list); vca_unpoll(sp->fd); vca_close_session(sp, "timeout"); @@ -354,7 +354,7 @@ vca_main(void *arg) clock_gettime(CLOCK_MONOTONIC, &t); TAILQ_FOREACH_SAFE(sp, &sesshead, list, sp2) { CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); - if (sp->t_idle.tv_sec + 5 < t.tv_sec) { + if (sp->t_idle.tv_sec + params->sess_timeout < t.tv_sec) { TAILQ_REMOVE(&sesshead, sp, list); vca_del(sp->fd); vca_close_session(sp, "timeout"); @@ -400,7 +400,8 @@ vca_kq_sess(struct sess *sp, int arm) CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); memset(ke, 0, sizeof ke); EV_SET(&ke[0], sp->fd, EVFILT_READ, arm, 0, 0, sp); - EV_SET(&ke[1], sp->fd, EVFILT_TIMER, arm , 0, 5000, sp); + EV_SET(&ke[1], sp->fd, EVFILT_TIMER, arm , 0, + params->sess_timeout * 1000, sp); i = kevent(kq, ke, 2, NULL, 0, NULL); if (arm == EV_ADD) assert(i == 0); diff --git a/varnish-cache/bin/varnishd/heritage.h b/varnish-cache/bin/varnishd/heritage.h index 1829bf29..b9019f34 100644 --- a/varnish-cache/bin/varnishd/heritage.h +++ b/varnish-cache/bin/varnishd/heritage.h @@ -39,6 +39,10 @@ struct params { /* Memory allocation hints */ unsigned mem_workspace; + + /* Acceptor hints */ + unsigned sess_timeout; + unsigned send_timeout; }; extern struct params *params; diff --git a/varnish-cache/bin/varnishd/mgt_param.c b/varnish-cache/bin/varnishd/mgt_param.c index 69dd5976..b19c097f 100644 --- a/varnish-cache/bin/varnishd/mgt_param.c +++ b/varnish-cache/bin/varnishd/mgt_param.c @@ -120,6 +120,46 @@ tweak_http_workspace(struct cli *cli, struct parspec *par, const char *arg) /*--------------------------------------------------------------------*/ +static void +tweak_sess_timeout(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->sess_timeout = u; + } + cli_out(cli, "%u [seconds]\n", params->sess_timeout); +} + +/*--------------------------------------------------------------------*/ + +static void +tweak_send_timeout(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->send_timeout = u; + } + cli_out(cli, "%u [seconds]\n", params->send_timeout); +} + +/*--------------------------------------------------------------------*/ + /* * Make sure to end all lines with either a space or newline of the * formatting will go haywire. @@ -166,6 +206,21 @@ static struct parspec parspec[] = { SHOULD_RESTART "Default is 4096 bytes. " "Minimum is 1024 bytes. " }, + { "sess_timeout", tweak_sess_timeout, + "Idle timeout for persistent sessions. " + "If a HTTP request has not been received in this many " + "seconds, the session is closed.\n" +#ifdef HAVE_ACCEPT_FILTERS + DELAYED_EFFECT +#endif + "Default is 15 seconds. " }, + { "send_timeout", tweak_send_timeout, + "Send timeout for client connections. " + "If no data has been sent to the client in this many seconds, " + "the session is closed.\n" + "See getopt(3) under SO_SNDTIMEO for more information.\n" + "Default is 600 seconds. " }, + { NULL, NULL, NULL } }; diff --git a/varnish-cache/bin/varnishd/varnishd.c b/varnish-cache/bin/varnishd/varnishd.c index 2a1f340d..b41dc672 100644 --- a/varnish-cache/bin/varnishd/varnishd.c +++ b/varnish-cache/bin/varnishd/varnishd.c @@ -333,11 +333,14 @@ main(int argc, char *argv[]) params = ¶m; mgt_vcc_init(); + /* XXX: move this to mgt_params.c ?? */ params->default_ttl = 120; params->wthread_min = 1; params->wthread_max = UINT_MAX; params->wthread_timeout = 10; params->mem_workspace = 4096; + params->sess_timeout = 15; + params->send_timeout = 600; while ((o = getopt(argc, argv, "b:df:h:p:s:t:T:Vw:")) != -1) switch (o) { -- 2.39.5