]> err.no Git - varnish/commitdiff
Make the session timeout and send timeout tweakables.
authorphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Sat, 19 Aug 2006 21:48:30 +0000 (21:48 +0000)
committerphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Sat, 19 Aug 2006 21:48:30 +0000 (21:48 +0000)
git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@839 d4fa192b-c00b-0410-8231-f00ffab90ce4

varnish-cache/bin/varnishd/cache_acceptor.c
varnish-cache/bin/varnishd/heritage.h
varnish-cache/bin/varnishd/mgt_param.c
varnish-cache/bin/varnishd/varnishd.c

index cb3a01a716cc5ca1bde26f9d665a494bacf18477..a547301d589b8622749a57b00dc639e7e6c5f63f 100644 (file)
@@ -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);
index 1829bf29a6f1c565651fa2f40aaa8314f329d4f2..b9019f34a4f58be707b046f001ab7ea7eea4aa87 100644 (file)
@@ -39,6 +39,10 @@ struct params {
 
        /* Memory allocation hints */
        unsigned                mem_workspace;
+
+       /* Acceptor hints */
+       unsigned                sess_timeout;
+       unsigned                send_timeout;
 };
 
 extern struct params *params;
index 69dd59769b27905b357cd3c7bac33e0c2e734021..b19c097f6c1a635eb896790011a2c9ee6a32f38e 100644 (file)
@@ -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 }
 };
 
index 2a1f340de147ebaaa6f0d9b278005deb869c0949..b41dc672efeadc299ae70d7cd01613e64f8dfbc9 100644 (file)
@@ -333,11 +333,14 @@ main(int argc, char *argv[])
        params = &param;
        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) {