You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-user@logging.apache.org by Chris Berry <ch...@gmail.com> on 2005/11/23 00:48:38 UTC
threading issue with log4j
Greetings,
We have a serious problem w/ log4j inside Tomcat. This has shown up because
we are recently logging to 2 Appenders from a single Category (a
FileAppender and a SyslogAppender), where before it was only 1. Under heavy
load, we are seeing all of the threads backing up behind the synchronized
block in Category.callAppenders() -- see below.
I found some references to this problem in the archives -- but no real
solution. Well, someone did offer a suggestion on how to correct the log4j
code (using multiple-read/single-write locking) -- but that was as far as it
went.
Is there any solution to the problem??
Is there another more thread-smart implementation of Category available??
AFAIK, the cardinal rule of log4j is "logging must be efficient" -- and this
certainly doesn't appear to be...
Thanks,
-- Chris
public
void callAppenders(LoggingEvent event) {
int writes = 0;
for(Category c = this; c != null; c=c.parent) {
// Protected against simultaneous call to addAppender,...
synchronized(c) {
if(c.aai != null) {
writes += c.aai.appendLoopOnAppenders(event);
}
if(!c.additive) {
break;
}
}
}
Re: threading issue with log4j
Posted by Paul Smith <ps...@aconex.com>.
What about wrapping the SyslogAppender in a AsyncAppender.? Clearly
the Syslog appender is taking a lot longer to flush the logs than a
file appender is. That would at least improve your throughput.
Paul
On 24/11/2005, at 1:24 AM, Chris Berry wrote:
> SyslogAppender
>
> On 11/23/05, Paul Smith <ps...@aconex.com> wrote:
>>
>> Question: Which appender did you "add" when it decided to slow
>> things down? The file appender or the Syslog appender?
>>
>> On 23/11/2005, at 4:56 PM, Chris Berry wrote:
>>
>>> I see that this has been corrected in the 1.3 codebase with read/
>>> write
>>> locks, but this won't help me. I have to wait until 1.3 goes final.
>>> Is there any other solution for us on 1.2 apart from hacking the
>>> Category
>>> class ourselves??
>>>
>>> BTW: I don't know why this problem has never shown up for us
>>> before. We
>>> never saw it until we added another Appender?? But reading the code
>>> that
>>> doesn't appear to have anything really to do with it?? It seems
>>> that because
>>> we have a base Category (i.e "com" in com.mycompany....) all of the
>>> logging
>>> is sync-ing on the same object.
>>> Thanks,
>>> -- Chris
>>>
>>> On 11/22/05, Chris Berry <ch...@gmail.com> wrote:
>>>>
>>>> Greetings,
>>>> We have a serious problem w/ log4j inside Tomcat. This has shown up
>>>> because we are recently logging to 2 Appenders from a single
>>>> Category (a
>>>> FileAppender and a SyslogAppender), where before it was only 1.
>>>> Under heavy
>>>> load, we are seeing all of the threads backing up behind the
>>>> synchronized
>>>> block in Category.callAppenders() -- see below.
>>>>
>>>> I found some references to this problem in the archives -- but no
>>>> real
>>>> solution. Well, someone did offer a suggestion on how to correct
>>>> the log4j
>>>> code (using multiple-read/single-write locking) -- but that was as
>>>> far as it
>>>> went.
>>>>
>>>> Is there any solution to the problem??
>>>> Is there another more thread-smart implementation of Category
>>>> available??
>>>> AFAIK, the cardinal rule of log4j is "logging must be efficient"
>>>> -- and
>>>> this certainly doesn't appear to be...
>>>> Thanks,
>>>> -- Chris
>>>>
>>>> public
>>>> void callAppenders(LoggingEvent event) {
>>>> int writes = 0;
>>>>
>>>> for(Category c = this; c != null; c=c.parent) {
>>>> // Protected against simultaneous call to addAppender,...
>>>> synchronized(c) {
>>>> if(c.aai != null) {
>>>> writes += c.aai.appendLoopOnAppenders(event);
>>>> }
>>>> if(!c.additive) {
>>>> break;
>>>> }
>>>> }
>>>> }
>>>>
>>>>
>>>>
>>
>>
>>
>>
Re: threading issue with log4j
Posted by Chris Berry <ch...@gmail.com>.
SyslogAppender
On 11/23/05, Paul Smith <ps...@aconex.com> wrote:
>
> Question: Which appender did you "add" when it decided to slow
> things down? The file appender or the Syslog appender?
>
> On 23/11/2005, at 4:56 PM, Chris Berry wrote:
>
> > I see that this has been corrected in the 1.3 codebase with read/write
> > locks, but this won't help me. I have to wait until 1.3 goes final.
> > Is there any other solution for us on 1.2 apart from hacking the
> > Category
> > class ourselves??
> >
> > BTW: I don't know why this problem has never shown up for us
> > before. We
> > never saw it until we added another Appender?? But reading the code
> > that
> > doesn't appear to have anything really to do with it?? It seems
> > that because
> > we have a base Category (i.e "com" in com.mycompany....) all of the
> > logging
> > is sync-ing on the same object.
> > Thanks,
> > -- Chris
> >
> > On 11/22/05, Chris Berry <ch...@gmail.com> wrote:
> >>
> >> Greetings,
> >> We have a serious problem w/ log4j inside Tomcat. This has shown up
> >> because we are recently logging to 2 Appenders from a single
> >> Category (a
> >> FileAppender and a SyslogAppender), where before it was only 1.
> >> Under heavy
> >> load, we are seeing all of the threads backing up behind the
> >> synchronized
> >> block in Category.callAppenders() -- see below.
> >>
> >> I found some references to this problem in the archives -- but no
> >> real
> >> solution. Well, someone did offer a suggestion on how to correct
> >> the log4j
> >> code (using multiple-read/single-write locking) -- but that was as
> >> far as it
> >> went.
> >>
> >> Is there any solution to the problem??
> >> Is there another more thread-smart implementation of Category
> >> available??
> >> AFAIK, the cardinal rule of log4j is "logging must be efficient"
> >> -- and
> >> this certainly doesn't appear to be...
> >> Thanks,
> >> -- Chris
> >>
> >> public
> >> void callAppenders(LoggingEvent event) {
> >> int writes = 0;
> >>
> >> for(Category c = this; c != null; c=c.parent) {
> >> // Protected against simultaneous call to addAppender,...
> >> synchronized(c) {
> >> if(c.aai != null) {
> >> writes += c.aai.appendLoopOnAppenders(event);
> >> }
> >> if(!c.additive) {
> >> break;
> >> }
> >> }
> >> }
> >>
> >>
> >>
>
>
>
>
Re: threading issue with log4j
Posted by Paul Smith <ps...@aconex.com>.
Question: Which appender did you "add" when it decided to slow
things down? The file appender or the Syslog appender?
On 23/11/2005, at 4:56 PM, Chris Berry wrote:
> I see that this has been corrected in the 1.3 codebase with read/write
> locks, but this won't help me. I have to wait until 1.3 goes final.
> Is there any other solution for us on 1.2 apart from hacking the
> Category
> class ourselves??
>
> BTW: I don't know why this problem has never shown up for us
> before. We
> never saw it until we added another Appender?? But reading the code
> that
> doesn't appear to have anything really to do with it?? It seems
> that because
> we have a base Category (i.e "com" in com.mycompany....) all of the
> logging
> is sync-ing on the same object.
> Thanks,
> -- Chris
>
> On 11/22/05, Chris Berry <ch...@gmail.com> wrote:
>>
>> Greetings,
>> We have a serious problem w/ log4j inside Tomcat. This has shown up
>> because we are recently logging to 2 Appenders from a single
>> Category (a
>> FileAppender and a SyslogAppender), where before it was only 1.
>> Under heavy
>> load, we are seeing all of the threads backing up behind the
>> synchronized
>> block in Category.callAppenders() -- see below.
>>
>> I found some references to this problem in the archives -- but no
>> real
>> solution. Well, someone did offer a suggestion on how to correct
>> the log4j
>> code (using multiple-read/single-write locking) -- but that was as
>> far as it
>> went.
>>
>> Is there any solution to the problem??
>> Is there another more thread-smart implementation of Category
>> available??
>> AFAIK, the cardinal rule of log4j is "logging must be efficient"
>> -- and
>> this certainly doesn't appear to be...
>> Thanks,
>> -- Chris
>>
>> public
>> void callAppenders(LoggingEvent event) {
>> int writes = 0;
>>
>> for(Category c = this; c != null; c=c.parent) {
>> // Protected against simultaneous call to addAppender,...
>> synchronized(c) {
>> if(c.aai != null) {
>> writes += c.aai.appendLoopOnAppenders(event);
>> }
>> if(!c.additive) {
>> break;
>> }
>> }
>> }
>>
>>
>>
Re: threading issue with log4j
Posted by Chris Berry <ch...@gmail.com>.
I see that this has been corrected in the 1.3 codebase with read/write
locks, but this won't help me. I have to wait until 1.3 goes final.
Is there any other solution for us on 1.2 apart from hacking the Category
class ourselves??
BTW: I don't know why this problem has never shown up for us before. We
never saw it until we added another Appender?? But reading the code that
doesn't appear to have anything really to do with it?? It seems that because
we have a base Category (i.e "com" in com.mycompany....) all of the logging
is sync-ing on the same object.
Thanks,
-- Chris
On 11/22/05, Chris Berry <ch...@gmail.com> wrote:
>
> Greetings,
> We have a serious problem w/ log4j inside Tomcat. This has shown up
> because we are recently logging to 2 Appenders from a single Category (a
> FileAppender and a SyslogAppender), where before it was only 1. Under heavy
> load, we are seeing all of the threads backing up behind the synchronized
> block in Category.callAppenders() -- see below.
>
> I found some references to this problem in the archives -- but no real
> solution. Well, someone did offer a suggestion on how to correct the log4j
> code (using multiple-read/single-write locking) -- but that was as far as it
> went.
>
> Is there any solution to the problem??
> Is there another more thread-smart implementation of Category available??
> AFAIK, the cardinal rule of log4j is "logging must be efficient" -- and
> this certainly doesn't appear to be...
> Thanks,
> -- Chris
>
> public
> void callAppenders(LoggingEvent event) {
> int writes = 0;
>
> for(Category c = this; c != null; c=c.parent) {
> // Protected against simultaneous call to addAppender,...
> synchronized(c) {
> if(c.aai != null) {
> writes += c.aai.appendLoopOnAppenders(event);
> }
> if(!c.additive) {
> break;
> }
> }
> }
>
>
>