quill icon indicating copy to clipboard operation
quill copied to clipboard

Good ideas for queue

Open alphanso opened this issue 1 year ago • 3 comments

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.

alphanso avatar Aug 10 '22 10:08 alphanso

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.

alphanso avatar Aug 10 '22 10:08 alphanso

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.

odygrd avatar Aug 16 '22 00:08 odygrd

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.

alphanso avatar Aug 17 '22 04:08 alphanso

A local cache for the consumer was added in #196

odygrd avatar Oct 26 '22 11:10 odygrd