]> err.no Git - varnish/commitdiff
We have a number of adjustable parameters, things like "default TTL" which
authorphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Sat, 19 Aug 2006 20:15:09 +0000 (20:15 +0000)
committerphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Sat, 19 Aug 2006 20:15:09 +0000 (20:15 +0000)
should be adjustable at runtime.

We need to make adjustments in such a way that a restart of the child also
uses the new paramters.

We can either do this by parsing the CLI in both mgt+child and have both
update their private copy, or we can parse it only in one of them and
update a shared copy.

We opt for the latter method.

Add a "struct params" which holds the adjustable parameters and put on
in the shmlog segment, between struct shmloghead and the round-robin
buffer.

Move parameters from heritage to params.

We put it there without exposing it in struct shmloghead which is
the public view of the shared memory because we do not want to make
it a public API or even to tempt people to think that it is one.

Now I just need to add the CLI functions to actually twiddle the
parameters.

git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@835 d4fa192b-c00b-0410-8231-f00ffab90ce4

varnish-cache/bin/varnishd/cache_backend.c
varnish-cache/bin/varnishd/cache_pool.c
varnish-cache/bin/varnishd/cache_session.c
varnish-cache/bin/varnishd/heritage.h
varnish-cache/bin/varnishd/rfc2616.c
varnish-cache/bin/varnishd/shmlog.c
varnish-cache/bin/varnishd/varnishd.c

index 5e7519fe8db31158cc427714be6b173a76fb1d61..2edc1e6c31d1f9154db1adac733d1f8294d06658 100644 (file)
@@ -39,7 +39,7 @@ vbe_new_conn(void)
        struct vbe_conn *vbc;
        unsigned char *p;
 
-       vbc = calloc(sizeof *vbc + heritage.mem_workspace * 2, 1);
+       vbc = calloc(sizeof *vbc + params->mem_workspace * 2, 1);
        if (vbc == NULL)
                return (NULL);
        VSL_stats->n_vbe_conn++;
@@ -48,9 +48,9 @@ vbe_new_conn(void)
        vbc->http2 = &vbc->http_mem[1];
        vbc->fd = -1;
        p = (void *)(vbc + 1);
-       http_Setup(vbc->http, p, heritage.mem_workspace);
-       p += heritage.mem_workspace;
-       http_Setup(vbc->http2, p, heritage.mem_workspace);
+       http_Setup(vbc->http, p, params->mem_workspace);
+       p += params->mem_workspace;
+       http_Setup(vbc->http2, p, params->mem_workspace);
        return (vbc);
 }
 
