0

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.

  • 1
    Possible duplicate of Is micro-optimisation important when coding? – gnat May 25 '18 at 16:22
  • 2
    Logging 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 5 '18 at 14:29
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.
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.

  • 2
    It depends on a lot of things, not just the framework. – Robert Harvey May 25 '18 at 19:57
  • OK. What are those things? – Mandrake Jun 8 '18 at 15:36
  • @Mandrake Did you mean to ask @Robert or me? – πάντα ῥεῖ Jun 8 '18 at 15:40
  • @RobertHarvey Sorry... It was directed to Robert. " What are those LOT of things? – Mandrake Jun 11 '18 at 18:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.