Hi Prashant,
Sorry if the article phrasing was confusing. As Ralph said, the point of async
logging is to do the (potentially time-consuming) I/O in a separate thread, so
when your app calls logger.info("..."), the method returns immediately.
You mention buffers, which is another way to improve performance. With buffered
I/O, the idea is to do the I/O for multiple log events together instead of for
each individual log event. Instead of writing directly to disk, we write to an
in-memory buffer which gets flushed to disk when the buffer is full.
Now, we were able to make an interesting improvement when bufferedIO is
combined with async logging. In addition to flushing the buffer to disk when
full, we _also_ flush to disk when the async queue is empty. So, when receiving
a burst of events, they are likely to get buffered in memory and only flushed
to disk once after the last event. This combines the efficiency of buffered I/O
with the convenience of having all your events on disk immediately.
See also http://java.dzone.com/articles/smart-batching
Best regards,
Remko
Sent from my iPhone
> On 2014/06/11, at 2:09, "Ulavapalli, Prashant"
> <[email protected]> wrote:
>
> Or is it something to do with this..
>
>
> http://www.grobmeier.de/log4j-2-performance-close-to-insane-20072013.html#.U5c7MpRdUUU
>
>
> "One nice little detail I should mention is that both Async Loggers and Async
> Appenders fix something that has always bothered me in Log4j-1.x, which is
> that they will flush the buffer after logging the last event in the queue.
> With Log4j-1.x, if you used buffered I/O, you often could not see the last
> few log events, as they were still stuck in the memory buffer. Your only
> option was setting immediateFlush to true, which forces disk I/O on every
> single log event and has a performance impact. With Async Loggers and
> Appenders in Log4j-2.0 your log statements are all flushed to disk, so they
> are always visible, but this happens in a very efficient manner."
>
> Can somebody confirm.
>
> Thanks
> -prashant
>
>
> From: <Ulavapalli>, Prashant Ulavapalli
> <[email protected]<mailto:[email protected]>>
> Reply-To: Log4J Users List
> <[email protected]<mailto:[email protected]>>
> Date: Tuesday, June 10, 2014 at 10:05 AM
> To: "[email protected]<mailto:[email protected]>"
> <[email protected]<mailto:[email protected]>>
> Subject: log4j2 Async Loggers
>
> Hi,
>
> I am trying to configure async loggers for my application using log4j2. When
> I log my events .. They still seem to be synchronous. I see the log even
> flushed to the file immediately. I would have assumed, async loggers will
> hold the events till the buffer is full before flushing. How do I confirm if
> is actually doing asynchronous logging. Or please correct if I am missing
> something.
>
> In my startup I have (for all async loggers).
>
> -DLog4jContextSelector=org.apache.logging.log4j.core.async.AsyncLoggerContextSelector
> Also, have the disruptor 3.2.1 in the class path. I use slf4j and use the
> bridge to log to log4j2
> This is my log4j2.xml (just using the one which the
> http://logging.apache.org/log4j/2.x/manual/appenders.html provides)
>
>
> 1. <?xml version="1.0" encoding="UTF-8"?>
> 2. <Configuration status="warn" name="MyApp" packages="">
> 3. <Appenders>
> 4. <RollingRandomAccessFile name="RollingRandomAccessFile"
> fileName="logs/app.log"
> 5. filePattern="logs/$${date:yyyy-MM}/app-%d{MM-dd-yyyy}-%i.log.gz"
> immediateFlush="false">
> 6. <PatternLayout>
> 7. <Pattern>%d %p %c{1.} [%t] %m%n</Pattern>
> 8. </PatternLayout>
> 9. <Policies>
> 10. <TimeBasedTriggeringPolicy />
> 11. <SizeBasedTriggeringPolicy size="250 MB"/>
> 12. </Policies>
> 13. </RollingRandomAccessFile>
> 14. </Appenders>
> 15. <Loggers>
> 16. <Root level="error">
> 17. <AppenderRef ref="RollingRandomAccessFile"/>
> 18. </Root>
> 19. </Loggers>
> 20. </Configuration>
>
> Thanks
> -prashant
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]