-
-
Notifications
You must be signed in to change notification settings - Fork 172
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
Would like to add file appender since spit appender takes more time #174
Comments
Hi there, PR welcome if you have a specific strategy in mind that'd help. Please keep in mind that it wouldn't be feasible to just keep the file permanently open as in your benchmark above. |
Thank you. Let me start work on this. My approach would be as follows
|
This is going to be the difficult one. How will you know when "logging has stopped"? The only obvious approach I can think of is to open the file, and start a recurring timer that checks every That'd work, but would involve more moving parts than I think this warrants. Keep in mind that even the current implementation can write 1000 lines in ~20ms. And if one needed more for bursting, there's the In any case, happy to take a look at a PR if you feel you have a reasonable solution in mind. Cheers! :-) |
The approach i described needs a function like taoensso.timbre/stop!. It will be a hook to release any resources held by appenders. I quickly looked at the logback manual, it has a method "stop" to release the resources.
|
When would the stop fn be called, and by whom? |
Generally it should be called when the web server is down through ServletContextListener#contextDestroyed. For standalone program, we need to call it manually. Another approach is adding shutdownhook to Runtime class. |
I'll be honest, I'm not very keen on adopting a new manual shutdown process just for this. For one, the level of complexity would be even greater than the timeout approach I described above and discounted for being unnecessarily complex. Before we continue; may I ask if it's a real requirement that you write >1000 entries per second on one device? We can make this go faster, but it's simple as it is and usually fast enough; is this really a bottleneck in a real-world application? |
Thank you for your reply. No, i don't have any real requirement. While I was reading timbre logging code base, I happened to see "spit" function used for file writing. It looked different to me as other logging framework like log4j and logback deals with file writing differently. Then I just wanted to know how much time difference it would be "spit" and "open-file-once" approach. The difference was approximately 50%. That is where all these things started. |
Okay, gotcha - thanks for clarifying. Opening and closing on each write is much slower than holding the file open. But the absolute cost is relatively insignificant either way in most cases, especially for a couple-line little appender that no one would really want to use for a major deployment anyway. If you've got an application that's putting out more than 40k log entries per second, in all likelihood you're anyway going to want to be writing to a proper DB or other software that's going to manage stuff like flushing, rotations, etc. This little appender's mostly just for simple applications that don't do an awful lot of logging. Like I say, we can certainly make if faster - but the cost would be extra complexity and engineering time - which I think probably wouldn't be worth it in this case. Does that make sense / seem reasonable? |
IMHO, Big applications are relying on logs first. Generally Each server I am ok with "spit" approach for smaller applications. But, Don't you have Thanks Again. On Fri, Jul 1, 2016 at 4:31 PM, Peter Taoussanis [email protected]
|
Timbre's well suited to large applications. This particular appender is described as a "simple More sophisticated users will want to use a different appender that fits their particular needs and environment. In most cases that'll mean an appender that coordinates with a robust, external logging system. Timbre's primary job is as a dispatcher; i.e. to interface between Clojure code and your logging targets. Appenders are the glue in this scenario; and the more sophisticated your needs, the more likely you're going to want a custom appender. They're just functions, and not hard to write - that Timbre comes out-the-box with any appenders at all, is mostly for convenience. Since the motivations behind this issue are hypothetical and I'm juggling a lot of urgent work atm, unfortunately going to need to bow out of further correspondence on this. Please feel free to close if you're satisfied. Otherwise always happy to take a look at a specific PR/s if you'd like to submit. If you do feel like exploring this further, I'd encourage you to really consider what the full range of approaches might be to something like this and what their tradeoffs are. Cheers! :-) |
I agree with there is no much can be done on small "spit" appender. But if we need to include better appender for the heavy logging use case, there is some support needed from timbre library side like "shutdownHook". Without such support, appender has no way to know when it can close / free the resources. We can have a timer approach, But still we need to know when the timer can be stopped. |
Sent a pull request Please review and let me know your feedback. |
Sure. Please note that it may take me a week or more to get back to you, have my hands pretty full atm. |
Thank you for the prompt reply |
No problem, thanks for the PR :-) |
Discussion at #181. |
Hi,
"spit-appender" opens and closes the file for each log message. so does "rolling-appender". Frequent opening and closing of a log file consumes more time, than writing messages into the file.
Do we have any efficient file appender for timbre logging library or do we need to write one? i am interested to write such one.
I just tested this use case with below code. I see spit-appender consumes 800 ms and "opening-file-once" approach consumes 20 ms approximately.
Thanks.
The text was updated successfully, but these errors were encountered: