|
What this is
Other links
The source code// Copyright 1996-1999, International Business Machines // Corporation. All Rights Reserved. // Copyright 2000, Ceki Gulcu. All Rights Reserved. // See the LICENCE file for the terms of distribution. package org.apache.log4j.performance; import org.apache.log4j.Category; import org.apache.log4j.xml.DOMConfigurator; import org.apache.log4j.NDC; import org.apache.log4j.performance.NOPWriter; /** Measure the performance of logging.
The results of the measurements (should) show that:
burstLen log
requests. The default value of this constant is 100. */
static int burstLen = 100;
static int DELAY_MULT = 1000/burstLen;
static Category cat = Category.getInstance("A0123456789.B0123456789.C0123456789");
static
void Usage(String msg) {
System.err.println(msg);
System.err.println(
"Usage: java "+Logging.class.getName()+" confFile runLength [delay] [burstLen]\n"+
" confFile is an XML configuration file and\n"+
" runLength (integer) is the length of test loop.\n"+
" delay is the time in millisecs to wait every bustLen log requests.");
System.exit(1);
}
/**
Usage: java org.apache.log4j.performance.Logging confFile runLength [delay] [burstLen]
This application just prints the average time it took to log. */ public static void main(String argv[]) { if(argv.length == 2) init(argv[0], argv[1], null, null); else if( argv.length == 4) init(argv[0], argv[1], argv[2], argv[3]); else Usage("Wrong number of arguments."); NDC.push("some context"); double delta; String msg = "ABCDEGHIJKLMNOPQRSTUVWXYZabcdeghijklmnopqrstuvwxyz1234567890"; if(delay <= 0) delta = NoDelayLoop(cat, msg); else delta = DelayedLoop(cat, msg); System.out.print((int)delta); Category.shutdown(); } /** Program wide initialization method. */ static void init(String configFile, String runLengthStr, String delayStr, String burstLenStr) { try { runLength = Integer.parseInt(runLengthStr); if(delayStr != null) { delay = Integer.parseInt(delayStr); } if(delayStr != null) { burstLen = Integer.parseInt(burstLenStr); DELAY_MULT = 1000/burstLen; } } catch(java.lang.NumberFormatException e) { e.printStackTrace(); } DOMConfigurator.configure(configFile); } static double NoDelayLoop(Category category, String msg) { long before = System.currentTimeMillis(); for(int i = 0; i < runLength; i++) { category.info(msg); } return ((System.currentTimeMillis() - before)*1000.0)/runLength; } static double DelayedLoop(Category category, String msg) { long before = System.currentTimeMillis(); int j = 0; Thread currentThread = Thread.currentThread(); for(int i = 0; i < runLength; i++) { category.info(msg); if(j++ == burstLen) { j = 0; try{currentThread.sleep(delay);}catch(Exception e){} } } double actualTime = ((System.currentTimeMillis()-before)*1000.0/runLength); System.out.println("actual time: "+actualTime); return (actualTime - delay*DELAY_MULT); } } |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.