buffer: Detecting ring buffer overflows?
I’m using a simple ring buffer, as so:
buffer.NewRing(buffer.New(8<<20))
In order to size the ring buffer for my use-case appropriately, I would like to collect some stats on how often it overflows (causing old data to be overwritten). I’m happy to open a PR to this effect, but wanted to discuss a sane API for exposing this information first.
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 15 (15 by maintainers)
Do you have an example of the strange behavior you’re seeing? (out of order data perhaps?) I can try adding some more tests for the RingBuffer, I’ll admit it’s much less battle tested (and more convoluted) than all the other buffers.
I think your log trick is totally fine, if you’d prefer not to modify RingBuffer in your codebase, you can also just copy this buffer below, and drop it anywhere you need a ‘log on overflow buffer’.
You could also detect an arbitrary Buffer is ‘overflowing’ via:
So far I don’t think there’s any need to add this to the buffer package (since it’s main use is debugging and it’s easy to drop in and configure to each individual use case).
Hope that helps! If there is an issue with this package I’ll help fix it fast for you, thanks for using it!
Hey, sounds like a good idea to me. I’m going to be busy with my day job until later today but I’ll be happy to share some ideas here after that.