andyford has asked for the wisdom of the Perl Monks concerning the following question:

Since my usage of Log4perl exactly mirrors the situation of concern in the documentation for Log::Log4perl::Appender::Synchronized , I figured I better start using it before something bad happens.
If multiple processes are using the same Log::Log4perl appender without synchronization, overwrites might happen. A typical scenario for this would be a process spawning children, each of which inherits the parent's Log::Log4perl configuration.
I put the extra synchronizing declarations into my Log4perl config file and away it went.

But how do I test it?

More specifically, how do I reliably generate an overwrite situation that the syncronization would fix?

Or is there another way to test the sync?

andyford
or non-Perl: Andy Ford

  • Comment on Testing effectiveness of Log4Perl synchronized appender

Replies are listed 'Best First'.
Re: Testing effectiveness of Log4Perl synchronized appender
by sgifford (Prior) on Sep 20, 2006 at 02:07 UTC
    I have written tests for similar situations by creating a bunch of children, having them write as quickly as they can for a while (say 1000 messages), then checking to make sure nothing was garbled and everything showed up. This test is probabilistic, so it's not guaranteed to find problems, but it's likely to, and more likely the longer you run it.
      As a small addition: you should tweak sgifford's suggestion using the non-sychronized appender until you get the overwrite error reproducably.

      Then use the synchronized version and see if it goes away.

      -- Hofmator

      Code written by Hofmator and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.

Re: Testing effectiveness of Log4Perl synchronized appender
by saintmike (Vicar) on Oct 11, 2006 at 18:46 UTC
    Take a look at how the Log4perl test suite does it. It uses a semaphore to synchronize the writers to purposely step on each other's toes.