Do logging impact application performance? First thing to know is , whether logs are written serially as processing takes place or are logged into file i a separate process? In java world how should I improve performance of my application where I need to log a lot in that case? Micro optimization is a side effect but I am looking for impact on putting log messages in java code. I later found , seems there is impact and log4j 2 seems originated out of this impact.
Asked
Active
Viewed 2,560 times
0
-
1Possible duplicate of [Is micro-optimisation important when coding?](https://softwareengineering.stackexchange.com/questions/99445/is-micro-optimisation-important-when-coding) – gnat May 25 '18 at 16:22
-
2Logging in a performant way is a bit more nuanced than your usual, run-of-the-mill micro-optimizing. – Robert Harvey May 25 '18 at 20:08
-
My question is totally different. Why -ve votes instead of answers? I am looking for impact of logs on performance. Micro optimization may be a sub/side effect but I need answers on logging specifically! – Mandrake Jun 05 '18 at 14:29
2 Answers
2
Well I see some possibilities about performances issues there, I will assume the logging framework you use is decent enough to not be the source of the problem.
- Synchronous logger : if you have configure synchronous logging everywhere, all your thread will regularly wait to be able to write at the disk. Synchronous logging is adequate for audit purpose where every log of something that has been done must figure.
- Asynchronous logging : it will take more memory and some more thread to handle. If your application interrupts, you will probably miss some of the last logs of the things that were done. So if you loaded your logs too much, it will either take lot of memory, of flush more often on the disk. Threads will only waits to be able to get the lock on the in memory buffer.
- Problem on development side : sometimes performance comes not from the configuration but from how the message to log is built (string concatenation, reinstantation of multiple object in lopo when not necessary,...), which take unecessary memory and cpu (and more garbage collection ? ).
To resume : with logging you may have trouble with :
- disk usage blocking processing while waiting for the possibility to write.
- memory consumption (and so eventually full GC)
- in-memory locks : when using asynchronous logging, if you log everything to one single file it is possible that your thread start to wait quite some time to access to the in-memory buffer storing all pending logs to write.

Walfrat
- 3,456
- 13
- 26
0
Depends on the logging framework you use.
It will have less performance impact, if the logging is done asynchronously, and sending the log messages is more or less a queueing operation in 1st place.
This might change the behavior regarding possible race conditions of your code though.
A bigger performance impact has to be considered, if logging is implemented synchronously and log messages are directly flushed to the log file.

πάντα ῥεῖ
- 1,540
- 3
- 12
- 19
-
2
-
-
-
@RobertHarvey Sorry... It was directed to Robert. " What are those LOT of things? – Mandrake Jun 11 '18 at 18:26