Mailing List Archive

r1002 - trunk/varnish-cache/bin/varnishd
Author: phk
Date: 2006-09-16 11:38:09 +0200 (Sat, 16 Sep 2006)
New Revision: 1002

Modified:
trunk/varnish-cache/bin/varnishd/cache_fetch.c
trunk/varnish-cache/bin/varnishd/heritage.h
trunk/varnish-cache/bin/varnishd/mgt_param.c
trunk/varnish-cache/bin/varnishd/tcp.c
Log:
Make the listen depth a paramter.

Clean up the paramter stuff even more.



Modified: trunk/varnish-cache/bin/varnishd/cache_fetch.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_fetch.c 2006-09-16 09:06:45 UTC (rev 1001)
+++ trunk/varnish-cache/bin/varnishd/cache_fetch.c 2006-09-16 09:38:09 UTC (rev 1002)
@@ -103,9 +103,9 @@
/* 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 @@
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;

Modified: trunk/varnish-cache/bin/varnishd/heritage.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/heritage.h 2006-09-16 09:06:45 UTC (rev 1001)
+++ trunk/varnish-cache/bin/varnishd/heritage.h 2006-09-16 09:38:09 UTC (rev 1002)
@@ -61,6 +61,9 @@
char *listen_address;
char *listen_host;
char *listen_port;
+
+ /* Listen depth */
+ unsigned listen_depth;
};

extern struct params *params;

Modified: trunk/varnish-cache/bin/varnishd/mgt_param.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/mgt_param.c 2006-09-16 09:06:45 UTC (rev 1001)
+++ trunk/varnish-cache/bin/varnishd/mgt_param.c 2006-09-16 09:38:09 UTC (rev 1002)
@@ -26,6 +26,7 @@
tweak_t *func;
const char *expl;
const char *def;
+ const char *units;
};

/*--------------------------------------------------------------------*/
@@ -44,20 +45,74 @@
}
*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);
+ }
+}
+
+/*--------------------------------------------------------------------*/
+
+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);
- else
- cli_out(cli, "%u [seconds]\n", params->default_ttl);
+ tweak_generic_uint(cli, &params->default_ttl, arg, 0, UINT_MAX);
}

/*--------------------------------------------------------------------*/
@@ -65,19 +120,10 @@
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, &params->wthread_min, arg,
+ 0, params->wthread_max);
}

/*--------------------------------------------------------------------*/
@@ -85,22 +131,10 @@
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, &params->wthread_max, arg,
+ params->wthread_min, UINT_MAX);
}

/*--------------------------------------------------------------------*/
@@ -118,19 +152,10 @@
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, &params->mem_workspace, arg,
+ 1024, UINT_MAX);
}

/*--------------------------------------------------------------------*/
@@ -165,19 +190,9 @@
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, &params->auto_restart, arg);
}

/*--------------------------------------------------------------------*/
@@ -185,14 +200,10 @@
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, &params->fetch_chunksize, arg,
+ 4, UINT_MAX / 1024);
}

#ifdef HAVE_SENDFILE
@@ -201,14 +212,9 @@
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, &params->sendfile_threshold, arg, 0, UINT_MAX);
}
#endif /* HAVE_SENDFILE */

@@ -218,26 +224,7 @@
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, &params->vcl_trace, arg);
}

/*--------------------------------------------------------------------*/
@@ -269,10 +256,20 @@
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, &params->listen_depth, arg, 0, UINT_MAX);
+}
+
+/*--------------------------------------------------------------------*/
+
/*
* Make sure to end all lines with either a space or newline of the
* formatting will go haywire.
@@ -297,64 +294,69 @@
"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 @@
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 @@
{
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;
+ }
}

Modified: trunk/varnish-cache/bin/varnishd/tcp.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/tcp.c 2006-09-16 09:06:45 UTC (rev 1001)
+++ trunk/varnish-cache/bin/varnishd/tcp.c 2006-09-16 09:38:09 UTC (rev 1002)
@@ -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 @@
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);