-
Notifications
You must be signed in to change notification settings - Fork 51
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
synchronous file output sink #25
base: master
Are you sure you want to change the base?
Conversation
Synchronous (blocking) file output sink for Windows / *nix. WIP, only compile-tested
Creates multiple threads that send messages to the synchronous file output sink.
There seems to be no point in using POSIX open+write; using fwrite takes less code and can be marginally faster.
Wrong CreateFile flags
Not checking for thread completion properly; needs INFINITE timeout not 0 !
Hi, thanks for working on this. I'll need some to go through this, but here initial thoughts after quick look:
|
Thanks for the quick review.
I thought that was exactly what I did ? i.e. I didn't touch zf_log.c ; to use the extra output sink one just needs to include the additional .h file and make sure to enable the right option at compile-time. But, at this stage it's pretty easy to change things so, whatever you prefer.
I'm not sure if I understand what you mean by this; that would require modifying zf_log.c ? I looked briefly and decided not to touch it , since it's structured to use one global sink and I just want along with that model.
I agree but I disagree. The mutex makes this robust on any kind of OS and load scenario with no possible doubt; there's just no real disadvantage. I'm sure the eventual performance bottleneck would be the OS write back-end, not the mutex overhead. If it somehow was a problem anyway, atomic primitives could be used instead. |
I was talking about having a separate library target, instead of inserting new code into existing
No. It's just a different interface for a code you wrote. In your patch you initialize
Any OS that requires this mutex to work correctly is broken. Such OS must be addressed specifically, instead of making everybody else slower. To my current knowledge, all major OSes behave correctly.
Problem is not with overhead, but with the fact that one thread will be waiting while other is writing. Many OSes already has such mutex in much better place with clever optimization around it so on quick pass nobody waits. It's redundant. |
WriteFile docs say
to me, that alone is enough justification to keep the mutex in there, because I don't want to assume / guess that it will work as expected. In POSIX, fwrite() is "AS-unsafe" - same situation. Even though testing ( https://www.notthewizard.com/2014/06/17/are-files-appends-really-atomic/ ) shows that indeed it can be atomic up to 4K chunks, and arguably log entries will not be that long, that's not my point. If there's no way to guarantee or verify async safety, the mutex stays.
Hmm, so multiple librairies are produced ? If the sinks just contain setup functions and callbacks (and no dependency / calls to zf_log.c core funcs), I guess that could work yes. My use case is to statically link against it so either way doesn't matter. The code is so small that I would see no point in having a system-wide lib.
Agreed... I remember having had some problems with that, but now I don't remember why or what... arg PS, unrelated: I think zf_log.c could be split into smaller pieces; for instance a lot of the #defines could go in a private .h file. I'm thinking of the PP* and ZF_LOG_MESSAGE_FORMAT* macros in particular |
As mentioned in #9 , here's a sync file output callback with both native Win* and unix/linux implementations.
Also includes a multi-threaded example, also for Win / *nix. I didn't integrate it in the test suite because I wasn't sure how.
Implementation notes :
I can rebase / squash the commits if required.