From: phk Date: Sat, 19 Aug 2006 21:32:10 +0000 (+0000) Subject: Implement the first load of tweable parameters X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ee2a580343d1c0be7f78e54adef084cd12b52112;p=varnish Implement the first load of tweable parameters git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@838 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- diff --git a/varnish-cache/bin/varnishd/mgt_param.c b/varnish-cache/bin/varnishd/mgt_param.c index 59537ec2..69dd5976 100644 --- a/varnish-cache/bin/varnishd/mgt_param.c +++ b/varnish-cache/bin/varnishd/mgt_param.c @@ -2,27 +2,247 @@ * $Id$ */ +#include +#include #include +#include +#include "cli.h" #include "cli_priv.h" #include "mgt.h" #include "mgt_cli.h" +#include "heritage.h" + +struct parspec; + +typedef void tweak_t(struct cli *, struct parspec *, const char *arg); + +struct parspec { + const char *name; + tweak_t *func; + const char *expl; +}; + +/*--------------------------------------------------------------------*/ + +static void +tweak_default_ttl(struct cli *cli, struct parspec *par, const char *arg) +{ + + (void)par; + if (arg != NULL) + params->default_ttl = strtoul(arg, NULL, 0); + cli_out(cli, "%u [seconds]\n", params->default_ttl); +} + +/*--------------------------------------------------------------------*/ + +static void +tweak_thread_pool_min(struct cli *cli, struct parspec *par, const char *arg) +{ + unsigned u; + + (void)par; + if (arg != NULL) { + u = strtoul(arg, NULL, 0); + if (u >= params->wthread_max) { + cli_out(cli, "Minimum must be less than maximum\n"); + cli_result(cli, CLIS_PARAM); + return; + } + params->wthread_min = u; + } + cli_out(cli, "%u [threads]\n", params->wthread_min); +} + +/*--------------------------------------------------------------------*/ + +static void +tweak_thread_pool_max(struct cli *cli, struct parspec *par, const char *arg) +{ + unsigned u; + + (void)par; + if (arg != NULL) { + u = strtoul(arg, NULL, 0); + if (u <= params->wthread_min) { + cli_out(cli, "Maximum must be greater than minimum\n"); + cli_result(cli, CLIS_PARAM); + return; + } + params->wthread_max = u; + } + if (params->wthread_max == UINT_MAX) + cli_out(cli, "unlimited\n"); + else + cli_out(cli, "%u [threads]\n", params->wthread_max); +} + +/*--------------------------------------------------------------------*/ + +static void +tweak_thread_pool_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->wthread_timeout = u; + } + cli_out(cli, "%u [seconds]\n", params->wthread_timeout); +} +/*--------------------------------------------------------------------*/ + +static void +tweak_http_workspace(struct cli *cli, struct parspec *par, const char *arg) +{ + unsigned u; + + (void)par; + if (arg != NULL) { + u = strtoul(arg, NULL, 0); + if (u <= 1024) { + cli_out(cli, "Workspace must be at least 1024 bytes\n"); + cli_result(cli, CLIS_PARAM); + return; + } + params->mem_workspace = u; + } + cli_out(cli, "%u [bytes]\n", params->mem_workspace); +} + +/*--------------------------------------------------------------------*/ + +/* + * Make sure to end all lines with either a space or newline of the + * formatting will go haywire. + */ + +#define DELAYED_EFFECT \ + "\nNB: This parameter will take some time to take effect.\n" + +#define SHOULD_RESTART \ + "\nNB: This parameter will not take full effect until the " \ + "child process has been restarted.\n" + +#define MUST_RESTART \ + "\nNB: This parameter will not take any effect until the " \ + "child process has been restarted.\n" + + +static struct parspec parspec[] = { + { "default_ttl", tweak_default_ttl, + "The TTL assigned to objects if neither the backend nor " + "the VCL code assigns one.\n" + "Objects already cached will not be affected by changes " + "made until they are fetched from the backend again.\n" + "To force an immediate effect at the expense of a total " + "flush of the cache use \"url.purge .\"\n" + "Default is 120 seconds. " }, + { "thread_pool_min", tweak_thread_pool_min, + "The minimum number of threads in the worker pool.\n" + DELAYED_EFFECT + "Default is 1 thread. " + "Minimum is 1 thread. " }, + { "thread_pool_max", tweak_thread_pool_max, + "The maximum number of threads in the worker pool.\n" + DELAYED_EFFECT + "Default is no limit." }, + { "thread_pool_timeout", tweak_thread_pool_timeout, + "Thread dies after this many seconds of inactivity.\n" + "Default is 10 seconds. " + "Minimum is 1 second. " }, + { "http_workspace", tweak_http_workspace, + "Bytes of HTTP protocol workspace allocated. " + "This space must be big enough for the entire HTTP protocol " + "header and any edits done to it in the VCL code.\n" + SHOULD_RESTART + "Default is 4096 bytes. " + "Minimum is 1024 bytes. " }, + { NULL, NULL, NULL } +}; + +/*--------------------------------------------------------------------*/ + void mcf_param_show(struct cli *cli, char **av, void *priv) { + struct parspec *pp; + const char *p, *q; + int lfmt; - (void)cli; - (void)av; (void)priv; + if (av[2] == NULL || strcmp(av[2], "-l")) + lfmt = 0; + else + lfmt = 1; + for (pp = parspec; pp->name != NULL; pp++) { + if (av[2] != NULL && !lfmt && strcmp(pp->name, av[2])) + continue; + cli_out(cli, "%-20s ", pp->name); + if (pp->func == NULL) { + cli_out(cli, "Not implemented.\n"); + if (av[2] != NULL && !lfmt) + return; + else + continue; + } + pp->func(cli, pp, NULL); + if (av[2] != NULL) { + /* Format text to 72 col width */ + for (p = pp->expl; *p != '\0'; ) { + q = strchr(p, '\n'); + if (q == NULL) + q = strchr(p, '\0'); + assert(q != NULL); + if (q > p + 52) { + q = p + 52; + while (q > p && *q != ' ') + q--; + assert(q != NULL); + } + cli_out(cli, "%20s %.*s\n", "", q - p, p); + p = q; + if (*p == ' ' || *p == '\n') + p++; + } + if (!lfmt) + return; + else + cli_out(cli, "\n"); + } + } + if (av[2] != NULL && !lfmt) { + cli_result(cli, CLIS_PARAM); + cli_out(cli, "Unknown paramter \"%s\".", av[2]); + } } +/*--------------------------------------------------------------------*/ + void mcf_param_set(struct cli *cli, char **av, void *priv) { + struct parspec *pp; - (void)cli; - (void)av; (void)priv; + for (pp = parspec; pp->name != NULL; pp++) { + if (!strcmp(pp->name, av[2])) { + cli_out(cli, "%-20s ", pp->name); + pp->func(cli, pp, av[3]); + return; + } + } + if (av[2] != NULL) { + cli_result(cli, CLIS_PARAM); + cli_out(cli, "Unknown paramter \"%s\".", av[2]); + } } diff --git a/varnish-cache/include/cli.h b/varnish-cache/include/cli.h index 31fc17ec..7eb05d6e 100644 --- a/varnish-cache/include/cli.h +++ b/varnish-cache/include/cli.h @@ -79,9 +79,9 @@ #define CLI_PARAM_SHOW \ "param.show", \ - "param.show []", \ + "param.show [-l] []", \ "\tShow parameters and their values.", \ - 0, 1 + 0, 2 #define CLI_PARAM_SET \ "param.set", \