Replies: 3 comments 1 reply
-
Beta Was this translation helpful? Give feedback.
-
你想测试log4j2的内存使用情况,应该参考这篇文档https://logging.apache.org/log4j/2.x/manual/garbagefree.html. 我自己也写了一个日志库,https://github.com/jdkstack/nogc4j-ce. |
Beta Was this translation helpful? Give feedback.
-
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.
What does
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:
|
Beta Was this translation helpful? Give feedback.
-
After reading the official performance report, the conclusion is that log4j2 is more powerful, but why isn't it the case when I test it myself?
1. Do nothing
log4j2
Firstly, without doing anything, the application's memory is about 160M:
logback
But I only have around 30MB of memory when using Logback:
2. Write log
It was tested in the same way: http://127.0.0.1:8080/log4j2/pressure?minLengthInclusive=102400&maxLengthExclusive=409600×=10000
log4j2
Although the memory usage is not very high, it is more than twice as much as logback.
logback
Did I do something wrong?
This is my test project(Spring Boot):
log-sample.zip
Beta Was this translation helpful? Give feedback.
All reactions