Urgent.News

What's breaking now, across thousands of outlets.

Tech

Why a Lock‑Free Ring Buffer Beats Mutex Queues in a 200 kRPS Rust Service

In a telemetry ingest service we were hitting 200 k requests per second on a single 8‑core box. The naive design used a Mutex<VecDeque<T>> shared between the async dispatcher and a pool of worker threads. Under load the mutex became a hotspot, inflating tail latency and causing occasional lock‑starvation spikes. The Bottleneck A Mutex serializes all access, even when threads are only reading the…

In a telemetry ingest service, engineers observed the system processing 200,000 requests per second on an 8‑core machine. Initially, the design utilized a Mutex VecDeque shared between the async dispatcher and a group of worker threads. However, the mutex proved to be a bottleneck, as its serialization of all queue access exacerbated tail latency and led to occasional lock‑starvation.

The synchronization overhead caused the lock function to consume about 12% of total CPU cycles, vastly outweighing the actual message‑processing work.

Desperate to alleviate the performance hit, the team switched to a lock‑free ring buffer employing atomic indices. This new structure allows the producer to claim a slot by atomically incrementing a head counter, while the consumer reads from a tail counter. By fixing the buffer size and using relaxed ordering for data payloads with acquire/release semantics only on the indices, cache‑line ping‑pong is eliminated. The implementation is constrained within a single cache line per index, thereby minimizing contention.

Benchmarks on the same hardware demonstrated that switching to the lock‑free ring buffer reduced per‑request latency from 1.8 milliseconds to just 0.6 milliseconds, and also eliminated the periodic spikes in latency caused by lock contention. However, the trade‑offs include the necessity of sizing the buffer correctly to handle burst traffic, using UnsafeCell to bypass Rust’s aliasing rules, guarding against false sharing when the buffer size isn’t a power of two, and acknowledging that the performance gains are more pronounced in CPU‑bound workloads.

In summary, eliminating the mutex in favor of a lock‑free ring buffer significantly lowered latency and provided a more predictable latency profile. This case illustrates the advantages of lock‑free designs in environments where synchronization overhead dominates. Reporters are invited to share their experiences handling high‑throughput queuing in Rust or other systems—whether they favor lock‑free structures, bounded channels, or a hybrid approach.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

7 Open-Source Figma Alternatives for UI Design and Prototyping

Looking for an open-source alternative to Figma? Figma is widely used for UI design, prototyping, and collaboration, but it isn't the only option for creating digital designs.

  • Open Design uses AI agents for visual asset creation and prototyping
  • Penpot closely resembles Figma with vector-based design and prototyping
  • Graphite offers node-based procedural editing for graphics and motion graphics

Hreflang: The Audit That Stops Your Pages Fighting Across Countries

I work at SEOSage, which builds desktop SEO audit software. The steps below work with any crawler. The wrong version of your page is ranking somewhere right now.

  • Incorrect hreflang tags cause pages to rank in wrong locations or cannibalize traffic.
  • Lack of reciprocal links makes Google ignore hreflang tags without reciprocity.
  • Fix hreflang errors by clusters instead of individual tags for root cause resolution.

What Happens to Your PDF When You Open It in a Browser? PDFdepth.com

PDFs are everywhere in software development. They're used for invoices, reports, contracts, technical documentation, forms, and much more.

  • PDFs can be processed locally, server-side, or hybridly in web applications.
  • Hybrid processing balances local and server-side processing for optimal performance and privacy.

More from Tuesday 13 October →