From 0b93b4dff5b64895920d72f8bcf834a59dfad102 Mon Sep 17 00:00:00 2001 From: phk Date: Sat, 16 Sep 2006 09:38:09 +0000 Subject: [PATCH] Make the listen depth a paramter. Clean up the paramter stuff even more. git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@1002 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- varnish-cache/bin/varnishd/cache_fetch.c | 7 +- varnish-cache/bin/varnishd/heritage.h | 3 + varnish-cache/bin/varnishd/mgt_param.c | 237 ++++++++++++----------- varnish-cache/bin/varnishd/tcp.c | 3 +- 4 files changed, 133 insertions(+), 117 deletions(-) diff --git a/varnish-cache/bin/varnishd/cache_fetch.c b/varnish-cache/bin/varnishd/cache_fetch.c index dbec3008..9d3597a6 100644 --- a/varnish-cache/bin/varnishd/cache_fetch.c +++ b/varnish-cache/bin/varnishd/cache_fetch.c @@ -103,9 +103,9 @@ fetch_chunked(const struct sess *sp, int fd, struct http *hp) /* Get some storage if we don't have any */ if (st == NULL || st->len == st->space) { v = u; - if (u < params->fetch_chunksize && + if (u < params->fetch_chunksize * 1024 && stevedore->trim != NULL) - v = params->fetch_chunksize; + v = params->fetch_chunksize * 1024; st = stevedore->alloc(stevedore, v); XXXAN(st->stevedore); TAILQ_INSERT_TAIL(&sp->obj->store, st, list); @@ -180,7 +180,8 @@ fetch_eof(const struct sess *sp, int fd, struct http *hp) st = NULL; while (1) { if (v == 0) { - st = stevedore->alloc(stevedore, params->fetch_chunksize); + st = stevedore->alloc(stevedore, + params->fetch_chunksize * 1024); XXXAN(st->stevedore); TAILQ_INSERT_TAIL(&sp->obj->store, st, list); p = st->ptr + st->len; diff --git a/varnish-cache/bin/varnishd/heritage.h b/varnish-cache/bin/varnishd/heritage.h index 0c528377..1089b14f 100644 --- a/varnish-cache/bin/varnishd/heritage.h +++ b/varnish-cache/bin/varnishd/heritage.h @@ -61,6 +61,9 @@ struct params { char *listen_address; char *listen_host; char *listen_port; + + /* Listen depth */ + unsigned listen_depth; }; extern struct params *params; diff --git a/varnish-cache/bin/varnishd/mgt_param.c b/varnish-cache/bin/varnishd/mgt_param.c index abca995e..1fb1004d 100644 --- a/varnish-cache/bin/varnishd/mgt_param.c +++ b/varnish-cache/bin/varnishd/mgt_param.c @@ -26,6 +26,7 @@ struct parspec { tweak_t *func; const char *expl; const char *def; + const char *units; }; /*--------------------------------------------------------------------*/ @@ -44,7 +45,64 @@ tweak_generic_timeout(struct cli *cli, unsigned *dst, const char *arg) } *dst = u; } else - cli_out(cli, "%u [seconds]\n", *dst); + cli_out(cli, "%u", *dst); +} + +/*--------------------------------------------------------------------*/ + +static void +tweak_generic_bool(struct cli *cli, unsigned *dest, const char *arg) +{ + if (arg != NULL) { + if (!strcasecmp(arg, "off")) + *dest = 0; + else if (!strcasecmp(arg, "disable")) + *dest = 0; + else if (!strcasecmp(arg, "no")) + *dest = 0; + else if (!strcasecmp(arg, "on")) + *dest = 1; + else if (!strcasecmp(arg, "enable")) + *dest = 1; + else if (!strcasecmp(arg, "yes")) + *dest = 1; + else { + cli_out(cli, "use \"on\" or \"off\"\n"); + cli_result(cli, CLIS_PARAM); + return; + } + } else + cli_out(cli, *dest ? "on" : "off"); +} + +/*--------------------------------------------------------------------*/ + +static void +tweak_generic_uint(struct cli *cli, unsigned *dest, const char *arg, unsigned min, unsigned max) +{ + unsigned u; + + if (arg != NULL) { + if (!strcasecmp(arg, "unlimited")) + u = UINT_MAX; + else + u = strtoul(arg, NULL, 0); + if (u < min) { + cli_out(cli, "Must be at least %u", min); + cli_result(cli, CLIS_PARAM); + return; + } + if (u > max) { + cli_out(cli, "Must be no more than %u", max); + cli_result(cli, CLIS_PARAM); + return; + } + *dest = u; + } else if (*dest == UINT_MAX) { + cli_out(cli, "unlimited", *dest); + } else { + cli_out(cli, "%u", *dest); + } } /*--------------------------------------------------------------------*/ @@ -54,10 +112,7 @@ tweak_default_ttl(struct cli *cli, struct parspec *par, const char *arg) { (void)par; - if (arg != NULL) - params->default_ttl = strtoul(arg, NULL, 0); - else - cli_out(cli, "%u [seconds]\n", params->default_ttl); + tweak_generic_uint(cli, ¶ms->default_ttl, arg, 0, UINT_MAX); } /*--------------------------------------------------------------------*/ @@ -65,19 +120,10 @@ tweak_default_ttl(struct cli *cli, struct parspec *par, const char *arg) 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; - } else - cli_out(cli, "%u [threads]\n", params->wthread_min); + tweak_generic_uint(cli, ¶ms->wthread_min, arg, + 0, params->wthread_max); } /*--------------------------------------------------------------------*/ @@ -85,22 +131,10 @@ tweak_thread_pool_min(struct cli *cli, struct parspec *par, const char *arg) 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); + tweak_generic_uint(cli, ¶ms->wthread_max, arg, + params->wthread_min, UINT_MAX); } /*--------------------------------------------------------------------*/ @@ -118,19 +152,10 @@ tweak_thread_pool_timeout(struct cli *cli, struct parspec *par, const char *arg) 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; - } else - cli_out(cli, "%u [bytes]\n", params->mem_workspace); + tweak_generic_uint(cli, ¶ms->mem_workspace, arg, + 1024, UINT_MAX); } /*--------------------------------------------------------------------*/ @@ -165,19 +190,9 @@ tweak_send_timeout(struct cli *cli, struct parspec *par, const char *arg) static void tweak_auto_restart(struct cli *cli, struct parspec *par, const char *arg) { - unsigned u; (void)par; - if (arg != NULL) { - u = strtoul(arg, NULL, 0); - if (u != 0 && u != 1) { - cli_out(cli, "Only zero and one allowed.\n"); - cli_result(cli, CLIS_PARAM); - return; - } - params->auto_restart = u; - } else - cli_out(cli, "%u {1 = yes, 0 = no}\n", params->auto_restart); + tweak_generic_bool(cli, ¶ms->auto_restart, arg); } /*--------------------------------------------------------------------*/ @@ -185,14 +200,10 @@ tweak_auto_restart(struct cli *cli, struct parspec *par, const char *arg) static void tweak_fetch_chunksize(struct cli *cli, struct parspec *par, const char *arg) { - unsigned u; (void)par; - if (arg != NULL) { - u = strtoul(arg, NULL, 0); - params->fetch_chunksize = u * 1024; - } else - cli_out(cli, "%u [kb]\n", params->fetch_chunksize * 1024); + tweak_generic_uint(cli, ¶ms->fetch_chunksize, arg, + 4, UINT_MAX / 1024); } #ifdef HAVE_SENDFILE @@ -201,14 +212,9 @@ tweak_fetch_chunksize(struct cli *cli, struct parspec *par, const char *arg) static void tweak_sendfile_threshold(struct cli *cli, struct parspec *par, const char *arg) { - unsigned u; (void)par; - if (arg != NULL) { - u = strtoul(arg, NULL, 0); - params->sendfile_threshold = u; - } else - cli_out(cli, "%u [bytes]\n", params->sendfile_threshold); + tweak_generic_uint(cli, ¶ms->sendfile_threshold, arg, 0, UINT_MAX); } #endif /* HAVE_SENDFILE */ @@ -218,26 +224,7 @@ static void tweak_vcl_trace(struct cli *cli, struct parspec *par, const char *arg) { (void)par; - if (arg != NULL) { - if (!strcasecmp(arg, "off")) - params->vcl_trace = 0; - else if (!strcasecmp(arg, "disable")) - params->vcl_trace = 0; - else if (!strcasecmp(arg, "no")) - params->vcl_trace = 0; - else if (!strcasecmp(arg, "on")) - params->vcl_trace = 1; - else if (!strcasecmp(arg, "enable")) - params->vcl_trace = 1; - else if (!strcasecmp(arg, "yes")) - params->vcl_trace = 1; - else { - cli_out(cli, "use \"on\" or \"off\"\n"); - cli_result(cli, CLIS_PARAM); - return; - } - } else - cli_out(cli, params->vcl_trace ? "on\n" : "off\n"); + tweak_generic_bool(cli, ¶ms->vcl_trace, arg); } /*--------------------------------------------------------------------*/ @@ -269,8 +256,18 @@ tweak_listen_address(struct cli *cli, struct parspec *par, const char *arg) params->listen_host = a; params->listen_port = p; } else - cli_out(cli, "%s\n", params->listen_address); + cli_out(cli, "%s", params->listen_address); +} + +/*--------------------------------------------------------------------*/ + +static void +tweak_listen_depth(struct cli *cli, struct parspec *par, const char *arg) +{ + (void)par; + tweak_generic_uint(cli, ¶ms->listen_depth, arg, 0, UINT_MAX); } + /*--------------------------------------------------------------------*/ /* @@ -297,64 +294,69 @@ static struct parspec parspec[] = { "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. ", "120" }, + "flush of the cache use \"url.purge .\"", + "120", "seconds" }, { "thread_pool_max", tweak_thread_pool_max, "The maximum number of threads in the worker pool.\n" - DELAYED_EFFECT - "Default is no limit.", "-1" }, + "-1 is unlimited.\n" + DELAYED_EFFECT, + "-1", "threads" }, { "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. ", "1" }, + "Minimum is 1 thread. ", + "1", "threads" }, { "thread_pool_timeout", tweak_thread_pool_timeout, "Thread dies after this many seconds of inactivity.\n" - "Default is 120 seconds. " - "Minimum is 1 second. ", "120" }, + "Minimum is 1 second. ", + "120", "seconds" }, { "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 8192 bytes. " - "Minimum is 1024 bytes. ", "8192" }, + "Minimum is 1024 bytes. ", + "8192", "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" - "Default is 5 seconds. ", "5" }, + "seconds, the session is closed.\n", + "5", "seconds" }, { "pipe_timeout", tweak_pipe_timeout, "Idle timeout for PIPE sessions. " "If nothing have been received in either directoin for " - "this many seconds, the session is closed.\n" - "Default is 60 seconds. ", "60" }, + "this many seconds, the session is closed.\n", + "60", "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" DELAYED_EFFECT - "See getopt(3) under SO_SNDTIMEO for more information.\n" - "Default is 600 seconds. ", "600" }, + "See getopt(3) under SO_SNDTIMEO for more information.\n", + "600", "seconds" }, { "auto_restart", tweak_auto_restart, - "Restart child process automatically if it dies. " - "1 = yes, 0 = no.\n" - "Default is 1. ", "1" }, + "Restart child process automatically if it dies.\n" + "Minimum is 4 kilobytes.\n", + "on", "bool" }, { "fetch_chunksize", tweak_fetch_chunksize, - "The default chunksize used by fetcher.\n" - "Default is 128 kilobytes. ", "128" }, + "The default chunksize used by fetcher.\n", + "128", "kilobytes" }, #ifdef HAVE_SENDFILE { "sendfile_threshold", tweak_sendfile_threshold, - "The minimum size of objects transmitted with sendfile.\n" - "Default is 8192 bytes.", "8192" }, + "The minimum size of objects transmitted with sendfile.\n", + "8192", "bytes" }, #endif /* HAVE_SENDFILE */ { "vcl_trace", tweak_vcl_trace, - "Trace VCL execution in the shmlog\n" - "Default is off", "off" }, + "Trace VCL execution in the shmlog\n", + "off", "bool" }, { "listen_address", tweak_listen_address, "The network address/port where Varnish services requests.\n" - MUST_RESTART - "Default is \"0.0.0.0:80\"", "0.0.0.0:80" }, + MUST_RESTART, + "0.0.0.0:80" }, + { "listen_depth", tweak_listen_depth, + "Listen(2) queue depth.\n" + MUST_RESTART, + "1024", "connections" }, { NULL, NULL, NULL } }; @@ -384,7 +386,12 @@ mcf_param_show(struct cli *cli, char **av, void *priv) continue; } pp->func(cli, pp, NULL); + if (pp->units != NULL) + cli_out(cli, " [%s]\n", pp->units); + else + cli_out(cli, "\n"); if (av[2] != NULL) { + cli_out(cli, "%-20s Default is %s\n", "", pp->def); /* Format text to 72 col width */ for (p = pp->expl; *p != '\0'; ) { q = strchr(p, '\n'); @@ -448,6 +455,10 @@ MCF_ParamInit(struct cli *cli) { struct parspec *pp; - for (pp = parspec; pp->name != NULL; pp++) + for (pp = parspec; pp->name != NULL; pp++) { + cli_out(cli, "Set Default for %s = %s\n", pp->name, pp->def); pp->func(cli, pp, pp->def); + if (cli->result != CLIS_OK) + return; + } } diff --git a/varnish-cache/bin/varnishd/tcp.c b/varnish-cache/bin/varnishd/tcp.c index f3764a59..39823837 100644 --- a/varnish-cache/bin/varnishd/tcp.c +++ b/varnish-cache/bin/varnishd/tcp.c @@ -21,6 +21,7 @@ #include "compat/strndup.h" #endif +#include "heritage.h" #include "mgt.h" #include "cli.h" #include "cli_priv.h" @@ -165,7 +166,7 @@ TCP_open(const char *addr, const char *port, int http) close(sd); return (-1); } - if (listen(sd, http ? 1024 : 16) != 0) { + if (listen(sd, http ? params->listen_depth : 16) != 0) { perror("listen()"); freeaddrinfo(res); close(sd); -- 2.39.5