erwan has asked for the wisdom of the Perl Monks concerning the following question:
Facing some efficiency issues with a quite complex program, I used NYTProf to profile it. I noticed that the logging operations (using Log4perl) require a significant amount of time (about 25%), so I tried to disable logging by setting the log level to OFF. Nothing is logged (of course), but according to NYTProf the time taken by Log4perl is still the same. I thought that as soon as level was OFF calls to log4perl would have exited immediately, but it seems there are a lot of internal computations whatever the level (?).
I have already optimized the most frequent calls in the following way:
if ($self->{logger}->is_trace()) { $self->{logger}->trace("total NbObsThis $i=$nbObservedThis +NGram->[$i]; nbObsAll $i=$nbObservedAllNGrams->[$i]; total=$totalObse +rvedAll; nbExpected $i=$nbExpectedThis[$i]; chisq = $chiSquare[$i]"); + }
and I was very surprised when I saw that even this simple call to is_trace() (when the log level is OFF) is very costly (takes 30% of the time spent in a sub called very often).
Of course I can create my own condition like
but it doesn't seem very elegant to add my own "optimized level" to the usual ones. Do you have any other ideas? Maybe something I missed about Log4perl? Thank you!if ($loggingOn) { $self->{logger}->trace("total NbObsThis $i=$nbObservedThisNGram->[$i]; + nbObsAll $i=$nbObservedAllNGrams->[$i]; total=$totalObservedAll; nbE +xpected $i=$nbExpectedThis[$i]; chisq = $chiSquare[$i]"); }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: log4perl and efficiency
by Solo (Deacon) on Sep 12, 2011 at 17:17 UTC | |
by erwan (Sexton) on Sep 12, 2011 at 17:30 UTC | |
by Solo (Deacon) on Sep 12, 2011 at 17:44 UTC | |
by erwan (Sexton) on Sep 12, 2011 at 17:54 UTC | |
Re: log4perl and efficiency
by BrowserUk (Patriarch) on Sep 12, 2011 at 16:56 UTC | |
by Anonymous Monk on Sep 12, 2011 at 18:43 UTC | |
by BrowserUk (Patriarch) on Sep 12, 2011 at 18:53 UTC | |
by Anonymous Monk on Sep 12, 2011 at 17:23 UTC | |
by BrowserUk (Patriarch) on Sep 12, 2011 at 17:58 UTC | |
Re: log4perl and efficiency
by erwan (Sexton) on Sep 12, 2011 at 18:19 UTC | |
by Solo (Deacon) on Sep 12, 2011 at 18:29 UTC | |
by erwan (Sexton) on Sep 12, 2011 at 19:03 UTC | |
by ForgotPasswordAgain (Priest) on Sep 12, 2011 at 22:20 UTC |