NaviServer - programmable web server
4.99  5.0

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

ns_server(n) 4.99.30 naviserver "NaviServer Built-in Commands"

Name

ns_server - Get state of the server's connection pools and queues

Table Of Contents

Synopsis

Description

This command provides a way to examine the current server's connection pools and queues. The allowed options (which may be abbreviated) are:

COMMANDS

ns_server ?-server s? filters

Returns a list of the currently defined filters.

ns_server ?-server s? pagedir

Returns the path of the virtual server's page directory root.

ns_server ?-server s? pools

Returns a list of the pools defined for this server.

ns_server ?-server s? requestprocs

Returns a list of the currently defined requestprocs (the registered procs for certain request patterns).

ns_server ?-server s? serverdir

Returns the path of the virtual server's base directory.

ns_server ?-server s? tcllib

Returns the path of the virtual server's private Tcl library.

ns_server ?-server s? traces

Returns a list of the currently defined traces.

ns_server ?-server s? url2file

Returns a list of the mappings from URLs to files.

ns_server ?-server s? ?-pool p? active ?-checkforproxy?
ns_server ?-server s? ?-pool p? all ?-checkforproxy?
ns_server ?-server s? ?-pool p? queued

These three commands return information about queued or running requests. For every request the command returns a list containing connection id, the peer address, state ("running" or "queued"), the request (HTTP method and url), running time, and bytes sent. The sub-command all returns the union of the running and queued requests.

When option -checkforproxy is given, it tries to return the peer address from "X-Forwarded-For" header field. If this is not possible (not given, or empty, or having the value "unknown") it falls back to the physical peer address.

ns_server ?-server s? ?-pool p? connections

Returns the number of connection requests processed by this pool since startup.

ns_server ?-server s? ?-pool p? map ?-noinherit? ?mapspec?

When the optional mapping specification (argument mapspec) is provided add this mapping to the server and pool (as specified or default). As a consequence matching requests (based on HTTP method and path) will be mapped to this connection pool.

When the optional argument mapspec is not provided, the command returns a list of mappings for the (given or default) server and pool.

ns_server ?-server s? mapped ?-exact? ?-noinherit? mapspec

Return the connection pool associated with the mapping specification (HTTP method and path). When the option -exact is used, the inheritance is deactivated, and only the values are returned directly assigned to the URL. When the option -noinherit is specified, only values set with the -noinherit flag are returned. For requests handled by the default connection pool, empty is returned.

ns_server ?-server s? ?-pool p? maxthreads ?value?

Query or set the maximum number of connection threads for this server and pool. The value must be large than minthreads and less than the maximum number of connections.

ns_server ?-server s? ?-pool p? minthreads ?value?

Query or set the minimum number of connection threads for this server and pool. The value must be between 1 and maxthreads.

ns_server ?-server s? ?-pool p? connectionratelimit ?value?

Query or set the maximum transmission rate per connection when data is sent via writer threads. The value is provided as KB/s. 0 means no rate limit.

ns_server ?-server s? ?-pool p? poolratelimit ?value?

Query or set the maximum transmission rate for the pool when data is sent via writer threads. The value is provided as KB/s. 0 means no rate limit. When the pool rate limit is set, all connections in this pool are managed.

ns_server ?-server s? ?-pool p? stats

Returns a list of attribute value pairs containing statistics for the server and pool, containing the number of requests, queued requests, dropped requests (queue overruns), cumulative times, and the number of started threads.

ns_server ?-server s? ?-pool p? threads

Returns a list of attribute value pairs containing information about the number of connection threads for the server and pool.

ns_server ?-server s? ?-pool p? unmap ?-noinherit? mapspec

Undo the effect of a ns_server map operation. As a consequence formerly mapped requests will be served by the default connection pool.

Limitation: when the mapspec contains a context filter (see below) this is ignored, all entries with the specified HTTP method and path are unmapped.

ns_server ?-server s? ?-pool p? waiting

Returns the number of connections waiting (i.e. queued) to be processed.

OPTIONS

-server s

Specifies the (virtual) server to be queried. If this option is not specified, the current server is used as a source.

-pool p

