Closed KjellKod closed 8 years ago
Hi Kjell,
Thanks for having a look.
In terms of the design, when the ring buffer is full, the producer just overwrites the log line in that slot [i.e. does not wait for consumer thread to pop the item]. In summary - the old log line will be lost when buffer is full.
In the event this occurs, its a sign the ring buffer size passed on initialization was chosen incorrectly relative to the logging frequency of the application. The end-user simply has to choose a more appropriate ring buffer size.
That's why I feel overwriting the old log line in the extreme case is the correct design choice. The added advantage is that in theory the latency is independent of the state of the ring buffer [because full or not, the producer always writes the log line to slot and does not care if there was a previous log line in the slot].
In terms of measuring worst case latency there are complications -
uint64_t begin = timestamp_now();
LOG_INFO << "Benchmark this";
uint64_t end = timestamp_now();
The error in measuring NanoLog latency like this is too high relative to the time NanoLog takes.
That's why in the benchmark, I measured the time taken to log 1000 lines (which would be in 100s of microseconds ) which can be measured accurately by chrono timestamps.
I do not know of any accurate way to measure individual log line latency...
Karthik
Cool. Thanks for explaining this.
I see why the "fire and forget" policy to logs is appealing. (I.e overwrite)
Sweet library! Nice work
I found the bench mark lacking in a couple of aspects
Thanks Kjell