3 ms·
One time we observed a dramatic drop-off in performance from one of our services after a certain day that week. I looked at recent releases and saw it perfectly
by mratzloff 9y ago
One time we observed a dramatic drop-off in performance from one of our services after a certain day that week. I looked at recent releases and saw it perfectly coincided with one.
I asked the engineer in question to investigate, but after looking he said, "It's nothing I could be doing."
So I sat with him and used git-bisect to prove to him it was his commit: he had added trace logging within a couple of tight loops in the hottest parts of the code base. I smiled.
"But it's trace. That's disabled in production. It can't be that," he said. But we had already proven it was that commit, and the only thing that changed was additional logging.
Long story short, the logging library was filtering calls by level just before actually writing, rather than as close as possible to the call site—a design bug, for sure.
I had him swap out the library everywhere it was being used.
Moral: logging is not free.
- hvidgaard 9y agoLogging is never free. Either you add additional compile time cost to remove it, or you add at the very least a single if and/or method call at runtime. It's not easy problem to solve. The best I've come up with so far, is using a decorator in conjunction with a DI framework that supports it. It's still only a wrap around method calls, but it enables completely turning off logging in production, and enable it when it is needed without making a special build, or wasting resources during normal execution.
- kbutler 9y agoPreprocessor-disabled logging (and generally compile-time disabled logging) is free at run-time. The compile-time cost of stripping out preprocessor macros disabled via #ifdef is close enough to free you'd have a really hard time measuring it - O(n) on number of lines of logging code, with n smaller than the number of lines of actual code for any real scenario, and a very small multiplier. The "cost" there is in the visual appearance of the source code.
- Fnoord 9y ago> Moral: logging is not free. I can see how this is even true for a sniffing hardware bridge but isn't it free when your source is fiber?