8

I work on a low-latency trading application. We'd like to increase the amount of lof4j logging that we write to file, whilst minimising the impact on our end-to-end processing time.

What is the recommended way of doing this? I think FileAppender.append is synchronous, so we need to do something a bit smarter than that....

Phil Harvey
  • 1,160
  • 4
  • 13
  • 19
  • 1
    "you think"? Have you verified that it's actually a bottleneck? That should be easy enough to do. – Joachim Sauer Feb 10 '11 at 12:53
  • 2
    Hint: check [the JavaDoc](http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/FileAppender.html#getBufferedIO()) for the `BufferedIO` option. – Joachim Sauer Feb 10 '11 at 12:54

3 Answers3

9

Yes, the appenders are synchronous. You want something like this:

http://www.spartanjava.com/2009/asynchronous-logging-with-log4j/

Danny Thomas
  • 1,879
  • 1
  • 18
  • 32
4

bear in mind that AsyncAppender adds a thread per appender & that increasing the amount of logging you do may mean a substantial increase in the amount of string concatentation going on which often means a substantial amount of string processing/munging/formatting which can be pretty expensive (relative to the latency involved in a low latency trading app anyway).

Matt
  • 8,367
  • 4
  • 31
  • 61
3

If you need to log from a multithreaded application slf4j and its implementation logback are much better choice.

Boris Pavlović
  • 63,078
  • 28
  • 122
  • 148