[💡 FEATURE REQUEST]: Non-blocking logging
Plugin
Logger
I have an idea!
Currently, logging is blocking.
You can see this in action by running roadrunner through pv:
./rr serve 2> >(pv -q -L 1k)
This will result in a slowdown of roadrunner, including startup and a slowdown of it being able to process requests, tasks or workflows. (You can increase or decrease the throttling to see its effects by tweaking the -L parameter). The effect is higher with higher levels of logging, e.g. debug-level.
In my case, I'm running the roadrunner process from another host process, and processing its logs sent to stderr to enrich it. Poor processing performance on my part meant I was filling the pipe and blocking roadrunner.
Hey @jackprice 👋🏻
Writing to a file (fd) would always be blocking and depends on your terminal throughput. This is why, if you need to write to a file, RR has a separate configuration for that (file logger). Also, debug logging level will slow down any application and should be used only on non-production environments.
While we can use goroutines, for example, to write logs in a non-blocking manner, this may introduce significant memory spikes and slowness for the entire application (more goroutines -> more resources used).
RR introduces several techniques under the hood, like sampling.
But I guess we can apply buffered writes as an additional technique to prevent stopping the application on log flushes.