qos-ch / logback

The reliable, generic, fast and flexible logging framework for Java.
http://logback.qos.ch
Other
2.97k stars 1.28k forks source link

Don't call file.length() for every append if we can avoid it #790

Open axiak opened 5 months ago

axiak commented 5 months ago

This change introduces a way for the ResiliantFileOutputStream to track its own position in the file. This means that instead of calling File.length() (which ends up being a syscall) for each event, we only call it when we're recovering a stream.

ceki commented 5 months ago

@axiak Hi Michael,

Thank you for this contribution. When you say that File.length() is called for each event, on which execution path do you think this occurs?

griffinjm commented 5 months ago

@axiak Hi Michael,

Thank you for this contribution. When you say that File.length() is called for each event, on which execution path do you think this occurs?

From my read through the file length check occurs only when the rollover check interval is passed. For all standard TriggeringPolicy implementations it is not on every append.

This would be an optimization when checking for rollover if someone has a low rollover check interval. Depending on the triggering policy this can vary, for SizeBased it is by default 60 seconds in DefaultInvocationGate, but configurable, TimeBased are derived from the filename pattern provided. If someone has a filename date pattern which causes the policy to use a very low periodicity, e.g. MILLISECONDS or SECONDS, or someone configures the InvocationGate for SizeBased with a very low value.

In these limited cases this could be an improvement, in exchange for extra state and complexity.