8 ms·
Also, it goes without saying, but never buffer logs. Each line should end up with a write(2) call or something equivalent. If you buffer logs, and the process
by yongjik 5y ago
Also, it goes without saying, but never buffer logs. Each line should end up with a write(2) call or something equivalent. If you buffer logs, and the process crashes, you lose logs exactly when you really really need it.
- Spivak 5y agoI agree with you in theory if resources were infinite but there is no way to log at the rates developers actually want to log and have a performant application without buffering. I think the more practical advice is "buffer logs outside your application" or "buffer logs in a separate thread/process that crashes independently of your application code." Even the small places I've worked could easily push 250G logs a day.
- yongjik 5y agoI guess "buffering in a separate process" can be handy, esp. if you have strict performance requirements, but I guess using shared memory correctly can be tricky...? (Without shared memory, I imagine you'll have one system call per log anyway - in which case it's not much different from calling one write() per line.)