Limits
Each request runs under limits for memory and processor time. Novis has a default for both, and you
can change them in nvs.toml. A request that goes over a limit stops, and the other requests keep
running.
The default limits
Section titled “The default limits”When nvs.toml does not set a limit, Novis uses these values:
| Key | Default |
|---|---|
memory |
128M for every program |
cpu_time |
30s for a request, a WebSocket or SSE connection, a scheduled script and a queued job |
wall_time, max_output, max_tasks |
no limit |
On a WebSocket or SSE connection, cpu_time limits each turn. A turn ends when the handler waits for
its next message or sleeps. The CPU count then starts again at zero.
A command-line program has no cpu_time limit by default. This is true for nvs run, a
#[Command] method and nvs test. A command-line program still has the 128M memory limit.
false removes a limit:
[limits]memory = falseRaise a limit in nvs.toml
Section titled “Raise a limit in nvs.toml”A request cannot raise its own limit unless nvs.toml allows it. To give every request more, write
the new value in [limits]:
[limits]memory = "256M"cpu_time = "60s"A starting value and a maximum
Section titled “A starting value and a maximum”[limits] is what each request starts with. [limits.hard] is the maximum: the most a request may
raise itself to. When [limits.hard] does not set a key, the maximum is the value in [limits]. A
request can then lower that limit, but it cannot raise it.
A command-line program is different. When [limits.hard] does not set memory, it may raise its
own memory limit with Core\Config::set('memory', ...). It starts at 128M.
This is the nvs.toml for the program below:
[limits]memory = "64M"cpu_time = "5s"
[limits.hard]memory = "256M"cpu_time = "30s"Most requests are small, so keep the starting value low. A request that builds a large report raises its own limit:
<?nvs// This program reads its memory limit and raises it for one large report.echo 'start: ', Core\Config::get('memory'), "\n";
// `Core\Config::set` returns `true` when the new value is below the ceiling.echo '128M: ', Core\Config::set('memory', '128M') ? 'ok' : 'not allowed', "\n";
// 1G is above the ceiling of 256M, so the result is `false`.echo '1G: ', Core\Config::set('memory', '1G') ? 'ok' : 'not allowed', "\n";echo 'now: ', Core\Config::get('memory'), "\n";start: 64M128M: ok1G: not allowednow: 128MCore\Config::set returns false for a value above the maximum, and the limit stays the same.
A request may change only some limits. The page of
Core\Config::set lists them.
The limits
Section titled “The limits”| Key | What it limits |
|---|---|
memory |
the memory one request may use |
cpu_time |
the processor time one request may use; time spent waiting for a database is not counted |
wall_time |
the time from the start of the request to the end, waiting included |
max_output |
the size of the response |
max_tasks |
how many tasks one request may run at the same time |
wall_time limits how long a client waits. cpu_time stops a loop that never ends, but not a
request that waits for a slow query.
Memory and the number of requests
Section titled “Memory and the number of requests”The server starts a new request only when its memory has room for it. It takes the memory of the
machine and keeps 128M for itself. In a container, the server uses the memory limit of the
container.
Then it counts the memory that the running requests use now. A new request starts when that memory,
plus the memory limit of one request, fits in the rest. When [limits.hard] memory is set, the
server uses that value as the limit of one request. When no request is running, a request always
starts. A request that cannot start gets the status 503.
The memory limit is the most memory one request may use. Most requests use much less. A request that waits for a slow query uses a few kilobytes, so many such requests can wait at the same time.
If the running requests together grow past the rest of the memory, the server stops the request that grew. Its error says that the server’s memory is full. The other requests keep running.
[server] max_in_flight is a second limit. It is the most requests that may run at the same time.
When a request goes over
Section titled “When a request goes over”The request stops at once. This is not an exception, so no catch block runs. The server writes
FATAL: and the reason to its log. The client keeps the part of the response that was already sent.
Do and don’t
Section titled “Do and don’t”- Do set
wall_timefor every server. It has no default, so a request that waits for a slow service has no time limit. - Do set a maximum in
[limits.hard]when a request needs to raise its own limit. - Do raise a limit in the one request that needs it, with
Core\Config::set. - Don’t raise the starting value for every request because one page needs more. Each request then uses more memory, and fewer requests run at the same time.
- Don’t catch a limit as an error. Make the work smaller, or raise the limit before you start it.
Read more in Syntax: limits and Reference: limits.
