quill
quill copied to clipboard
Good ideas for queue
Hi,
I have been using quill and it works well for my use case. I just wanted to share another implementation of SPSC queue which I found interesting.
https://github.com/rigtorp/SPSCQueue https://rigtorp.se/ringbuffer/
Please feel free to close this issue.
Also, it will be a good idea to add raw memcpy to benchmark. This will give us a lower limit of how fast a logger can be.
Hello,
Thanks for sharing and for using quill.
There are multiple ways to implement a SPSC queue.
Also when designing the queue it boils down to mainly two options :
a) a single typed queue where you specify the type as part of the queue e.g. queue<int>
b) a variant queue where you do not specify the type of object you are pushing, instead you just reserve and write to a number of bytes in a queue and therefore you can write any object, but you also need to know how to retrieve that object later.
One possible implementation of a single typed queue is the rigtorp one above. However, a single typed queue would not work well for a logger. The logger does not know in advance what types the user will be logging. Also you don't want to wrap/group multiple potential types in a union or reserve a max slot size per message (which the single typed queue requires) as it would take unnecessarily a lot of space.
I am not suggesting you to use rigtorp one above. I really like the idea used to avoid false sharing. It gave writer_index and reader_index, it's own cache line. Also, it created a copy of writer index and reader index so that each core can cache those index values. It may be possible to borrow those ideas from that implementation. This will help improve workload when reader is lagging behind writer a lot.
A local cache for the consumer was added in #196