NaviServer - programmable web server

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

# ns_writer(n) 4.99.8 naviserver "NaviServer Built-in Commands"

## Name

ns_writer - Manage files with writer thread

## Table Of Contents

## Synopsis

- ns_writer list ?-server s?
- ns_writer submit data
- ns_writer submitfile ?-headers? ?-offset offset? ?-size size? file
- ns_writer size driver ?value?
- ns_writer streaming driver ?value?

## Description

This command allows to submit data or file to be returned to the client connection using writer thread instead of current connection thread. Writer thread processes multiple sockets using async socket operations which consumes less resources than returning multiple files to the slow clients in separate thread.

## COMMANDS

ns_writer list ?-server s?

  Returns list of all currently submitted files. Every list entry contains the start time of the initiating request, name of the thread, driver, the ip-address of the requestor, the file descriptor, the remaining size and the bytes already sent, and the client data as provided via [ns_conn clientdata]. If -server is specified, only the submitted file entries from the specified server are returned.

ns_writer submit data

  Submit arbitrary data to be returned via writer thread, data can be binary.

ns_writer submitfile ?-headers? ?-offset offset? ?-size size? file

  Submits file to be returned via writer thread. For parital requests, ns_writer does NOT change status code or sets content-range. Optionally the following arguments can be used:

  -headers Tells the writer to provide required HTTP headers, like content size, type and status.

  -offset If specified, file will be returned starting with this offset.

  -size If not specified, the whole file will be retuned, otherwise only given part. Can be combined with -offset.

ns_writer size driver ?value?

  Query or set configuration parameter writersize of the writer(s) of the specified driver.

ns_writer streaming driver ?value?

  Query or set configuration parameter writerstreaming of the writer(s) of the specified driver.

## CONFIGURATION

Basic configuration options:

ns_section "ns/server/default/module/nssock"
ns_param writerthreads 1
ns_param writersize 4096
ns_param writerstreaming true

writerthreads parameter specified how many writer threads will be used, multiple threads will be rotated to spread the load across all threads

writersize specifies the minimal size of the file to be considered for writer thread, this parameter is used by connection thread when returning file and if size exceeds configured value, file will be returned via writer thread and connection thread will be released to handle other requests.

writerstreaming specifies whether or not streaming HTML output (e.g. sent via ns_write) should be sent via the writer. When sending server responses over slow connections, this option reduces the blocking time of the connection threads and can therfore reduce the damage of slow-read attacks.

## EXAMPLES

    ns_writer submitfile /tmp/biglist.txt

## See Also

ns_conn, ns_returnfile, ns_write

## Keywords

configuration, writer