[logback-dev] Appender synchronization

Ralph Goers ralph.goers at dslextreme.com
Sat Oct 11 06:53:47 CEST 2008

I would have opened a Jira issue for this (I will) but it appears to be 

We have run into a serious performance problem with a custom appender. 
The appender is not particularly fast and logback ends up being a system 
wide bottleneck. This is because the doAppend method of AppenderBase is 
synchronzed and Logger's callApenders method calls appendLoopOnAppenders 
within a synchronzed block.  Synchronized blocks should always be as 
small as possible. Synchronizing appender calls is just asking for 
trouble. Chapter 4 currently documents this behavior and should be changed.

In my case I can avoid the first issue by having my appender override 
doAppend, but this really shouldn't be necessary. It would be much 
better to have appenders that aren't thread safe synchronize on the 
doAppend method or, better yet, within the method.  The guard to avoid 
recursion can be handled with a thread local.
As for callAppenders, there is unfortunately no way for me to bypass 
this problem without patching logback. java.util.concurrent provides 
several ways to avoid this. One would be to replace the synchronization 
with a ReadWriteLock. An even better alternative would be to completely 
remove the synchronization from Logger and change AppenderAttachableImpl 
use a ReadWriteLock to manage access to the appender List.

I will try to work up some patches for these and add them to jira when 
they are done and jira is available again.


More information about the logback-dev mailing list