[deferred]
deferred.max_concurrent
How many requests one core keeps open at a time for work that runs after the response is sent.
Sending an invoice, filling a cache or writing an audit row can run after the response. The person waiting then gets the response first. The request is not finished yet, and it keeps all the memory it was using. Without a limit, many such requests at once could use all the memory of a core.
The limit counts requests, not pieces of work. A request that adds ten functions counts once. When the limit is reached, Core\Task::runAfterResponse throws an error in the request that called it. That request is still running, so it can do the work itself. Nothing is put in a queue.
Only nvs.toml sets this value. A program may read it, but it cannot change it.
Only nvs.toml sets this key. A request may not change it.
A change in the file takes effect a few seconds after you save it. The server does not restart.
The examples below run with this configuration file.
# Each core runs the after-response work of at most 256 requests at once.[deferred]max_concurrent = 256
# A program may raise its own memory limit up to 512M.[limits.hard]memory = "512M"How much after response work a core holds
<?nvs// Work that runs after the response is sent keeps its request open a little longer.// `[deferred] max_concurrent` is how many of those requests one core keeps at one time.// This file sets it://// [deferred]// max_concurrent = 256
echo 'requests held per core: ', Core\Config::get('deferred.max_concurrent') ?? '(no value)', "\n";
// A waiting request keeps its memory, up to `limits.hard.memory`.// The `nvs.toml` beside this program sets it to `512M`, so this prints `512M`.echo 'each may hold up to: ', Core\Config::get('limits.hard.memory') ?? '(nothing)', "\n";
// The right limit depends on the size of the machine. A program may read it but not// change it. `Core\Config::set` returns `false`, so this prints `no`.string $name = 'deferred.max_concurrent';echo 'raise it from code: ', Core\Config::set($name, '4096') ? 'yes' : 'no', "\n";
// `Core\Task::runAfterResponse` runs this function after the response is sent. At the limit, it// throws an error, and the request can do the work itself.Core\Task::runAfterResponse(fn(): void => { echo "and the work itself runs once the answer is on its way\n";});
echo "answered\n";requests held per core: 256each may hold up to: 512Mraise it from code: noansweredand the work itself runs once the answer is on its wayChangelog
| Version | Change |
|---|---|
0.0.6 | The page of each setting says whether a request may change it with Core\Config::set. A page for a block lists the settings in it that a request may change. |
deferred.deadline
[deferred] deadline is the time limit of work that runs after the response is sent.
Core\Task::runAfterResponse runs a function after the response has been sent. Sending an email or writing an audit record is work of this kind. Each call to runAfterResponse may give its own deadline. A call that does not give one gets the value of this key. When this key is not written, such a call has no deadline.
A request may change this key for itself with Core\Config::set. [deferred] max_concurrent is in the same block, and only nvs.toml sets it. So a program can change its own deadline. It cannot change how many requests may have work waiting at the same time.
nvs.toml sets the value that each request starts with. A request may change its own value with Core\Config::set, up to the ceiling where the key has one.
A change in the file takes effect a few seconds after you save it. The server does not restart.
How long after response work may take
<?nvs// Work that runs after the response is sent has a deadline. `[deferred] deadline` is// the deadline when a call does not give its own. This file sets nothing, so the// built-in default is used. It is the same as this block://// [deferred]// deadline = "30s"
echo 'written here: ', Core\Config::get('deferred.deadline') ?? '(nothing, so the built-in default)', "\n";
// Your program may change this setting while it runs. Most settings do not allow that.// A job with quick work can set a shorter deadline, so this prints `yes`.echo 'give it 5s: ', Core\Config::set('deferred.deadline', '5s') ? 'yes' : 'no', "\n";echo 'now in force: ', Core\Config::get('deferred.deadline') ?? '(nothing)', "\n";
// `max_concurrent` is how many requests each core keeps open for this work at one time.// It depends on the size of the machine, so a program cannot change it. This prints `no`.string $cap = 'deferred.max_concurrent';echo 'raise the cap: ', Core\Config::set($cap, '4096') ? 'yes' : 'no', "\n";
// `Core\Config::restore` deletes the value this program set. `get` then returns the value// from the configuration file. This file sets nothing, so `get` returns `null`.Core\Config::restore('deferred.deadline');echo 'restored to: ', Core\Config::get('deferred.deadline') ?? '(nothing, so the built-in default)', "\n";written here: (nothing, so the built-in default)give it 5s: yesnow in force: 5sraise the cap: norestored to: (nothing, so the built-in default)Changelog
| Version | Change |
|---|---|
0.0.6 | The page of each setting says whether a request may change it with Core\Config::set. A page for a block lists the settings in it that a request may change. |
