NaviServer - programmable web server


[ Main Table Of Contents | Table Of Contents | Keyword Index ]

ns_limits(n) 4.99.8 naviserver "NaviServer Built-In Commands"

Name

ns_limits - Connection request resource limits

Table Of Contents

Synopsis

Description

There are 4 limits which may be set to protect the server: the maximum number of running connections, the maximum number of waiting connections, max number of bytes the server will read, and the response timeout.

The four limits are assembled into a bundle and the bundle is registered for one or more URLs.

A default limits bundle is created at server startup and applies to all URLs which do not have a more specific limit registered. The configuration options can be adjusted for the default limits and any additional limits created at run-time.

COMMANDS

ns_limits_set ?-maxrun n? ?-maxwait n? ?-maxupload n? ?-timeout t? ?--? limit

Set the configuration options for a named limits bundle. If the limit does not exist it will be created. Default values are used for unspecified options.

Limits bundles exist in a process-wide namespace. The single limit X may be registered for more than one virtual server. This makes sense, as the resources being controlled are a limit of the machine the NaviServer is running on (or some subset of) and affects all virtual servers.

-maxrun n

The maximum number of connections which can be running simultaneously for all URLs bound to this limit. Default: 100.

-maxwait n

The maximum number of connections which can be simultaneously waiting to run because a thread is not available. Default: 100.

-maxupload bytes

The maximum size, in bytes, which the server will accept for POST, PUT etc. requests. Default: 10240000.

-timeout t

The number of seconds within which a request should run to completion. Default: 100.

ns_limits_get limit

Get the current configuration options and accumulated runtime statistics for the named limits bundle. The result is a list in Tcl array-get format which can be used, for example, to initialise a hash table.

nrunning

The number of connections currently running with a URL which is mapped to this limit bundle.

nwaiting

The number of active connections waiting to run because either there is no connection thread available or the ?maxrun? limit has been reached.

ntimeout

Number of connections closed due to timeout.

ndropped

Number of connections dropped due to...

noverflow

Number of connections dropped due to ...

maxrun

The current maxrun configuration option, which may be adjusted by a call to ns_limits_set with the -maxrun option.

maxwait

The current maxwait configuration option, which may be adjusted by a call to ns_limits_set with the -maxwait option.

maxupload

The current maxupload configuration option, which may be adjusted by a call to ns_limits_set with the -maxupload option.

timeout

The current timout configuration option, which may be adjusted by a call to ns_limits_set with the -timeout option.

ns_limits_register ?-noinherit bool? ?-server s? ?--? limit method url

Register the named limits for the given URL.

-noinherit boolean

If specified, a request URL such as /foo/bar will not match a limit registered on /foo. The default is false -- URL inheritence applies. The mechanism is the same as ns_register_proc.

-server server

The virtual server to use. Defaults to the server the command is run within if not specified. Limits are server global, but must be registered per-virtual server. This is mainly useful for startup scripts such as the main init.tcl bootstrap, which does not run within the context of a virtual server.

ns_limits_list ?pattern?

List the names of all limit structures, or only those whose name matches the given glob pattern. The limit names can be passed to ns_limits_get and ns_limits_register.

CONFIGURATION

The following configuration options are available to control limits at server startup in addition to the ns_limits commands which can be run once the the server has started:

ns/limits

Global limit names and descriptions:

ns_section "ns/limits"
ns_param   default   "Default connections"
ns_param   slow      "Slow connections"
ns/limit/$limitname

Global limit configurations:

ns_section "ns/limit/default"
ns_param   maxrun    100
ns_param   maxwait   100
ns_param   maxupload 10240000
ns_param   timeout   60
ns_section "ns/limit/slow"
ns_param   maxrun    10
ns_param   maxwait   0
ns/server/server1/limits

Mapping virtual server URLs to global limits:

ns_section "ns/server/server1/limits"
ns_param   default   {GET /*}
ns_param   slow      {GET /download}
ns_param   slow      {GET /*.pdf}

EXAMPLES

The following example shows how to prevent large file downloads (which may take some time to complete) from using up all available connection slots, preventing other pages from being served.

The large files are loacted in the /download directory. We also want to control large PDF files which are located throughout the URL hierarchy using the same limit.

With this configuration there can be at most 10 simultaneous downloads of PDF files or files in the /download directory, in total, at any one time. Reuquests for other URLs will have the default limit applied.

ns_limits_set -maxrun 10 -maxwait 0 -- slow
ns_limits_register slow GET /download
ns_limits_register slow GET /*.pdf

The following example proc can be used to log statistics on failed requests peridoically:

proc log_limits {} {
    foreach limit [ns_limits_list] {
        array set l [ns_limits_get $limit]
        ns_log notice "limit[$limit]: " \
            "timeouts: $l(ntimeout) drops: $l(ndropped) overflows: $l(noverflow)"
    }
}
ns_schedule_proc 3600 log_limits

See Also

ns_server

Keywords

configuration, limit, resource, timeout, upload