-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added Unsafe Methods for Group Processing #2
base: master
Are you sure you want to change the base?
Conversation
Hmm, I can see the usecase, but why not do this with:
That keeps the library simple to use, and helps with the kind of operation you need. |
Well, thats a good point. Doing it. |
* Created LockingFifo to avoid having a mutex locked when not needed * Added Peek call * Added AddList * Added NextN
Ok I added, the NextN can be improved by slicing it though (I left a todo). I also did:
|
Just added travis script for testing with golangci-lint and coveralls based on my logging repo: https://github.com/quan-to/slog Just enable this repo at https://coveralls.io and at travis and it should be good to go. |
Ok just noticed that the default was to be Safe not Unsafe. So I changed the Queue to UnsafeQueue and renamed LockingQueue to Queue. That way the default is safe for Go Routines. |
Can we remove the UnsafeQueue completely? It doesn't seem to add much anymore over the normal Queue? |
I changed a bit the library to be able to do batch processing.
It doesn't change the behavior of the current methods, but I added few:
UnsafeAdd
=> Adds without lockingUnsafeNext
=> Get's next without lockingUnsafeLock
=> LocksUnsafeUnlock
=> UnlocksThat might seens a bit odd, but I have a use case here. Let's suppose I have a routine that needs N samples from the fifo, and other routine that puts V samples into the fifo.
In the current version you would do:
So the thing is that two things happen here:
For sure that won't give any data corruption, but can impact performance due the mutex.lock() / unlock() calls (which are sort of expensive according to pprof). With my changes I can do this:
This way, it will ensure that the loop runs without lock/unlocking the fifo unnecessarily and both operations will write all data that it wants before anyone reading it.
It doesn't impact in any way the current flow of Add / Next, so that is just a new feature I would like to add to the oficial library, since it might be useful depending on the use case.