[slf4j-dev] Appender synchronization

Ralph Goers ralph.goers at dslextreme.com
Sat Oct 11 08:04:47 CEST 2008


Darn. Please ignore. Resending to the logback list.

Ralph Goers wrote:
> I would have opened a Jira issue for this (I will) but it appears to 
> be unavailable.
>
> 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.
>
> Ralph



More information about the slf4j-dev mailing list