ppkarwasz commented on issue #2856:
URL: 
https://github.com/apache/logging-log4j2/issues/2856#issuecomment-2304705850

   > ### 1. Do nothing
   > 
   >     * log4j2
   >       Firstly, without doing anything, the application's memory is about 
160M:
   
   This graph isn't really reliable: you don't see any garbage-collection 
event, so it is entirely possible that most of the 160 MiB could be collected.
   
   > ### 2. Write log
   > 
   > It was tested in the same way: 
http://127.0.0.1:8080/log4j2/pressure?minLengthInclusive=102400&;
   maxLengthExclusive=409600&times=10000
   
   What does `minLengthInclusive` and `maxLengthExclusive` parameters mean? If 
these are the sizes of log messages, their values greatly exceed the size of a 
typical log event. Log4j Core by default expects log messages up to 518 bytes 
and log events up to 8192 bytes in size. Besides these limits you start 
creating a **lot** of temporary objects and you are no longer garbage-free. See 
[Garbage Free 
logging](https://logging.staged.apache.org/log4j/2.x/manual/garbagefree.html) 
for more details.
   
   > the conclusion is that log4j2 is more powerful, but why isn't it the case 
when I test it myself?
   
   If by "powerful" you mean that Log4j Core always provides a better 
performance and lower memory usage than Logback, the conclusion is wrong. 
Everything depends on how your application is configured and how you use 
logging. Note that the astonishing 20M messages/s is a **peak** throughput that 
you can keep for **very small** periods of time (a couple of ms). You can 
compare this with the performance of SSDs: writing the first 8 MiB or so is 
lightning fast, but the sustainable rate is much lower.
   
   Regarding memory usage:
   
   - The **garbage-free** mode increases your memory usage, since many reusable 
buffers need to be allocated. You pay an initial memory price, but later on you 
will not experience GC pauses due to logging. Nowadays garbage collection is 
very fast, but a couple of years ago it was a "stop the world" event, which was 
very costly for financial applications. See 
[`log4j2.enableThreadlocals`](https://logging.staged.apache.org/log4j/2.x/manual/garbagefree.html#log4j2.enableThreadlocals)
 for details on how to disable garbage-free logging.
   - Using the Disruptor also costs memory, since it pre-allocates up to 256 
× 1024 buffers. See [asynchronous 
loggers](https://logging.staged.apache.org/log4j/2.x/manual/async.html) on how 
to enable or disable the usage of the LMAX Disruptor.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to