cameron314 / cameron314/concurrentqueue

Zero-copy support

Open
#359 4 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C++
Stars
12.5k
Forks
1.9k
PR merge metrics
No merged PRs in 30d

Description

I am willing to use the concurrent queue for a low latency network application. Overall, I need to enqueue network packets on one thread, and decode them in another thread - in practice that would be multiple producers/consumers, but it does not matter here. The queuing is necessary as with high packet rates, decoding synchronously would be too long and start dropping incoming packets.

In pseudo code, that means my flow is roughly:

// Producer
Packet p;
while (true) {
    read(&p); // Read (copy) packet to a temporary stack variable
    q.enqueue(p); // Copy to the queue
} 

// Consumer
Packet p;
while (true) {
    q.dequeue(p); // Copy from the queue to a stack variable
    decode(&p); // Decode from the stack variable
} 

My actual packets are copied all over the place here.

  1. From kernel to userspace with read()
  2. From producer stack to queue
  3. From queue to consumer stack

Now, I am more of a C programmer than C++, so the subtleties of move operations are a bit magical to me, but do I have some way to ensure that p will not be copied upon enqueuing and dequeuing? It seems a bit magical to me.

Also the possible move is only on the producer side, not on the consumer side, as far as I understand.

I would propose an explicit API to handle that case, which splits enqueue and dequeue in two halves. The first half grabs the slot from the queue, and the second half commits the operation.

That would look like:

// Producer
while (true) {
    Packet* p = q.enqueue_stage(); // Grab the slot
    read(p); // Read (copy) the packet directly in the slot
    q.enqueue_commit(p); // Finish the enqueue
} 

// Consumer
while (true) {
    Packet* p = q.dequeue_stage(); // Grab the slot
    decode(p); // Decode the packet directly from the slot
    q.dequeue_commit(); // Finish the dequeue
}

This would allow true (producer + consumer) zero copy behavior, without relying on compiler optimizations.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The issue names no files, tests, or entry points. Start by reviewing the queue’s existing enqueue/dequeue API and the proposed staged operations; done would require a maintainer-approved zero-copy design and validation for producer and consumer use.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
performance
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.