Skip to main content

Resource limits and cancellation ownership

Use limits at several layers. Asyncara-managed native memory, PHP's allocator, external libraries, kernel buffers and child processes are different budgets. A single memory limit cannot truthfully cover all of them.

use Asyncara\Runtime;
Runtime::configure([
'taskLimit' => 10000,
'futureLimit' => 20000,
'nativeMemoryLimit' => 128 * 1024 * 1024,
'httpMaxConnections' => 64,
'httpMaxHostConnections' => 8,
]);

Configure before starting a Scheduler. Task/Future admission failures are explicit; they do not silently drop work. Choose capacity from peak simultaneous operations, not total lifetime request count. The native memory ledger does not include all libcurl, OpenSSL, libpq, Connector/C or SQLite allocations.

LayerCapacity policyApplication action
Queue / producer streamBlock producer when fullAwait admission; close abandoned streams
Tasks / Futures / managed allocationsReject with capacity/errorBound submission and handle overload
ConnectionPoolBounded connections and queued acquisitionsKeep leases short; do not leak borrowers
Redis / PostgreSQL notificationsBounded count and bytes; fail on overflowConsume promptly; use durable messaging when needed
HTTP / WebSocket bodiesBounded buffers/messagesStream large data; respect chunk/message limits
ProcessPoolBounded jobs, IPC bytes and workersBack off on admission and configure OS limits

A waiter is not always the operation owner​

Future::await($token) cancels that wait without automatically destroying a shared operation. Async::await($future) is the stronger owning await form: it cancels/joins its unfinished operation on exit. A Task's cancellation token is cooperative. Database cancellation does not prove remote acknowledgement; file cancellation does not undo a write; HTTP cancellation cannot retract sent bytes.

Resource-bearing objects generally reject cloning and serialization. Assignment shares the same PHP object, not an independently owned descriptor. Close resources in finally and await asynchronous close where required. Normal request shutdown drains/cancels native ownership, but SIGKILL, OOM termination and host failure cannot promise application-level cleanup or remote rollback.

Deployment budgets​

Set PHP memory_limit, process/container limits, descriptor limits, connection limits and request-body limits consistently. A multiworker App multiplies per-process pools and memory. Monitor memory and descriptor trends after application warmup and completed-request cleanup. Use diagnostics to inspect backend and pending work; diagnostic coverage is intentionally bounded.