I was having a problem where even though I was using an AsyncAppender
the logging did not seem to be being buffered and slowed down the
application being logged. I tracked the problem down to the
LocationInfo class which synchronizes on a single StringWriter
shared across all threads in its constructor. New instances of
the object are created by the LoggingEvent getLocationInformation
method which is called by the AsyncAppender on the thread which
called the logging method.

I modified the LocationInfo class to defer the parsing of the
Throwable's stack trace until the information was actually
needed by one of the get methods.

This has the following advantages:
1) If the location information is not actually needed then the
   parsing is never done.
2) If all the logging is done by the AsyncAppender then there
   is no contention for the shared StringWriter.

It does increase the amount of space used for a LoggingEvent
and does complicate the serialization of the LoggingEvent as
it has to make sure that the throwable's stack trace has been
parsed before serialization.

In a very simple test this small changed made a single threaded
GUI application run about 10 times faster simply because the
parsing was being done on a background thread.

I would like log4j to be modified to incorporate this change
but am not sure of the best way to get this done so if anyone
else would like this fix then please speak up.

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to