index 4eccc6af25611ef9962ca0d119f8deac731f642a..32d80cbbeb48fb349a396c29e3420ad9a0171f1e 100644 (file)
@@ -192,7 +192,7 @@ wrk_thread(void *priv)
                } else {
                        /* If we are a dynamic thread, time out and die */
                        AZ(clock_gettime(CLOCK_REALTIME, &ts));
-                       ts.tv_sec += heritage.wthread_timeout;
+                       ts.tv_sec += params->wthread_timeout;
                        if (pthread_cond_timedwait(&w->cv, &wrk_mtx, &ts)) {
                                VSL_stats->n_wrk--;
                                TAILQ_REMOVE(&wrk_idle, w, list);
@@ -237,7 +237,7 @@ WRK_QueueSession(struct sess *sp)
        wrk_overflow++;
 
        /* Can we create more threads ? */
-       if (VSL_stats->n_wrk >= heritage.wthread_max) {
+       if (VSL_stats->n_wrk >= params->wthread_max) {
                VSL_stats->n_wrk_max++;
                AZ(pthread_mutex_unlock(&wrk_mtx));
                return;
@@ -273,8 +273,8 @@ WRK_Init(void)
 
        AZ(pthread_mutex_init(&wrk_mtx, NULL));
 
-       VSL(SLT_Debug, 0, "Starting %u worker threads", heritage.wthread_min);
-       for (i = 0; i < heritage.wthread_min; i++) {
+       VSL(SLT_Debug, 0, "Starting %u worker threads", params->wthread_min);
+       for (i = 0; i < params->wthread_min; i++) {
                VSL_stats->n_wrk++;
                AZ(pthread_create(&tp, NULL, wrk_thread, &i));
                AZ(pthread_detach(tp));
index abe36f136045b9d15a982d78cafff1ab99c8f7fe..77240424083eedf159b22ad17ed405a316f240e1 100644 (file)
@@ -186,7 +186,7 @@ SES_New(struct sockaddr *addr, unsigned len)
        struct sessmem *sm;
 
        sm = calloc(
-           sizeof *sm + heritage.mem_workspace,
+           sizeof *sm + params->mem_workspace,
            1);
        if (sm == NULL)
                return (NULL);
@@ -203,7 +203,7 @@ SES_New(struct sockaddr *addr, unsigned len)
                sm->sess.sockaddrlen = len;
        }
 
-       http_Setup(&sm->http, (void *)(sm + 1), heritage.mem_workspace);
+       http_Setup(&sm->http, (void *)(sm + 1), params->mem_workspace);
 
        sm->sess.acct.first = time(NULL);
 
index 0fa64dc3d4915a493c65a3ac7d9c6fcd6acb9afc..1829bf29a6f1c565651fa2f40aaa8314f329d4f2 100644 (file)
@@ -25,6 +25,11 @@ struct heritage {
        /* Hash method */
        struct hash_slinger     *hash;
 
+};
+
+struct params {
+
+       /* TTL used for lack of anything better */
        unsigned                default_ttl;
 
        /* Worker threads */
@@ -36,6 +41,7 @@ struct heritage {
        unsigned                mem_workspace;
 };
 
+extern struct params *params;
 extern struct heritage heritage;
 
 void child_main(void);
index 380014496ec7d6c27aa34811a4806da2e93445c4..2c74b1a981ee0ba43e60341b2d0979b9824bc2e6 100644 (file)
@@ -111,7 +111,7 @@ RFC2616_Ttl(struct sess *sp, struct http *hp, struct object *obj)
                                retirement_age = h_expires - h_date;
                }
                if (retirement_age == INT_MAX)
-                       retirement_age = heritage.default_ttl;
+                       retirement_age = params->default_ttl;
 
                ttd = obj->entered + retirement_age;
        }
index 0c08980d5a2a159c7565656d78f73e96efa3422a..e62f9216e0fd40d42ec275d5a92bc977f517ae05 100644 (file)
@@ -135,44 +135,68 @@ VSL_Init(void)
 
 /*--------------------------------------------------------------------*/
 
-void
-VSL_MgtInit(const char *fn, unsigned size)
+static int
+vsl_goodold(int fd)
 {
        struct shmloghead slh;
-       int i = 0;
+       int i;
 
        memset(&slh, 0, sizeof slh);    /* XXX: for flexelint */
-       heritage.vsl_fd = open(fn, O_RDWR, 0644);
-       if (heritage.vsl_fd >= 0)
-               i = read(heritage.vsl_fd, &slh, sizeof slh);
-       if (heritage.vsl_fd < 0 || i != sizeof slh ||
-           slh.magic != SHMLOGHEAD_MAGIC ||
-           slh.hdrsize != sizeof slh) {
-               /* XXX more checks */
+       i = read(fd, &slh, sizeof slh);
+       if (i != sizeof slh)
+               return (0);
+       if (slh.magic != SHMLOGHEAD_MAGIC)
+               return (0);
+       if (slh.hdrsize != sizeof slh)
+               return (0);
+       if (slh.start != sizeof slh + sizeof *params)
+               return (0);
+       /* XXX more checks */
+       heritage.vsl_size = slh.size + slh.start;
+       return (1);
+}
 
+static void
+vsl_buildnew(const char *fn, unsigned size)
+{
+       struct shmloghead slh;
+       int i;
+
+       (void)unlink(fn);
+       heritage.vsl_fd = open(fn, O_RDWR | O_CREAT, 0644);
+       if (heritage.vsl_fd < 0) {
+               fprintf(stderr, "Could not open %s: %s\n",
+                   fn, strerror(errno));
+               exit (1);
+       }
+
+       memset(&slh, 0, sizeof slh);
+       slh.magic = SHMLOGHEAD_MAGIC;
+       slh.hdrsize = sizeof slh;
+       slh.size = size;
+       slh.ptr = 0;
+       slh.start = sizeof slh + sizeof *params;
+       i = write(heritage.vsl_fd, &slh, sizeof slh);
+       assert(i == sizeof slh);
+       heritage.vsl_size = slh.start + size;
+       AZ(ftruncate(heritage.vsl_fd, (off_t)heritage.vsl_size));
+}
+
+void
+VSL_MgtInit(const char *fn, unsigned size)
+{
+       int i;
+       struct params *pp;
+
+       i = open(fn, O_RDWR, 0644);
+       if (i >= 0 && vsl_goodold(i)) {
+               fprintf(stderr, "Using old SHMFILE\n");
+               heritage.vsl_fd = i;
+       } else {
                fprintf(stderr, "Creating new SHMFILE\n");
-               if (heritage.vsl_fd >= 0)
-                       close(heritage.vsl_fd);
-               (void)unlink(fn);
-               heritage.vsl_fd = open(fn, O_RDWR | O_CREAT, 0644);
-               if (heritage.vsl_fd < 0) {
-                       fprintf(stderr, "Could not open %s: %s\n",
-                           fn, strerror(errno));
-                       exit (1);
-               }
-
-               memset(&slh, 0, sizeof slh);
-               slh.magic = SHMLOGHEAD_MAGIC;
-               slh.hdrsize = sizeof slh;
-               slh.size = size;
-               slh.ptr = 0;
-               slh.start = sizeof slh;
-               AZ(lseek(heritage.vsl_fd, 0, SEEK_SET));
-               i = write(heritage.vsl_fd, &slh, sizeof slh);
-               assert(i == sizeof slh);
-               AZ(ftruncate(heritage.vsl_fd, (off_t)sizeof slh + (off_t)size));
+               (void)close(i);
+               vsl_buildnew(fn, size);
        }
-       heritage.vsl_size = slh.size + slh.start;
 
        loghead = mmap(NULL, heritage.vsl_size,
            PROT_READ|PROT_WRITE,
@@ -180,4 +204,7 @@ VSL_MgtInit(const char *fn, unsigned size)
            heritage.vsl_fd, 0);
        assert(loghead != MAP_FAILED);
        VSL_stats = &loghead->stats;
+       pp = (void *)(loghead + 1);
+       memcpy(pp, params, sizeof *pp);
+       params = pp;
 }
index bd503006ddfd3fece83b92ebac0bc7290c0419fc..2a1f340de147ebaaa6f0d9b278005deb869c0949 100644 (file)
@@ -32,6 +32,7 @@
 #endif
 
 struct heritage heritage;
+struct params *params;
 
 /*--------------------------------------------------------------------*/
 
@@ -188,13 +189,13 @@ tackle_warg(const char *argv)
                usage();
        if (ua < 1)
                usage();
-       heritage.wthread_min = ua;
-       heritage.wthread_max = ua;
-       heritage.wthread_timeout = 10;
+       params->wthread_min = ua;
+       params->wthread_max = ua;
+       params->wthread_timeout = 10;
        if (i >= 2)
-               heritage.wthread_max = ub;
+               params->wthread_max = ub;
        if (i >= 3)
-               heritage.wthread_timeout = uc;
+               params->wthread_timeout = uc;
 }
 
 /*--------------------------------------------------------------------
@@ -323,17 +324,20 @@ main(int argc, char *argv[])
        const char *sflag = "file";
        const char *hflag = "classic";
        const char *Tflag = NULL;
+       struct params param;
 
        setbuf(stdout, NULL);
        setbuf(stderr, NULL);
 
+       memset(&param, 0, sizeof param);
+       params = &param;
        mgt_vcc_init(); 
 
-       heritage.default_ttl = 120;
-       heritage.wthread_min = 1;
-       heritage.wthread_max = UINT_MAX;
-       heritage.wthread_timeout = 10;
-       heritage.mem_workspace = 4096;
+       params->default_ttl = 120;
+       params->wthread_min = 1;
+       params->wthread_max = UINT_MAX;
+       params->wthread_timeout = 10;
+       params->mem_workspace = 4096;
 
        while ((o = getopt(argc, argv, "b:df:h:p:s:t:T:Vw:")) != -1)
                switch (o) {
@@ -356,7 +360,7 @@ main(int argc, char *argv[])
                        sflag = optarg;
                        break;
                case 't':
-                       heritage.default_ttl = strtoul(optarg, NULL, 0);
+                       params->default_ttl = strtoul(optarg, NULL, 0);
                        break;
                case 'T':
                        Tflag = optarg;