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
newFastLogger1 ensures the ordering of logs #207
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Your solution looks sound to me. Thanks for that fix!
writer buffd@BufFD{..} tvar ref mvar = loop (0 :: Int) | ||
where | ||
loop cnt = do | ||
cnt' <- atomically $ do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm wondering if you're already using TVar
for spin-waiting, wouldn't it be easier to just use TQueue
and a poison pill instead of TVar
, IORef
and get rid of MVar
for signalling shutdown?
P.S. It took me a while to decipher the meaning of tvar
, ref
, mvar
. Maybe it would be a good idea to use more meaningful names?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
STM is heavier than atomicModifyIORef'
.
In this design, STM transactions run only when the builder reaches the limit.
Yes, MVar Buffer
is not necessary. I should think whether or not we can remove it from SingleLogger
easily.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I looked at SingleLogger
and it looks good.
@carbolymer @khibino Now |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Merged. I will release a new major version! |
Released! |
@carbolymer @khibino This should fix #203.
The old logic cannot ensure the ordering of logs even if the number of internal builders are 1.
This PR calls the old one
MultiLogger
and introduces a new one calledSingleLogger
.SingleLogger
uses a queue of builder in addition to an internal builder.The internal builder gets empty and the queue glows atomically.
The builders of the queue are written by a single dedicated thread, thus the ordering is maintained.
A test case is also provided.