serilog / serilog-sinks-periodicbatching

Infrastructure for Serilog sinks that process events in batches.
Apache License 2.0
70 stars 29 forks source link

Timer should be stopped when there are no remaining events #44

Closed mniak closed 4 years ago

mniak commented 4 years ago

I think the timer should be disable when there ar no more events to be written/sent/emmited.

In a recent problem described in #43 (totally my fault) I got to perceive that the class PeridodicBatchingSink continues running even when there are no more events.

The High CPU Usage problem I was facing was due to period being informed TimeSpan.Zero. While I assume this was my fault, there were no reason to the timer to keep running when the log event count reaches zero.

It should be started again when next event comes.

Is this behavior by-design? Would it make any sense to improve this like described?

Thanks!

skomis-mm commented 4 years ago

Hi @mniak,

I beleive it is by design. Technically there is a contract (OnEmpyBatch) that should be respected when there are no events in the batch.

It wasn't designed to work with periods around the delta of zero. The whole point of this is to offload sending burst of events with batches and at ~constant pace.

mniak commented 4 years ago

/// Allows derived sinks to perform periodic work without requiring additional threads /// or timers (thus avoiding additional flush/shut-down complexity).

Oh, I see. Thank you very much for the attention!