[ 
https://issues.apache.org/jira/browse/LOG4J2-2792?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17085447#comment-17085447
 ] 

Ralph Goers commented on LOG4J2-2792:
-------------------------------------

The thread dump shows a lot of threads in java.lang.StackWalker.  This would be 
happening if somewhere in your logging configuration something is configured to 
require location information. Stack walking in Java is very slow and believe it 
or not I spent quite a bit of effort in LOG4J2-2644 to improve the performance. 
One of the improvements was to move collection of the location information 
higher up in the call path because StackWalker perfoms better when traversing a 
small number of stack frames. But it only does that if it detects that some 
component requires location information. From the stack traces I can tell that 
that is true in your case. 

I would also wonder if when you upgraded Log4j you upgraded from Java 8 to Java 
9+ at the same time. StackWalker was introduced in Java 9 and the mechanism 
Log4j used prior to that was removed. Unfortunately, the mechanism that was 
removed from Java was a bit faster.

One of the problems with StackWalker is that it requires the use of Streams. 
While convenient, Stream performance is not great. I found the fastest way to 
process the stack was to convert it to an array and use a for loop. However, 
StackWalker still uses a Stream to create the array.

The best option would be to use a profiling tool like YourKit and do CPU 
profiling on your application. We could then create a bug report with the 
OpenJDK team that demonstrates how slow StackWalker is and ask them to just 
return the array without using Streams.

The workaround would be to modify your configuration to not require location 
information if it is causing you that much overhead.

> Performance issue in log4j 2.12.1 and log4j 2.13.0
> --------------------------------------------------
>
>                 Key: LOG4J2-2792
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-2792
>             Project: Log4j 2
>          Issue Type: Bug
>          Components: API, Core
>    Affects Versions: 2.12.1, 2.13.0
>         Environment: System configuration: Redhat Linux 7,12-core,16Gb RAM
> Application server: Apache tomcat 9.0.16
>            Reporter: Riya Reji
>            Priority: Blocker
>         Attachments: 24-jstack-2020-02-23-173500.zip, log4j2.xml, 
> log4j_2_13_CPU_SPIKE.PNG
>
>
> Hi,
> When log4j2 was upgraded from 2.11.0 to 2.12.1 or 2.13.0,the cpu utilization 
> was spiking to 100 %. When 2.11.0 version was used the CPU utilization was 
> below 40%.
>  
> PFA image of CPU utilization when 2.13.0 was used



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to