A memory budget for every task
- The problem
- A single runaway task can use up all the memory and bring down the whole program, including the parts that were working fine. In most languages nothing stands in its way. Erlang and Elixir are known for isolating work in this way; Nikaia is specified to do the same.
- An example
- A background task reads a large upload into memory, and keeps reading. Your main application, which was serving requests, runs out of memory with it.
- What Nikaia checks
- Every task gets a memory budget of its own. A task that spends it ends on its own, and the rest of the program, your main application included, runs on. A shared value has a budget of its own too. This is decided and written into the specification. A calculation that runs while the program is built is already bounded in steps and in memory.
- The limit
- The per-task budget is not built yet. Today a task that takes too much memory can still take it from the whole program. Once built, it is a protection while the program runs, not a proof: Nikaia will not show at build time that a task stays within its budget, it makes sure that a task which does not ends with
task::OverBudget, an error like any other, and only that task ends. Memory that a Rust crate or a C library allocates and keeps for itself is in no budget.
Go deeper
More under Very safe: Conflicting actionsTasks that get stuckErrors that go unhandledBroken promises