 robwant
|
|
Total Posts: 3 |
Joined: Jul 2022 |
|
|
What are the most efficient and low-latency approaches for sharing data between threads in a C++ system, and why? My primary concern is minimizing latency and maximizing performance, as I have two threads that are each pinned to their own core: a thread that builds an orderbook snapshot and a thread that reads the snapshot object. I am considering using a lock-free queue with a size of just under 3 and either putting the snapshot object into the queue or passing a pointer to it. Another option mentioned to me was using a WAMP router to publish and subscribe to orderbook data and persist it in a LMDB database that is shared via memory mapping of database files. Are there any other options to consider, and what are the trade-offs and benefits of each approach in terms of latency and performance?
for those who dont have an idea regarding what an orderbook snapshot is :
class OrderbookSnapshot { public: OrderbookSnapshot(); OrderbookSnapshot(std::array bids, std::array asks);
std::array get_bids() const; std::array get_asks() const;
private: std::array bids_; std::array asks_; }; This is what i want to share between the two threads. |
|
|
|
 radikal
|
|
Total Posts: 267 |
Joined: Dec 2012 |
|
|
For these things, I'd really recommend using some benchmarking to test.
Generally, lock free queues with just copying the entire structs is relatively high performance. Typically, the cache hits justify the extra memcopying. |
There are no surprising facts, only models that are surprised by facts |
|