You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-dev@logging.apache.org by pd...@volantis.com on 2002/01/21 18:14:00 UTC

Improvements to LocationInfo.

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:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Improvements to LocationInfo.

Posted by pd...@volantis.com.
Ceki Gülcü wrote:
> 
> One quick question. Are you sure your code extracts the correct
> location information? Regards, Ceki
> 

Before we started using log4j we had our own home grown logging
mechanism which extracted the location information on the background
thread and we never had a problem with it and we used it on
JDK 1.2 and JDK 1.3.

The documentation for Throwable says
  "A Throwable class contains a snapshot of the execution stack
   of its thread at the time it was created. It can also contain
   a message string that gives more information about the error."
so it looks as though it is safe to parse the stack trace on a
different thread to the thread which originally threw it.

A question for you, in JDK 1.4 a getStackTrace method has
been added to Throwable which allows you to get access to the
location information much more easily, are there plans (has it
already been done) to use this mechanism when it is available
(not sure how you would tell) instead of parsing the printed
stack trace ?

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Improvements to LocationInfo.

Posted by pd...@volantis.com.
I have just noticed that LocationInfo.fullInfo is public which
seems a very dangerous thing to be doing, is there any reason
why it is done this way and would anyone mind if I made it
private and added a getFullInfo method.

I have checked the log4j source code and found one place that
it is used (in PatternParser).

Also, could anyone tell me why the other members of
LocationInfo are package private rather than just private ?

Please note, I am not criticising I just want to know why it
has been done that way.

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Improvements to LocationInfo.

Posted by Ceki Gülcü <ce...@qos.ch>.
One quick question. Are you sure your code extracts the correct
location information? Regards, Ceki

At 17:14 21.01.2002 +0000, pduffin@volantis.com wrote:
>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:   <ma...@jakarta.apache.org>
>For additional commands, e-mail: <ma...@jakarta.apache.org>

--
Ceki Gülcü - http://qos.ch



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>