blackbull.server.affinity¶
blackbull.server.affinity
¶
Worker event-loop CPU placement.
Never widen the inherited affinity mask or pin executor threads to the loop CPU. BB_CPU_PINNING=off must disable placement.
apply_worker_affinity(worker_id, spec)
¶
Pin this thread for worker worker_id; return the mask it had before.
The return value is what make_offload_executor needs — the
placement the operator gave us, which offloaded work should keep even
though the event loop no longer does. None means nothing was pinned
and no executor override is warranted.
make_offload_executor(allowed, max_workers=None)
¶
A thread pool whose threads run on allowed, not on the loop's pin.
A thread that cannot set the mask still runs its work: losing the spread costs throughput, refusing to start the thread costs the request.
resolve_worker_cpus(spec, worker_id, allowed)
¶
CPUs worker worker_id should run on, or None to leave it alone.
allowed is the mask the process already carries — the placement the operator chose. The result is always a subset of it.