>Not only, it would also appear inside the config file in order to set
>the locking model of FileAppender like in the third example of
>http://logging.apache.org/log4net/release/config-examples.html#fileappender
>Right now it would be
>
><lockingModel type="log4net.Appender.FileAppender+MutexLock" />

Quite obvious what it does. If one enters "MutexLock .NET" into google there
are plenty useful resources to find out what it does.

>> Did you actually do performance tests too? A mutex is rather expensive
>and
>> it should be avoided to acquire/release it multiple times unless really
>> necessary.
>
>It would be aquired and released for each single logging event.  The
>alternatives are (1) don't share the same log file between different
>processes or (2) repeatedly open and close the file (which is the
>MinimalLocking model).  Whether the mutex performs better or worse than
>MinimalLocking depends on the concrete circumstances, I guess, but I'd
>expect the overhead of opening a file to be significant as well.

Based on my observations, acquiring a mutex lock can take up to 30ms. IMHO
the solution alternative 3) would require a little more effort. Namely
collect a bunch of log events in the appender and dispatch them with one
Mutex lock as fast as possible. I've here a reference implementation, but
unfortunately I can't share it due to license restrictions. :-(

The implementation basically works on two queues containing a ordered set of
log events:

* outerQueue
* innerQueue

New events are put to the outerQueue and all items in the innerQueue are
written to the logfile in one go. And to speed things up, the queues are
swapped in two conditions:

* new log event is put to the outerQueue and the innerQueue is empty
  => swap innerQueue and outerQueue and write all events in innerQueue
* innerQueue write is finished and the outerQueue is not empty
  => swap innerQueue and outerQueue and write all events in innerQueue

I tested this on a quad-core, running 8 processes with 8 threads each
logging in a while(true) loop and it works like a charm. :-)

Greetings,
D.

Reply via email to