Added Unsafe Methods for Group Processing#2
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.