ns_server - Get state of the server's connection pools and queues
This command provides a way to examine the current server's connection pools and queues. The allowed options (which may be abbreviated) are:
Returns a list of the currently defined filters.
Returns a list of the registered hostnames for this server. This result list can be used as a white-list of configured and therefore secure contents accepted in the host header field of a request.
Returns the path of the virtual server's page directory root.
Returns a list of the pools defined for this server.
Returns a list of the currently defined requestprocs (the registered procs for certain request patterns).
Returns the path of the virtual server's base directory.
Returns the path of the virtual server's private Tcl library.
Returns a list of the currently defined traces.
Returns a list of the mappings from URLs to files.
Returns a Boolean value to indicate whether virtual hosting is enabled for this server. The setting of this value influences e.g. the result of ns_conn location.
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.
Returns the number of connection requests processed by this pool since startup.
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.
Per default, return the connection pool associated with the mapping specification (HTTP method and path). An empty value indicates the default connection pool. When the -all is specified, a dict is returned containing the keys pool and handler indicating the connection pool and the request handler handling this request.
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, not the files below in the subtree.
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.
Query or set the minimum number of connection threads for this server and pool. The value must be between 1 and maxthreads.
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.
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.
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.
Returns a list of attribute value pairs containing information about the number of connection threads for the server and pool.
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.
Returns the number of connections waiting (i.e. queued) to be processed.
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 are defined in the configuration file. In these sections, also the mapping of requests to the pools can be defined with the configuration values map-inherit and map-noinherit. The term map is the short form of map-inherit The specification using map-noinherit corresponds to the -noinherit as described above.
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_param map-noinherit "GET /dotlrn/mt" } 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) }