emabee / flexi_logger

A flexible logger for rust programs that can write to stderr, stdout, and/or to log files
Apache License 2.0
307 stars 50 forks source link

flexi_logger Performance #70

Closed rohitjoshi closed 3 years ago

rohitjoshi commented 3 years ago

I switch from slog_async to flexi_logger and lost ~20% throughput. The log level is set to info and less than 10 lines are logged per second. Any reason for this performance drop?

I suspect few things but please help me here.

  1. For slog, I used features to remove debug statements at compile time:
    slog = { version = "2.5.2", features = ["max_level_trace", "release_max_level_info"] }

    but this is not supported by flexi_logger. I did use log level features as below.

    
    log = { version = "0.4.11", features = ["max_level_trace", "release_max_level_info"] }


2. slog uses async sink with channel size as ~64K but don't see similar config for flexi_logger. Any way to use async / buffer logging using flexi_logger?
emabee commented 3 years ago

Ad 1: Compile time filters are provided by the log crate into which flexi_logger 'plugs' in. See https://docs.rs/log/0.4.11/log/#compile-time-filters .

Ad 2: I added an option use_buffering (see https://docs.rs/flexi_logger/0.17.0/flexi_logger/struct.Logger.html#method.use_buffering) with version 0.17; would be great if you could try it out and let me know if this helps already far enough. I also started to experiment with crossbeam channels, but didn't see a big enough difference yet (but this may be platform specific).

rohitjoshi commented 3 years ago

I will try it out and let you know. Thank you 🙏

rohitjoshi commented 3 years ago

With buffering, it would be good to implement auto flush timer so buffered output will be written to log. Eg. Nginx allows configurable buffer size and flush interval http://nginx.org/en/docs/stream/ngx_stream_log_module.html#access_log

emabee commented 3 years ago

Is implemented with 0.17.1; see https://docs.rs/flexi_logger/0.17.1/flexi_logger/struct.Logger.html#method.buffer_and_flush or https://docs.rs/flexi_logger/0.17.1/flexi_logger/struct.Logger.html#method.buffer_and_flush_with

Thanks for the proposal!!