Progressive Chunked Queue for Scalable Multi-Producer Systems
Find Innovative SolutionsGenerate Solutions
Solution Overview
Problem
Multi-producer concurrent queues based on compare-and-swap instructions do not scale with the number of producer threads, leading to poor system performance due to CAS failures and increased latency.
Innovation Solution
Implementing a progressive chunked queue that uses fetch-and-add instructions, allowing multiple producers to make progress independently and reuse memory chunks, while consumers coordinate through epoch sequences to mark slots and recycle memory chunks.
Engineering Contradictions & Design Principles
Engineering Contradiction Analysis
1Reliability
If multi-producer concurrent queues use compare-and-swap instructions, then thread synchronization is achieved, but system performance deteriorates due to CAS failures and increased latency
Solution Approach 1:
The queue is divided into multiple independent memory chunks, each with its own sequence counter. Producer threads operate on different chunks independently, eliminating CAS contention. Each chunk can be processed by any producer thread without coordinating with others, segmenting the critical section and improving parallelism.
Solution Approach 2:
A memory chunk pool acts as an intermediary between producers and consumers. Producers allocate chunks from the pool and write items, while consumers retrieve chunks and consume items. This intermediary structure decouples producers and consumers, allowing independent operation without direct CAS-based synchronization between them.
2Productivity
If multiple producer threads operate on the same queue, then throughput increases, but latency increases due to CAS failures
Solution Approach 1:
The queue is divided into multiple independent memory chunks, each with its own sequence counter. Producer threads operate on different chunks independently, eliminating CAS contention. Each chunk can be processed by any producer thread without coordinating with others, segmenting the critical section and improving parallelism.
Solution Approach 2:
Memory chunks are pre-allocated and initialized with sequence counters before being placed in the pool. This preliminary preparation eliminates the need for runtime allocation and initialization operations that would require synchronization, allowing producers to immediately write items without CAS failures.
3Quantity of substance
If memory chunks are reused by consumers, then memory footprint is reduced, but coordination complexity increases
Solution Approach 1:
A memory chunk pool acts as an intermediary between producers and consumers. Producers allocate chunks from the pool and write items, while consumers retrieve chunks and consume items. This intermediary structure decouples producers and consumers, allowing independent operation without direct CAS-based synchronization between them.
Solution Approach 2:
Each memory chunk contains its own sequence counter and item data, making it a self-contained unit that can be independently allocated, processed, and recycled. Consumers can determine chunk validity by checking the sequence counter without needing complex coordination with producers, enabling self-service operation.
Data Source
AI summary
A method includes receiving, by a producer thread of a plurality of producer threads, an offer request associated with an item. The producer thread increases a sequence and determines (i) a chunk identifier of a memory chunk from a pool of memory chunks and (ii) a first slot position in the memory chunk to offer the item. The producer thread also writes the item into the memory chunk at the first slot position. Then, a first consumer thread of a plurality of consumer threads determines the first slot position of the item and consumes the item at the first slot position. A second consumer thread consumes another item at a second slot position in the memory chunk and recycles the memory chunk.


