Thursday, December 1, 2011

log4cxx is quite slow

log4cxx is an open source logging library which is used quite often in many projects by many firms, however, when trying to measure some latency  recently, I noticed this library is too slow to be used in a low-latency project. So what factor contributes to the slowness?


Think about it, if you are about to write a logger which need to support multi-writer/one-reader, what will you do?  log4cxx won't be too much different!

First, it need to create a record of what need to be logged, regardless of whether the record resource is from a memory pool or from raw memory, it need some time to do this;

Second, it needs to format the log data into some string format and save in the record created in the first step, again, this step is not trivial, time-wise;

Third,  it need to push this records into a queue and then the reader thread can then write it to a log file, will this enqueue need some kind of lock?  You bet.

In the next post, we will talk about some fast loggers.

No comments:

Post a Comment