logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Remko Popma <remko.po...@gmail.com>
Subject Re: Async Loggers and Appenders
Date Thu, 06 Feb 2014 09:38:59 GMT
On Thursday, February 6, 2014, McCarthy, Peter (Peter) <petermc@avaya.com>

> Folks,
> In documentation for Async appenders you state the following :
> "Asynchronous Appenders already existed in Log4j 1.x, but have been
> enhanced to flush to disk at the end of a batch (when the queue is empty).
> This produces the same result as configuring "immediateFlush=true", that
> is, all received log events are always available on disk, but is more
> efficient because it does not need to touch the disk on each and every log
> event. (Async Appenders use ArrayBlockingQueue internally and do not need
> the disruptor jar on the classpath.)"
> In the case of an abnormal termination of the jvm (e.g. a native thread
> references an invalid memory location causing a segmentation fault), the
> above statement would not hold true as the contents of the buffer would be
> lost depending on whether the shutdown hooks were called or not. Is this a
> reasonable assumption?

Yes, more or less: if you get a segfault it is safe to assume that all data
that was only in memory and not on disk is now lost. But bear in mind that
shutdown hooks are only called when the JVM _shuts down_. They won't be
called when you get a segfault.

> Also for Asynchronous Appenders, ensuring that their buffers are flushed
> relies on the fact that shutdown hooks are invoked, is this also correct?

No, shutdown hooks are not necessary. Async Appenders (and Async Loggers)
will simply signal to the underlying appender for each log event whether
this event is the "end of a batch of events". (False if there are still
other events remaining in the queue, true if the current event is the last
one in the queue.)
This allows the underlying appender to avoid unnecessary calls to flush()
the buffer. However, the buffer _will_ be flushed at the end of a batch.
This does not rely on shutdown hooks. If your application somehow puts log
events in the queue at a rate that the queue is never empty, the
underlying appender
will still flush every time the buffer is full. Either way, shutdown hooks
don't come into play.

Regards, -Remko

Thanks for your opinion on these matters
> Regards
> Peter McCarthy

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message