Skip to content
Role Pair Selection

Role-pair selection

The fastest way to pick a SubEtha primitive: find the row whose role pair matches your shape, take the type, move on. The shape - who-talks-to-who - is what determines the primitive. Strategy adaptation is a secondary axis the sidecar handles via the AdaptiveIpc<T> umbrella, which auto-picks among the specialized primitives below based on declarative workload hints.

Cross-process MMF primitives

Use these when the two ends are in different address spaces, or when one end is “the same process tomorrow after a restart”. The data lives in a memory-mapped file; the kernel page-aliases the mapping between participants and there is no kernel on the data path after construction.

The Python package and the PowerShell module name each structure the same way: subetha.HashMap in Python is SubEtha.HashMap in PowerShell, made by New-SubEthaHashMap.

Role pairPrimitivePython / PowerShell
producer + consumer (lock-free MPMC)SharedRingRing, the adaptive ring, which takes the SPSC, MPSC or MPMC shape its peers need
single-producer + N consumers (fan-out)SharedBroadcastRingBroadcastRing
LIFO stackSharedTreiberStackStack
shared mutable cellSharedCellCell
one-shot initSharedOnceCellLazyValue
atomic wordSharedAtomicU32, SharedAtomicU64, SharedAtomicBoolAtomic, 64 bits
key/value lookupSharedHashMapHashMap
LRU cache (bounded, eviction)SharedLRUCacheLruCache
mutual exclusion (reader/writer)SharedRWLockRWLock
counting semaphoreSharedSemaphoreSemaphore
rate limit (token bucket)SharedRateLimiterRateLimiter
logical clock (Lamport / hybrid)SharedFenceClockFenceClock

Several primitives sit on the same role-pair shape but tune for a specific data layout:

TypeSame role-pair asSpecializationPython / PowerShell
SharedBTreeMapSharedHashMapordered keys, range queriesBTreeMap
SharedLinkedListSharedTreiberStackdoubly linked, both-end opsLinkedList
SharedVecSharedRingindexed array, random accessVec
SharedRegion(allocator role pair)sub-allocator inside the MMFRegion

Sketches and probabilistic structures - SharedBloomFilter, SharedCountMinSketch, SharedHyperLogLog, SharedReservoirSampler, SharedHistogram - share the “insert + query” role pair of SharedHashMap but trade exactness for fixed-size footprint. From Python and PowerShell they are BloomFilter, CountMinSketch, HyperLogLog, Reservoir and Histogram.

Work-stealing deques (producer + consumer family)

Several deque variants exist because the workload shape inside “producer + consumer” splits further: batched producers want one shape, work-stealing thieves want another, broadcast fan-out wants a third.

VariantShape that fits
SharedDequeChase-Lev baseline (owner-pop, thief-steal)
SharedDequeKhlKHL - work stealing with per-slot publication radius
SharedDequeKhpdKHPD - publication-line batched fan-out
SharedDequeLohLOH - LIFO cache + LCRQ steal slow path
SharedDequeUrdURD - per-thief mailbox; explicit consumer set
SharedDequeFclFCL - flat combining for high contention

AutoIpc::build_work_steal_queue() with declarative hints (.batch_size, .consumers, .idle_wait) picks among these without the caller naming a variant.

From Python and PowerShell, Deque (an owner and its thieves) and the front door’s WorkQueue carry this role pair; the named variants are Rust’s.

Coordination primitives

The shapes here are not the canonical reader/writer or producer/consumer; they coordinate liveness, ownership, or fan-out across the participants.

Role pairPrimitivePython / PowerShell
liveness signal across processesHeartbeatTable, SharedLeaderElectionHeartbeat, LeaderElection
owner of a resource + lease holdersOwnerLeaseOwnerLease
epoch barrier (all participants synchronize)EpochBarrierEpochBarrier
failover (work reassignment on dead peer)FailoverWatchdognot bound
priority fan-outPriorityFanoutnot bound
event log (emit + drain + fold)EventStateLognot bound
version chain (append-only history)SharedVersionedChainVersionChain
time-keyed slot tileSharedTimePointTileTimePointTile
topology mapping (fan-in / fan-out routing)SharedTopologyMapTopologyMap
named handle table (transient identifiers)SharedHandleTableHandleTable
dependency graph (nodes + edges)SharedGraphGraph
async pointer (deferred resolution)SharedAsyncPointernot bound

What to do once you have picked one

  • For a direct cross-process primitive: open or create the MMF via create(path, capacity) or open(path, capacity), then call the primitive’s regular methods; from Python, the class’s constructor and its open, and from PowerShell its New- and Open- cmdlets. See the cross-process tutorial .
  • For automatic primitive selection: use AutoIpc::new(path) and declare workload hints; the builder picks the best primitive among the table above. See AdaptiveIpc<T> . From Python and PowerShell the front door’s AdaptiveQueue picks a shape from the traffic it sees.
  • For a custom policy: implement the Policy trait, build an instance whose make_policy returns your impl, and let the sidecar consult it on each scan; from Python and PowerShell, pass a callable or a ScriptBlock to an object’s observe. See Write a custom Policy .

See also