Stack Queue

License Cargo Documentation

A heapless auto-batching queue featuring deferrable batching by way of negotiating exclusive access over task ranges on thread-owned circular buffers. As tasks continue to be enqueued until batches are bounded and doing so is constant-time and can be deferred until after a database connection has been acquired, this allows for optimal opportunitistic batching without collection overhead and delivers maximum throughput at all workload levels without superfluous timeouts.

Runtime Configuration

By utilizing a barrier to guard thread local data destruction until runtime threads rendezvous during shutdown, it becomes possible to create thread-safe pointers to thread-local data owned by runtime worker threads. In order for async-local to protect thread local data within an async context, the provided barrier-protected Tokio Runtime must be used to ensure tasks never outlive thread local data owned by worker threads. By default, this crate makes no assumptions about the runtime used, and comes with the leaky-context feature flag enabled which prevents Context from ever deallocating by using Box::leak; to avoid this extra indirection, disable leaky-context and configure the runtime using the tokio::main or tokio::test macro with the crate attribute set to async_local with only the barrier-protected-runtime feature flag set on async-local.

Benchmark results // batching 16 tasks

| crossbeam | flume | stack-queue::TaskQueue | stack-queue::BackgroundQueue | tokio::mpsc | |:------------------------|:-------------------------------|:----------------------------------|:----------------------------------------|:------------------------------- | | 1.74 us (✅ 1.00x) | 2.01 us (❌ 1.16x slower) | 974.99 ns (✅ 1.78x faster) | 644.55 ns (🚀 2.69x faster) | 1.96 us (❌ 1.13x slower) |


Stable Usage

This crate conditionally makes use of the nightly only feature typealiasimpltrait to allow async fns in traits to be unboxed. To compile on stable the boxed feature flag can be used to downgrade asynct::asynctrait to asynctrait::async_trait.