java - log4j performance -


I'm developing a web app, and some information logs to help me improve the app and follow it Want to do (I'm using Tomcat 6)

First I thought I would use stringbillers, add logs to them and one task would continue them in the database like every 2 minutes. Since I was concerned about the performance of the out-the-box logging system, then I did some tests. Especially with log4j

Here is my code:

Main.Java

  Public static zero main (string [] args) {thread [] thread = new thread [Lumbertread.readsmbar]; (Int i = 0; i & lt; LoggerThread.threadsNumber; ++ i) {thread [i] = new thread (new logreadthread ("name -" + i)); } LoggerThread.startTimestamp = System.currentTimeMillis (); For (int i = 0; i & lt; LoggerThread.threadsNumber; ++ i) {thread [i] .start (); }  

LoggerThread.java

  Public class loggerThread executes Runnable {public static int threadsNumber = 10; Public static prolonged start stumps; Private static counter counter = 0; The name of the private string; Public logger (string name) {this.name = name; } Private logger log = logger.getlogger (this.getClass ()); @ Override Public Wide Run (for (IntiI = 0; I & lt; 10000; ++ i) {log.info (name + ":" + i); if (I == 99 99) {int C = increaseCounter (); if (C == thread number) {System.out.println ("Elapsed time:" + (SystemCurrenttime milliseconds) - startimstep));}}}} Private synchronized int mounting counter ( ) {Return ++ counter;}}}  

log4j.properties

  log4j.logger.main.LoggerThread = debug, f log4j.appender.f = Org.apache.log4j.RollingFileAppender log4j.appender.f.layout = org.apache.log4j.PatternLayout log4j.appender.f.layout.ConversionPattern =% d {ABSOLUTE}% 5p% c {1}:% L -% M% n log4j.appender F.File = c: /logs/logging.log log4j.appender.f.MaxFileSiz E = 15000Kb log4j.appender.f.MaxBackupIndex = 50  

I think log4j is a very common configuration. First of all I used Log4J 1.2.14 and I realized That was a new version, so I went to 1.2.16

The figures here (all in milliseconds)

LoggerTrade. Threadsnumber = 10

  1.2.14: 4235, 4267, 4328, 4282, 1.2.16: 2780, 2781, 2797, 2781  
< P> LoggerTrade. ThreadsNumber = 100

  1.2.14: 41312, 41014, 42251, 1.2.16: 25606, 2572 9, 25922  

me It seems that it is very fast, do not forget that in every cycle the run method does not just enter the file, it has to add the string to (name + ":" + i) , and if Check I = 998 99).

When the number of threads is 10, then logging 100.000 and if the test and coincidence when it is 100, then 1.000.000 logging is done and if I have read somewhere between the test and the insertion (JVM stringbirder Does not combine to use the antenna, simple connection).

Did I miss something? Am I doing something wrong? Did I forget any factor and reduce performance? If these figures are correct, then I think I do not have to worry about the performance of LO-4J, even if I log in heavily, do I?

I have read: "In fact, the usual cost of logging is approximately 300 300 microsounds." Is this correct? Yes, Log4J is known fast, due to the conscious effort of its implementers.

See also the "Performance" section at the end of this.


Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -