varnishd·续1

Persistent storage. Varnish will store objects in a file in a manner that will secure the survival of most of the objects in the event of a planned or unplanned shutdown of Varnish. The persistent storage backend has multiple issues with it and will likely be removed from a future version of Varnish.

Jail#

Varnish jails are a generalization over various platform specific methods to reduce the privileges of varnish processes. They may have specific options. Available jails are:

-j <solaris[,worker=`privspec`]>

Reduce privileges(5) for varnishd and sub-processes to the minimally required set. Only available on platforms which have the setppriv(2) call.

The optional worker argument can be used to pass a privilege-specification (see ppriv(1)) by which to extend the effective set of the varnish worker process. While extended privileges may be required by custom vmods, not using the worker option is always more secure.

Example to grant basic privileges to the worker process::

-j solaris,worker=basic



-j <linux[,transparent_hugepage=`thp_setting`][,`unix jail option`...]>

Default on Linux platforms, it extends the UNIX jail with Linux-specific mechanisms:

  • It warns when workdir is not on a tmpfs.
  • It tries to keep the process dumpable after dropping privileges.
  • It adds control over the transparent hugepage (THP) setting.

thp_setting can take these values:

  • ignore: Do nothing
  • enable: Enable THP (see Note below)
  • disable: Disable THP
  • try-disable (default): Try to disable, ignore failure (but emit a warning)

Note: Technically, enable is “disable the disable”, so it does not necessarily enable THP. The setting names have been chosen to avoid a confusing double negation.

-j <unix[,user=`user`][,ccgroup=`group`][,workuser=`user`]>

Default on all other platforms when varnishd is started with an effective uid of 0 (“as root”).

With the unix jail mechanism activated, varnish will switch to an alternative user for subprocesses and change the effective uid of the master process whenever possible.

The optional user argument specifies which alternative user to use. It defaults to varnish.

The optional ccgroup argument specifies a group to add to varnish subprocesses requiring access to a c-compiler. There is no default.

The optional workuser argument specifies an alternative user to use for the worker process. It defaults to vcache.

The users given for the user and workuser arguments need to have the same primary (“login”) group.

To set up a system for the default users with a group name varnish, shell commands similar to these may be used:

  groupadd varnish
  useradd -g varnish -d /nonexistent -s /bin/false \
    -c "Varnish-Cache Daemon User" varnish
  useradd -g varnish -d /nonexistent -s /bin/false \
    -c "Varnish-Cache Worker User" vcache



-j none

last resort jail choice: With jail mechanism none, varnish will run all processes with the privileges it was started with.

Management Interface#

If the -T option was specified, varnishd will offer a command-line management interface on the specified address and port. The recommended way of connecting to the command-line management interface is through varnishadm.

The commands available are documented in varnish-cli.

CLI Command File#

The -I option makes it possible to run arbitrary management commands when varnishd is launched, before the worker process is started. In particular, this is the way to load configurations, apply labels to them, and make a VCL instance active that uses those labels on startup:

vcl.load panic /etc/varnish_panic.vcl
vcl.load siteA0 /etc/varnish_siteA.vcl
vcl.load siteB0 /etc/varnish_siteB.vcl
vcl.load siteC0 /etc/varnish_siteC.vcl
vcl.label siteA siteA0
vcl.label siteB siteB0
vcl.label siteC siteC0
vcl.load main /etc/varnish_main.vcl
vcl.use main

Every line in the file, including the last line, must be terminated by a newline or carriage return or is otherwise considered truncated, which is a fatal error.

If a command in the file is prefixed with ‘-’, failure will not abort the startup.

Note that it is necessary to include an explicit vcl.use command to select which VCL should be the active VCL when relying on CLI Command File to load the configurations at startup.

RUN TIME PARAMETERS#

Runtime parameters can either be set during startup with the -p command line option for varnishd(1) or through the CLI using the param.set or param.reset commands. They can be locked during startup with the -r command line option.

Run Time Parameter Units#

There are different types of parameters that may accept a list of specific values, or optionally take a unit suffix.

bool#

A boolean parameter accepts the values on and off.

It will also recognize the following values:

  • yes and no
  • true and false
  • enable and disable
bytes#

A bytes parameter requires one of the following units suffixes:

  • b (bytes)
  • k (kibibytes, 1024 bytes)
  • m (mebibytes, 1024 kibibytes)
  • g (gibibytes, 1024 mebibytes)
  • t (tebibytes, 1024 gibibytes)
  • p (pebibytes, 1024 tebibytes)

Multiplicator units may be appended with an extra b. For example 32k is equivalent to 32kb. Bytes units are case-insensitive.

seconds#

A duration parameter may accept the following units suffixes:

  • ms (milliseconds)
  • s (seconds)
  • m (minutes)
  • h (hours)
  • d (days)
  • w (weeks)
  • y (years)

If the parameter is a timeout or a deadline, a value of “never” (when allowed) disables the effect of the parameter.

Run Time Parameter Flags#

Runtime parameters are marked with shorthand flags to avoid repeating the same text over and over in the table below. The meaning of the flags are:

  • experimental

We have no solid information about good/bad/optimal values for this parameter. Feedback with experience and observations are most welcome.

  • delayed

This parameter can be changed on the fly, but will not take effect immediately.

  • restart

The worker process must be stopped and restarted, before this parameter takes effect.

  • reload

The VCL programs must be reloaded for this parameter to take effect.

  • wizard

Do not touch unless you really know what you’re doing.

  • only_root

Only works if varnishd is running as root.

Default Value Exceptions on 32 bit Systems#

Be aware that on 32 bit systems, certain default or maximum values are reduced relative to the values listed below, in order to conserve VM space:

  • workspace_client: 24k
  • workspace_backend: 20k
  • http_resp_size: 8k
  • http_req_size: 12k
  • gzip_buffer: 4k
  • vsl_buffer: 4k
  • vsl_space: 1G (maximum)
  • thread_pool_stack: 64k

List of Parameters#

This text is produced from the same text you will find in the CLI if you use the param.show command:

accept_filter#

NB: This parameter depends on a feature which is not available on all platforms.

  • Units: bool
  • Default: on (if your platform supports accept filters)

Enable kernel accept-filters. This may require a kernel module to be loaded to have an effect when enabled.

Enabling accept_filter may prevent some requests to reach Varnish in the first place. Malformed requests may go unnoticed and not increase the client_req_400 counter. GET or HEAD requests with a body may be blocked altogether.

acceptor_sleep_decay#
  • Default: 0.9
  • Minimum: 0
  • Maximum: 1
  • Flags: experimental

If we run out of resources, such as file descriptors or worker threads, the acceptor will sleep between accepts. This parameter (multiplicatively) reduce the sleep duration for each successful accept. (ie: 0.9 = reduce by 10%)

acceptor_sleep_incr#
  • Units: seconds
  • Default: 0.000
  • Minimum: 0.000
  • Maximum: 1.000
  • Flags: experimental

If we run out of resources, such as file descriptors or worker threads, the acceptor will sleep between accepts. This parameter control how much longer we sleep, each time we fail to accept a new connection.

acceptor_sleep_max#
  • Units: seconds
  • Default: 0.050
  • Minimum: 0.000
  • Maximum: 10.000
  • Flags: experimental

If we run out of resources, such as file descriptors or worker threads, the acceptor will sleep between accepts. This parameter limits how long it can sleep between attempts to accept new connections.

auto_restart#
  • Units: bool
  • Default: on

Automatically restart the child/worker process if it dies.

backend_idle_timeout#
  • Units: seconds
  • Default: 60.000
  • Minimum: 1.000

Timeout before we close unused backend connections.

backend_local_error_holddown#
  • Units: seconds
  • Default: 10.000
  • Minimum: 0.000
  • Flags: experimental

When connecting to backends, certain error codes (EADDRNOTAVAIL, EACCESS, EPERM) signal a local resource shortage or configuration issue for which retrying connection attempts may worsen the situation due to the complexity of the operations involved in the kernel. This parameter prevents repeated connection attempts for the configured duration.

backend_remote_error_holddown#
  • Units: seconds
  • Default: 0.250
  • Minimum: 0.000
  • Flags: experimental

When connecting to backends, certain error codes (ECONNREFUSED, ENETUNREACH) signal fundamental connection issues such as the backend not accepting connections or routing problems for which repeated connection attempts are considered useless This parameter prevents repeated connection attempts for the configured duration.

backend_wait_limit#
  • Default: 0
  • Minimum: 0
  • Flags: experimental

Maximum number of transactions that can queue waiting for a backend connection to become available. This default of 0 (zero) means that there is no transaction queueing. VCL can override this default value for each backend.

Note that this feature must be used with caution, as it can cause threads to pile up and increase response times.

backend_wait_timeout#
  • Units: seconds
  • Default: 0.000
  • Minimum: 0.000
  • Flags: timeout, experimental

When a backend has no connections available for a transaction, the transaction can be queued (see backend_wait_limit) to wait for a connection. This is the default time that the transaction will wait before giving up. VCL can override this default value for each backend.

It is strongly advised to never set this higher than a couple of seconds.

ban_any_variant#
  • Units: checks
  • Default: 0
  • Minimum: 0

Maximum number of possibly non matching variants that we evaluate against the ban list during a lookup. Setting this to 0 means that only the matching variants will be evaluated against the current ban list.

ban_cutoff#
  • Units: bans
  • Default: 0
  • Minimum: 0
  • Flags: experimental

Expurge long tail content from the cache to keep the number of bans below this value. 0 disables.

When this parameter is set to a non-zero value, the ban lurker continues to work the ban list as usual top to bottom, but when it reaches the ban_cutoff-th ban, it treats all objects as if they matched a ban and expunges them from cache. As actively used objects get tested against the ban list at request time and thus are likely to be associated with bans near the top of the ban list, with ban_cutoff, least recently accessed objects (the “long tail”) are removed.

This parameter is a safety net to avoid bad response times due to bans being tested at lookup time. Setting a cutoff trades response time for cache efficiency. The recommended value is proportional to rate(bans_lurker_tests_tested) / n_objects while the ban lurker is working, which is the number of bans the system can sustain. The additional latency due to request ban testing is in the order of ban_cutoff / rate(bans_lurker_tests_tested). For example, for rate(bans_lurker_tests_tested) = 2M/s and a tolerable latency of 100ms, a good value for ban_cutoff may be 200K.

ban_dups#
  • Units: bool
  • Default: on

Eliminate older identical bans when a new ban is added. This saves CPU cycles by not comparing objects to identical bans. This is a waste of time if you have many bans which are never identical.

ban_lurker_age#
  • Units: seconds
  • Default: 60.000
  • Minimum: 0.000

The ban lurker will ignore bans until they are this old. When a ban is added, the active traffic will be tested against it as part of object lookup. Because many applications issue bans in bursts, this parameter holds the ban-lurker off until the rush is over. This should be set to the approximate time which a ban-burst takes.

ban_lurker_batch#
  • Default: 1000
  • Minimum: 1

The ban lurker sleeps ${ban_lurker_sleep} after examining this many objects. Use this to pace the ban-lurker if it eats too many resources.

ban_lurker_holdoff#
  • Units: seconds
  • Default: 0.010
  • Minimum: 0.000
  • Flags: experimental

How long the ban lurker sleeps when giving way to lookup due to lock contention.