Specifies the pool to be queried. If this option is not specified, the default pool of the server is used as a source.

-noinherit

Optional flag for the connection pool mappings. When used, the specified path will be used literally, i.e., only exactly this path, but no sub-paths are mapped.

mapspec

A list of two or three arguments, containing an HTTP method, a path and optionally a context filter. Example:

 GET /*.tcl

When the mapspec is used as three element list, the last argument is the context filter, containing a request header-field and a value for matching. The pseudo request header-field "X-NS-ip" is used for mapping requests from a certain IP address of from an IP range (in CIDR notation). In reverse proxy mode, the client IP address is taken form the value as provided by the reverse proxy server.

Examples:

 ns_server -pool bots map "GET /* {user-agent *bot*}"
 ns_server -pool bots map "GET /* {user-agent *crawl*}"
 ns_server -pool bots map "GET /* {user-agent *baidu*}"
 ns_server -pool bots map "GET /* {X-NS-ip 2a03:2880::/29}"
 
 ns_server -pool local map "GET /* {X-NS-ip 127.0.0.1}"
 ns_server -pool local map "GET /* {X-NS-ip 137.208.1.0/16}"

EXAMPLES

The following example shows, how dynamic connection pool mapping can be implemented based on the "partialtimes" of a request: When a request is taking longer than a certain threshold, the combination of HTTP method and request path (the mapspec) is mapped dynamically to a pool named "slow". As a consequence later requests with the same HTTP method and path will be served from this connection pool.

 ns_register_trace GET /* {
    set pt [ns_conn partialtimes]
    set req [list [ns_conn method] [ns_conn url]]
    set ctime [expr {[dict get $pt runtime] + [dict get $pt filtertime]}]
    if {$ctime > 3.0 && [ns_server mapped $req] eq ""} {
       ns_server -pool slow map -noinherit $req
    }
 }

The connection thread pools can be defined as usual in the config file:

 ns_section "ns/server/${server}/pools" {
    ns_param fast "Fast lane pool"
    ns_param slow "Slow lane pool"
    ns_param bots "Bot pool"
 }
 
 ns_section "ns/server/${server}/pool/fast" {
    ns_param minthreads 4
    ns_param maxthreads 4
    ns_param rejectoverrun true
    ns_param map "GET /*.png"
    ns_param map "GET /*.jpg"
    ns_param map "GET /*.pdf"
 }
 
 ns_section "ns/server/${server}/pool/slow" {
    ns_param minthreads 5
    ns_param maxthreads 15
    ns_param maxconnections 200
    ns_param rejectoverrun true
 }
ns_section "ns/server/${server}/pool/bots" {
    ns_param   map "GET  /* {user-agent *bot*}"
    ns_param   map "GET  /* {user-agent *rawl*}"
    ns_param   map "GET  /* {user-agent *pider*}"
    ns_param   map "GET  /* {user-agent *baidu*}"
    ns_param   minthreads 2
    ns_param   maxthreads 2
    ns_param   rejectoverrun true
    ns_param   poolratelimit 1000    ;# 0; limit rate for pool to this amount (KB/s); 0 means unlimited
}

You might query a certain mapping at runtime:

 % ns_server mapped "GET /images/logo.png"
 fast

Mapping with context constraints can also be provided in the configuration file. We extend the example above by adding a bot pool.

 ns_section "ns/server/${server}/pools" {
    ns_param fast "Fast lane pool"
    ns_param slow "Slow lane pool"
    ns_param bots "Bot pool"
 }
 #
 # ...
 #
 ns_section "ns/server/${server}/pool/bots" {
    ns_param map "GET  /* {user-agent *bot*}"
    ns_param map "GET  /* {user-agent *rawl*}"
    ns_param map "GET  /* {user-agent *pider*}"
    ns_param map "GET  /* {user-agent *baidu*}"
    ns_param minthreads 2
    ns_param maxthreads 2
    ns_param rejectoverrun true
    ns_param poolratelimit 1000    ;# limit rate for pool to this amount (KB/s)
}

See Also

ns_conn, ns_register

Keywords

configuration, connection thread pools, pagedir, pools, reverseproxy, server built-in, tuning