Blocking threads in log4j appender

1,177 views
Skip to first unread message

Andrei Shakirin

unread,
Nov 7, 2017, 12:42:39 PM11/7/17
to OPS4J
Hi,

I have experienced that under high load logj4 appender (packed into pax-logging-service.jar) blocks threads and essentially reduces the throughput (in my case about 15%).

The stack trace from thread dump:
"qtp52584153-10776" - Thread t@10776
   java
.lang.Thread.State: BLOCKED
        at org
.apache.log4j.AppenderSkeleton.doAppend(AppenderSkeleton.java:231)
       
- waiting to lock <6a484498> (a org.apache.log4j.DailyRollingFileAppender) owned by "ArticlePAAThread" t@10014
        at org
.apache.log4j.helpers.AppenderAttachableImpl.appendLoopOnAppenders(AppenderAttachableImpl.java:59)
        at org
.apache.log4j.Category.callAppenders(Category.java:179)
        at org
.apache.log4j.Category.forcedLog(Category.java:333)
        at org
.apache.log4j.Category.log(Category.java:724)
        at org
.ops4j.pax.logging.service.internal.PaxLoggerImpl.inform(PaxLoggerImpl.java:167)
        at org
.ops4j.pax.logging.internal.TrackingLogger.inform(TrackingLogger.java:86)
        at org
.ops4j.pax.logging.slf4j.Slf4jLogger.info(Slf4jLogger.java:534)
        at xxx
.LoggingServiceExecutionTimeHandler.filter(LoggingServiceExecutionTimeHandler.java:52)


The issue is discussed in log4j bugzilla: https://bz.apache.org/bugzilla/show_bug.cgi?id=50213, basically it is related to synchronized doAppend() method in AppenderSkeleton class.
As far as I see the problem still appears in latest ops4j pax logging version (1.10.1).

Any suggestion how to fix or workaround this problem?

Regards,
Andrei.

Matt Sicker

unread,
Nov 7, 2017, 12:44:50 PM11/7/17
to op...@googlegroups.com
Log4j 1.x is unsupported nowadays; you should migrate to Log4j 2.x. If you're unable to migrate, then your best bet is to try to use an AsyncAppender, though those are also vastly improved in Log4j 2.x (along with far less synchronized blocks to cause problems).


--
--
------------------
OPS4J - http://www.ops4j.org - op...@googlegroups.com

---
You received this message because you are subscribed to the Google Groups "OPS4J" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ops4j+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Matt Sicker <boa...@gmail.com>

Andrei Shakirin

unread,
Nov 7, 2017, 12:53:43 PM11/7/17
to OPS4J
Hi Matt,

Thanks for quick response, but I don't use log4j directly, only through the pax-logging-service.jar. 
And the issue is still there even with last released pax-logging-service version (1.10.1).

Async appender is an option, will definitely try that.

Regards,
Andrei.

Matt Sicker

unread,
Nov 7, 2017, 12:58:11 PM11/7/17
to op...@googlegroups.com
If you use pax-logging-log4j2, you can migrate easily, though the version of log4j2 in there is somewhat out of date.

Async appender will certainly alleviate some issues, but it can't do much about APIs that publicly add the synchronized keyword to hot spots like in log4j1.

--
--
------------------
OPS4J - http://www.ops4j.org - op...@googlegroups.com

---
You received this message because you are subscribed to the Google Groups "OPS4J" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ops4j+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Matt Sicker <boa...@gmail.com>

Niclas Hedhman

unread,
Nov 8, 2017, 3:04:19 AM11/8/17
to OPS4J
Andrei,

In case it is not clear; pax-logging-log4j2 is a replacement implementation for the pax-logging-service.
Niclas Hedhman, Software Developer
http://polygene.apache.org - New Energy for Java
Reply all
Reply to author
Forward
0 new messages