5 ms·
One disadvantage of that - though it only matters in some contexts - is that you pay the cost of formatting all those log messages (or at least copying enough d
by quietbritishjim 6y ago
One disadvantage of that - though it only matters in some contexts - is that you pay the cost of formatting all those log messages (or at least copying enough data to be able to format them later) even if they're never read.
- falcolas 6y agoThe cost of writing data to memory is incredibly small; you'd have to be working on something like gaming engines for it to even be noticeable. Logging can also be done in a separate thread, reducing even that exceptionally minor cost.
- wsargent 6y agoCan confirm -- writing data to memory is incredibly fast. It's faster to use a lock-free queue and use CAS to insert data though: http://psy-lob-saw.blogspot.com/2016/12/linked-array-queues-part-2-spsc.html http://psy-lob-saw.blogspot.com/2016/12/linked-array-queues-... I've benchmarked code myself, and the flamegraphs will barely show the SpscArrayQueue in the profile.
- wsargent 6y agoThat depends on where the ringbuffer is placed. If you're placing the ringbuffer inside an appender, then the appender's encoder will format. However, if the ringbuffer itself is an appender, then you can store the logging events as is until it's time to dump them -- this is the approach in terse-logback [1] Another option is to put the ringbuffer BEFORE sending it to the logging framework, so it's never processed by SLF4J at all. This means that it's more accessible to the application, at the cost of losing the initial timestamp of the logging event. This is the approach taken in Blindsight. [2] Shout out to Bunyan, which is (AFAIK) the only server side logging framework that has ringbuffers out of the box. [3] [1] https://tersesystems.github.io/terse-logback/guide/ringbuffer/ https://tersesystems.github.io/terse-logback/guide/ringbuffe... [2] https://tersesystems.github.io/blindsight/usage/buffer.html https://tersesystems.github.io/blindsight/usage/buffer.html [3] https://github.com/trentm/node-bunyan#raw--ringbuffer-stream https://github.com/trentm/node-bunyan#raw--ringbuffer-stream