logging-log4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From c...@apache.org
Subject cvs commit: logging-log4j/tests/src/java/org/apache/log4j/performance package.html build.xml NewVsSetLen.java NOPWriter.java logging Loop.java SystemTime.java NullAppender.java
Date Mon, 06 Sep 2004 14:47:24 GMT
ceki        2004/09/06 07:47:24

  Added:       tests/src/java/org/apache/log4j/performance package.html
                        build.xml NewVsSetLen.java NOPWriter.java logging
                        Loop.java SystemTime.java NullAppender.java
  Log:
  Moved files from src/java/o/a/l/performance to tests/src/java/o/a/l/performance
  
  Revision  Changes    Path
  1.1                  logging-log4j/tests/src/java/org/apache/log4j/performance/package.html
  
  Index: package.html
  ===================================================================
  <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
  <html> <head>
  <title></title>
  </head>
  
    <body>
  
      <p>Package to measure the performance of the different log4j
        components.
      </p>
  
      <p><b> <font color="#FF2222">The
        <code>org.apache.log4j.performance</code> package is intended
        for internal use only.</font> Consequently, the classes in this
        package are not included in the <em>log4j.jar</em> file.</b>
      </p>
  
    </body> 
  </html>
  
  
  
  1.1                  logging-log4j/tests/src/java/org/apache/log4j/performance/build.xml
  
  Index: build.xml
  ===================================================================
  <!-- This build file is intended to be launched from $LOG4J_HOME/tests -->
  
  	<project name="log4j-tests" default="usage" basedir="." >
  
    <property file="build.properties"/>
    
  	
    <!-- The base directory relative to which most targets are built -->
    <property name="base" value="."/>
   
    <!-- The directory where source files are stored. -->
  	
    <property name="project.source.home" value="../src/java/"/>
    <property name="project.classes.home" value="../dist/classes/"/>
    <property name="examples.classes" value="../examples/classes/"/>
    <property name="tests.source.home" value="${base}/tests/src/java/"/>
  
    <property name="longrun" value="1000000"/>
    <property name="shortrun" value="10000"/>
  
    <path id="perf.classpath">
      <pathelement location="${project.source.home}"/>
      <pathelement location="${project.classes.home}"/>
      <pathelement location="${examples.classes}"/>
      <pathelement location="${tests.source.home}"/>
      <pathelement location="./classes"/>
    </path>
    
  	<target name="usage">
  		<echo>
  	      These are the targets supported by this ANT build scpript:
  	      
  		  null - run performance tests using NullAppender	
  	      
  	      runAll - run all available tests
  	    </echo>
  	  </target>
  		
  	<target name="loop">
  		<java classname="org.apache.log4j.performance.Loop" 
  			  fork="yes" failonerror="yes">
  			<classpath refid="perf.classpath"/>
  			<sysproperty key="pattern" value="${pattern}"/>
  			<arg line="${runLen} ${configFile}"/>
  		</java>
  	</target>
  
   	<target name="null-loop">
   	  <echo message="Pattern is ${pattern}"/> 	
        <antcall target="loop">
     	    <param name="pattern" value="${pattern}"/>
     	    <param name="runLen" value="${longrun}"/>
   	    <param name="configFile" value="input/performance/null-appender1.xml"/>
       </antcall>
  	</target>	
  		
  	<target name="short-null-loop">
  	  <echo message="Pattern is ${pattern}"/> 	
  	  <antcall target="loop">
  	  <param name="pattern" value="${pattern}"/>
  	  <param name="runLen" value="${shortrun}"/>
  	  <param name="configFile" value="input/performance/null-appender.xml"/>
  	 </antcall>
  	</target>		
  		
  	<target name="null">
  		 <antcall target="null-loop">
  		   <param name="pattern" value=""/>
  		 </antcall>
  		 <antcall target="null-loop">
  		   <param name="pattern" value="%p - %m%n"/>
  		 </antcall>
  		 <antcall target="null-loop">
  		   <param name="pattern" value="%-5p - %m%n"/>
  		 </antcall>
  		 <antcall target="null-loop">
  		   <param name="pattern" value="%r [%t] %-5p %c{2} %x - %m%n"/>
  		 </antcall>
  		 <antcall target="null-loop">
  		   <param name="pattern" value="%r [%t] %-5p %.10c %x - %m%n"/>
  		 </antcall>
  		 <antcall target="null-loop">
  		   <param name="pattern" value="%r [%t] %-5p %.20c %x - %m%n"/>
  		 </antcall>
  		 <antcall target="null-loop">
  		   <param name="pattern" value="%r [%t] %-5p %c - %m%n"/>
  		 </antcall>
  		 <antcall target="null-loop">
  		   <param name="pattern" value="%d{ISO8601} [%t] %-5p %c %x - %m%n"/>
  		 </antcall>
  		 <antcall target="null-loop">
  		   <param name="pattern" value="%d{yyyy-MM-dd HH:mm:ss,SSS} [%t] %-5p %c %x - %m%n"/>
  		 </antcall>
  		 <antcall target="short-null-loop">
  		   <param name="pattern" value="%l - %m%n"/>
  		 </antcall>
  		 <antcall target="short-null-loop">
  		   <param name="pattern" value="%C.%M.%L - %m%n"/>
  		 </antcall>
  
  	 </target>	
    
  </project>
  
  
  1.1                  logging-log4j/tests/src/java/org/apache/log4j/performance/NewVsSetLen.java
  
  Index: NewVsSetLen.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software
   * License version 1.1, a copy of which has been included with this
   * distribution in the LICENSE.txt file.  */
  
  package org.apache.log4j.performance;
  
  /**
  
     This program compares the cost of creating a new StringBuffer and
     converting it to a String versus keeping the same StringBuffer,
     setting its size to zero and then converting it to String.
  
     <p>The table below gives some figures.
  
  <p>   <table border="1" cellpadding="4">
     <tr BGCOLOR="#33CCFF">
       <th BGCOLOR="#CCCCCC" rowspan="2">Total Message length
       <th colspan="2" align="center">0
       <th colspan="2" align="center">1
       <th colspan="2" align="center">2
       <th colspan="2" align="center">4
       <th colspan="2" align="center">8
     </tr>
  
     <tr BGCOLOR="#3366FF">
       <td>New Buffer</td> <td>setLength</td> 
       <td>New Buffer</td> <td>setLength</td>
       <td>New Buffer</td> <td>setLength</td>
       <td>New Buffer</td> <td>setLength</td>
       <td>New Buffer</td> <td>setLength</td>
     </tr>
  
     <tr align="right"> 
     <td BGCOLOR="#CCCCCC">256 
     <td>33 <td>22 
     <td>34 <td>22
     <td>34 <td>22
     <td>34 <td>22 
     <td>33 <td>23
     </tr>
  
     <tr align="right"> 
     <td BGCOLOR="#CCCCCC">1024 
     <td>58 <td>41
     <td>59 <td>45
     <td>59 <td>48
     <td>59 <td>51 
     <td>60 <td>44
     </tr>
  
     <tr align="right"> 
     <td BGCOLOR="#CCCCCC">4096 
     <td>146 <td>132
     <td>138 <td>132
     <td>144 <td>126
     <td>142 <td>132
     <td>136 <td>132 
     </tr>
  
     <tr align="right"> 
     <td BGCOLOR="#CCCCCC">16384 
     <td>617 <td>593 
     <td>593 <td>609
     <td>601 <td>617
     <td>601 <td>632 
     <td>593 <td>632
     </tr>
  
     <tr align="right"> 
     <td BGCOLOR="#CCCCCC">65536 
     <td>3218 <td>3281
     <td>3093 <td>3125 
     <td>3125 <td>3156
     <td>3125 <td>3281 
     <td>3062 <td>3562
     </tr>
  
     <tr align="right"> 
     <td BGCOLOR="#CCCCCC">262144 
     <td>14750 <td>15125
     <td>14000 <td>15500 
     <td>14000 <td>16125 
     <td>14000 <td>18000 
     <td>14000 <td>21375 
     </tr>
  
     <tr align="right"> 
     <td BGCOLOR="#CCCCCC">1048576 
     <td>87500 <td>80000
     <td>60500 <td>82000 
     <td>57000 <td>93000 
     <td>57500 <td>118500 
     <td>57500 <td>168500 
     </tr>
  
     <caption ALIGN="BOTTOM">Performance comparisons of new buffer
     creation versus setLength(0) approach for various message sizes and
     secondary loop lengths.
     </caption>
     </table>
  
     <p>The tests copy a message to a destination string buffer and then
     copy a 256 character buffer to another buffer the number of times
     as specified by the secondary loop length.
  
  
     <p>The <code>setLength(0)</code> method is usually faster. However,
     after copying a large string it becomes slow even when copying
     small strings.
  
  
     <p>This is due to a peculiarity in the <code>copy</code> method in
     StringBuffer class which creates a character array of the same
     length as the old buffer even if the vast majority of those
     characters are unused. 
  
     <p>The tests were performed on Linux using IBM's JDK 1.1.8.
  
     <p>The test script is a crude model of what might happen in
     reality. If you remain unconvinced of its results, then please send
     your alternative measurement scenario.
  
     
  
     
  */
  public class NewVsSetLen {
  
    static String s;
  
    static int BIGBUF_LEN = 1048576;
    static int SBUF_LEN = 256;
    static int RUN_LENGTH = BIGBUF_LEN/4;
  
    static char[] sbuf = new char[SBUF_LEN];
    static char[] bigbuf = new char[BIGBUF_LEN];
  
    {
      for(int i = 0; i < SBUF_LEN; i++) {
        sbuf[i] = (char) (i);
      }
  
      for(int i = 0; i < BIGBUF_LEN; i++) {
        bigbuf[i] = (char) (i);
      }
    }
  
  
    static
    public 
    void main(String[] args) {    
   
      int t;
  
      for(int len = SBUF_LEN; len <= BIGBUF_LEN; len*=4, RUN_LENGTH /= 4) {
        System.out.println("<td>"+len+"\n");
        for(int second = 0; second < 16;) {
  	System.out.println("SECOND loop="+second +", RUN_LENGTH="
  			   +RUN_LENGTH+", len="+len);
  	t = (int)newBuffer(len, second);
  
  	System.out.print("<td>" + t);
  	t = (int)setLen(len, second);
  	System.out.println(" <td>" + t + " \n");
  	if(second == 0) {
  	  second = 1;
  	} else {
  	  second *= 2;
  	}
        }
      }
      
    }
  
    static
    double newBuffer(int size, int second) {    
      long before = System.currentTimeMillis();
  
      for(int i = 0; i < RUN_LENGTH; i++) {
        StringBuffer buf = new StringBuffer(SBUF_LEN);
        buf.append(sbuf, 0, sbuf.length);
        buf.append(bigbuf, 0, size);
        s = buf.toString();
      }
  
      for(int x = 0; x <  second; x++) {
        StringBuffer buf = new StringBuffer(SBUF_LEN);
        buf.append(sbuf, 0, SBUF_LEN);
        s = buf.toString();
      }
      return (System.currentTimeMillis() - before)*1000.0/RUN_LENGTH;    
    }
  
    static
    double setLen(int size, int second) {
      long before = System.currentTimeMillis();
  
      StringBuffer buf = new StringBuffer(SBUF_LEN);
  
      for(int i = 0; i < RUN_LENGTH; i++) {
        buf.append(sbuf, 0, sbuf.length);
        buf.append(bigbuf, 0, size);
        s = buf.toString();
        buf.setLength(0);
      }
  
      for(int x = 0; x < second; x++) {
        buf.append(sbuf, 0, SBUF_LEN);
        s = buf.toString();
        buf.setLength(0);
      }
      return (System.currentTimeMillis() - before)*1000.0/RUN_LENGTH;    
    }  
  }
  
  
  
  1.1                  logging-log4j/tests/src/java/org/apache/log4j/performance/NOPWriter.java
  
  Index: NOPWriter.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software
   * License version 1.1, a copy of which has been included with this
   * distribution in the LICENSE.txt file.  */
  
  package org.apache.log4j.performance;
  
  import java.io.Writer;
  import java.io.IOException;
  
  /**
   * <p>Extends {@link Writer} with methods that return immediately
   * without doing anything. This class is used to measure the cost of
   * constructing a log message but not actually writing to any device.
   * </p>
  
   * <p><b> <font color="#FF2222">The
   * <code>org.apache.log4j.performance.NOPWriter</code> class is
   * intended for internal use only.</font> Consequently, it is not
   * included in the <em>log4j.jar</em> file.</b> </p>
   *  
   * @author Ceki G&uuml;lc&uuml; 
   * */
  public class NOPWriter extends Writer {
  
    public void write(char[] cbuf) throws IOException {}
  
    public void write(char[] cbuf, int off, int len) throws IOException {}
  
  
    public void write(int b) throws IOException {}
  
    public void write(String s) throws IOException {} 
  
    public void write(String s, int off, int len) throws IOException {} 
  
    public void flush() throws IOException {
    }
  
    public void close() throws IOException {
      System.err.println("Close called.");
    }
  }
  
  
  
  1.1                  logging-log4j/tests/src/java/org/apache/log4j/performance/logging
  
  Index: logging
  ===================================================================
  
  # Test the performance of logging
  
  # Set the variable REMOTE_HOST to the appropriate value for the
  # to perform SocketAppender measurements.
  
  
  LCF=logging.lcf
  TARGET_FILE=test
  DELAY=1000
  PORT=12345
  
  # The results are somehow RUN_LENGTH dependent. Keep RUN_LENGTH the
  # same to be able to compare results
  LONGRUN=100000
  SHORTRUN=5000
  
  #LONGRUN=1
  #SHORTRUN=2
  
  
  declare -i start=$1
  
  #D=-Dlog4j.configDebug
  # -------------------------------------------------------------
  function multiRun() {
    lcf=$1
    loopLength=$2
    msg=$3
    runLength=$4
      
    echo -n "Results: "
    
    declare -i total
    declare -i i
    i=0
    total=0
    
    while [ $i -lt $loopLength ]
    do
      i=$i+1
      x=$(java $D org.apache.log4j.performance.Logging  $lcf $runLength $5)
      if [ $x -lt 100 ]; then
        echo -n " "
      fi  
      echo -n "$x "
      total=$total+$x
    done
  
    while [ $i -lt 8 ]
    do
      i=$i+1
      echo -n "    "
    done  
    
    average=$[ $total / $loopLength ]
    echo "- average $average $msg"
  
  }
  # =============================================
  # Echo to $LCF
  # =============================================
  function lecho {
   echo $* >> $LCF
  }
  # =============================================
  
  
  echo "--------------" $(date) "---------------" 
  
  
  echo echo "Starting performance measures. This make take a few minutes...."
  
  declare -i TEST
  
  echo; echo "NullAppender:"; echo
  
  TEST=1
  if [ $TEST -ge $start ]; then
     multiRun xml/logging$TEST.xml 4 "SimpleLayout"  $LONGRUN 
  fi
  
  TEST=2
  if [ $TEST -ge $start ]; then
     format="%p - %m%n"
     multiRun xml/logging$TEST.xml 4 "PatternLayout \"$format\""  $LONGRUN 
  fi
  
  TEST=3
  if [ $TEST -ge $start ]; then
     format="%-5p - %m%n"
     multiRun xml/logging$TEST.xml 4 "PatternLayout \"$format\""  $LONGRUN 
  fi
  
  TEST=4
  if [ $TEST -ge $start ]; then
     multiRun xml/logging$TEST.xml 4 "TTCCLayout/RELATIVE"  $LONGRUN 
  fi
  
  TEST=5
  if [ $TEST -ge $start ]; then
     format="%r [%t] %-5p %c{2} %x - %m%n"
     multiRun xml/logging$TEST.xml 4 "PatternLayout \"$format\""  $LONGRUN 
  fi
  
  TEST=6
  if [ $TEST -ge $start ]; then
     format="%r [%t] %-5p %.10c %x - %m%n"
     multiRun xml/logging$TEST.xml 4 "PatternLayout \"$format\""  $LONGRUN 
  fi
  
  TEST=7
  if [ $TEST -ge $start ]; then
     format="%r [%t] %-5p %.20c %x - %m%n"
     multiRun xml/logging$TEST.xml 4 "PatternLayout \"$format\""  $LONGRUN 
  fi
  
  TEST=8
  if [ $TEST -ge $start ]; then
     format="%r [%t] %-5p %c - %m%n"
     multiRun xml/logging$TEST.xml 4 "PatternLayout \"$format\""  $LONGRUN 
  fi
  
  TEST=9
  if [ $TEST -ge $start ]; then
     multiRun xml/logging$TEST.xml 4 "TTCCLayout/ISO8601"  $LONGRUN 
  fi
  
  TEST=10
  if [ $TEST -ge $start ]; then
     format="%d{ISO8601} [%t] %-5p %c %x - %m%n"
     multiRun xml/logging$TEST.xml 4 "PatternLayout \"$format\""  $LONGRUN 
  fi
  
  TEST=11
  if [ $TEST -ge $start ]; then
     format="%d{yyyy-MM-dd HH:mm:ss,SSS} [%t] %-5p %c %x - %m%n"
     multiRun xml/logging$TEST.xml 4 "PatternLayout \"$format\""  $LONGRUN 
  fi
  
  TEST=12
  if [ $TEST -ge $start ]; then
     format="%l - %m%n"
     multiRun xml/logging$TEST.xml 4 "PatternLayout \"$format\""  $SHORTRUN 
  fi
  
  TEST=13
  if [ $TEST -ge $start ]; then
     format="%C.%M.%L - %m%n"
     multiRun xml/logging$TEST.xml 4 "PatternLayout \"$format\""  $SHORTRUN 
  fi
  
  echo 
  echo "FileAppender: "
  echo
  
  
  TEST=100
  if [ $TEST -ge $start ]; then
     multiRun xml/logging$TEST.xml 8 "SimpleLayout"  $LONGRUN 
  fi
  
  TEST=101
  if [ $TEST -ge $start ]; then
     format="%p - %m%n"
     multiRun xml/logging$TEST.xml 8 "PatternLayout \"$format\""  $LONGRUN    
  fi
  
  TEST=102
  if [ $TEST -ge $start ]; then
     multiRun xml/logging$TEST.xml 8 "TTCC/RELATIVE" $LONGRUN 
  fi
  
  TEST=103
  if [ $TEST -ge $start ]; then
     format="%r [%t] %-5p %c - %m%n"
     multiRun xml/logging$TEST.xml 8 "PatternLayout \"$format\""  $LONGRUN 
  fi
  
  TEST=104
  if [ $TEST -ge $start ]; then
     multiRun xml/logging$TEST.xml 8 "TTCCLayout/ISO8601"  $LONGRUN 
  fi
  
  
  TEST=105
  if [ $TEST -ge $start ]; then
     format="%d{ISO8601} [%t] %-5p %c %x - %m%n"
     multiRun xml/logging$TEST.xml 8 "PatternLayout \"$format\""  $LONGRUN 
  fi
  
  TEST=106
  if [ $TEST -ge $start ]; then
     format="%d{yyyy-MM-dd HH:mm:ss,SSS} [%t] %-5p %c %x - %m%n"
     multiRun xml/logging$TEST.xml 8 "PatternLayout \"$format\""  $LONGRUN    
  fi
  
  echo ================== 107 ===============================
  TEST=107
  if [ $TEST -ge $start ]; then
     format="%l - %m%n"
     multiRun xml/logging$TEST.xml 8 "PatternLayout \"$format\""  $SHORTRUN   
  fi
  
  echo -------------------------------------
  echo "FileAppender: ImmediateFlush=false"
  echo -------------------------------------
  
  TEST=200
  if [ $TEST -ge $start ]; then
     multiRun xml/logging$TEST.xml 8 "SimpleLayout"  $LONGRUN 
  fi
  
  TEST=201
  if [ $TEST -ge $start ]; then
     format="%p - %m%n"
     multiRun xml/logging$TEST.xml 8 "PatternLayout \"$format\""  $LONGRUN    
  fi
  
  TEST=202
  if [ $TEST -ge $start ]; then
     multiRun xml/logging$TEST.xml 8 "TTCC/RELATIVE" $LONGRUN 
  fi
  
  TEST=203
  if [ $TEST -ge $start ]; then
     format="%r [%t] %-5p %c - %m%n"
     multiRun xml/logging$TEST.xml 8 "PatternLayout \"$format\""  $LONGRUN 
  fi
  
  TEST=204
  if [ $TEST -ge $start ]; then
     multiRun xml/logging$TEST.xml 8 "TTCCLayout/ISO8601"  $LONGRUN 
  fi
  
  TEST=205
  if [ $TEST -ge $start ]; then
     format="%d{ISO8601} [%t] %-5p %c %x - %m%n"
     multiRun xml/logging$TEST.xml 8 "PatternLayout \"$format\""  $LONGRUN 
  fi
  
  TEST=206
  if [ $TEST -ge $start ]; then
     format="%d{yyyy-MM-dd HH:mm:ss,SSS} [%t] %-5p %c %x - %m%n"
     multiRun xml/logging$TEST.xml 8 "PatternLayout \"$format\""  $LONGRUN    
  fi
  
  TEST=207
  if [ $TEST -ge $start ]; then
     format="%l - %m%n"
     multiRun xml/logging$TEST.xml 8 "PatternLayout \"$format\""  $SHORTRUN   
  fi
  
  echo -------------------------------------
  echo "FileAppender: BufferedIO=true"
  echo -------------------------------------
  
  TEST=220
  if [ $TEST -ge $start ]; then
     multiRun xml/logging$TEST.xml 8 "SimpleLayout"  $LONGRUN 
  fi
  
  TEST=221
  if [ $TEST -ge $start ]; then
     format="%p - %m%n"
     multiRun xml/logging$TEST.xml 8 "PatternLayout \"$format\""  $LONGRUN    
  fi
  
  TEST=222
  if [ $TEST -ge $start ]; then
     multiRun xml/logging$TEST.xml 8 "TTCC/RELATIVE" $LONGRUN 
  fi
  
  TEST=223
  if [ $TEST -ge $start ]; then
     format="%r [%t] %-5p %c - %m%n"
     multiRun xml/logging$TEST.xml 8 "PatternLayout \"$format\""  $LONGRUN 
  fi
  
  TEST=224
  if [ $TEST -ge $start ]; then
     multiRun xml/logging$TEST.xml 8 "TTCCLayout/ISO8601"  $LONGRUN 
  fi
  
  TEST=225
  if [ $TEST -ge $start ]; then
     format="%d{ISO8601} [%t] %-5p %c %x - %m%n"
     multiRun xml/logging$TEST.xml 8 "PatternLayout \"$format\""  $LONGRUN 
  fi
  
  TEST=226
  if [ $TEST -ge $start ]; then
     format="%d{yyyy-MM-dd HH:mm:ss,SSS} [%t] %-5p %c %x - %m%n"
     multiRun xml/logging$TEST.xml 8 "PatternLayout \"$format\""  $LONGRUN    
  fi
  
  TEST=227
  if [ $TEST -ge $start ]; then
     format="%l - %m%n"
     multiRun xml/logging$TEST.xml 8 "PatternLayout \"$format\""  $SHORTRUN   
  fi
  
  
  echo ==================================
  echo Async appender
  echo ==================================
  
  TEST=300
  if [ $TEST -ge $start ]; then
     multiRun xml/logging$TEST.xml 8 "SimpleLayout"  $LONGRUN   
  fi
  
  TEST=301
  if [ $TEST -ge $start ]; then
     format="%p - %m%n"
     multiRun xml/logging$TEST.xml 8 "PatternLayout \"$format\""  $LONGRUN   
  fi
  
  TEST=302
  if [ $TEST -ge $start ]; then
     multiRun xml/logging$TEST.xml 8 "TTCCLayout/RELATIVE"  $LONGRUN   
  fi
  
  TEST=303
  if [ $TEST -ge $start ]; then
     format="%r [%t] %-5p %c - %m%n"
     multiRun xml/logging$TEST.xml 8 "PatternLayout \"$format\""  $LONGRUN   
  fi
  
  TEST=304
  if [ $TEST -ge $start ]; then
     multiRun xml/logging$TEST.xml 8 "TTCCLayout/ISO8601"  $LONGRUN   
  fi
  
  
  TEST=305
  if [ $TEST -ge $start ]; then
     format="%d{ISO8601} [%t] %-5p %c %x - %m%n"
     multiRun xml/logging$TEST.xml 8 "PatternLayout \"$format\""  $LONGRUN   
  fi
  
  TEST=306
  if [ $TEST -ge $start ]; then
     format="%d{yyyy-MM-dd HH:mm:ss,SSS} [%t] %-5p %c %x - %m%n"
     multiRun xml/logging$TEST.xml 8 "PatternLayout \"$format\""  $LONGRUN   
  fi
  
  TEST=307
  if [ $TEST -ge $start ]; then
     format="%l - %m%n"
     multiRun xml/logging$TEST.xml 8 "PatternLayout \"$format\""  $SHORTRUN   
  fi
  
  
  # ===============================================================
  #  Remote logging
  # ===============================================================
  TEST=1000
  #RL=1000
  RL=10000
  if [ $TEST -ge $start ]; then
     java org.apache.log4j.performance.Logging xml/logging$TEST.xml $RL 100 100
     #multiRun 4 "SocketAppender" $SHORTRUN $DELAY
  fi
  
  
  TEST=1001
  #RL=1000
  RL=30000
  if [ $TEST -ge $start ]; then
     java org.apache.log4j.performance.Logging xml/logging$TEST.xml $RL 
     #multiRun 4 "SocketAppender" $SHORTRUN $DELAY
  fi
  
  
  
  
  
  1.1                  logging-log4j/tests/src/java/org/apache/log4j/performance/Loop.java
  
  Index: Loop.java
  ===================================================================
  /*
   * Copyright 1999,2004 The Apache Software Foundation.
   * 
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * 
   *      http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  
  package org.apache.log4j.performance;
  
  import org.apache.log4j.LogManager;
  import org.apache.log4j.Logger;
  import org.apache.log4j.joran.JoranConfigurator;
  
  /**
   * Logs in a loop a number of times and measure the elapsed time.
   * 
   * @author Ceki G&uuml;lc&uuml;
   */
  public class Loop {
  
    static int runLength;
  
    final static Logger logger = Logger.getLogger(Loop.class);
  
    public static void main(String[] args) throws Exception {
      if (args.length == 2)
        init(args[0], args[1]);
      else
        usage("Wrong number of arguments.");
  
      long res = loop(logger, "Some fix message of medium length.");
      double average = (res * 1000.0) / runLength;
      System.out.println("Loop completed in [" + res + "] milliseconds, or ["
          + average + "] microseconds per log.");
  
    }
  
    static void usage(String msg) {
      System.err.println(msg);
      System.err.println("Usage: java " + Loop.class.getName()
          + " runLength configFile");
      System.err.println("\trunLength (integer) is the length of test loop.");
      System.err.println("\tconfigFile is an XML configuration file");
  
      System.exit(1);
    }
  
    static void init(String runLengthStr, String configFile) throws Exception {
      runLength = Integer.parseInt(runLengthStr);
      JoranConfigurator jc = new JoranConfigurator();
      jc.doConfigure(configFile, LogManager.getLoggerRepository());
    }
  
    static long loop(Logger logger, String msg) {
      long before = System.currentTimeMillis();
      for (int i = 0; i < runLength; i++) {
        logger.debug(msg);
      }
      return (System.currentTimeMillis() - before);
    }
  }
  
  
  1.1                  logging-log4j/tests/src/java/org/apache/log4j/performance/SystemTime.java
  
  Index: SystemTime.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software
   * License version 1.1, a copy of which has been included with this
   * distribution in the LICENSE.txt file.  */
  
  package org.apache.log4j.performance;
  
  /**
     Measures the time required to make a System.currentTimeMillis() and
     Thread.currentThread().getName() calls.
  
     <p>On an 233Mhz NT machine (JDK 1.1.7B) the
     System.currentTimeMillis() call takes under half a microsecond to
     complete whereas the Thread.currentThread().getName() call takes
     about 4 micro-seconds.
  
  */
  public class SystemTime {
  
    static int RUN_LENGTH = 1000000;
  
    static
    public 
    void main(String[] args) {    
      double t = systemCurrentTimeLoop();
      System.out.println("Average System.currentTimeMillis() call took " + t);
  
      t = currentThreadNameloop();
      System.out.println("Average Thread.currentThread().getName() call took " 
  		       + t);
      
    }
  
    static
    double systemCurrentTimeLoop() {
      long before = System.currentTimeMillis();
      long l;
      for(int i = 0; i < RUN_LENGTH; i++) {
        l = System.currentTimeMillis();
      }
      return (System.currentTimeMillis() - before)*1000.0/RUN_LENGTH;    
    }
  
    static
    double currentThreadNameloop() {
      long before = System.currentTimeMillis();
      String t;
      for(int i = 0; i < RUN_LENGTH; i++) {
        t = Thread.currentThread().getName();
      }
      return (System.currentTimeMillis() - before)*1000.0/RUN_LENGTH;    
    }  
  }
  
  
  
  1.1                  logging-log4j/tests/src/java/org/apache/log4j/performance/NullAppender.java
  
  Index: NullAppender.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software
   * License version 1.1, a copy of which has been included with this
   * distribution in the LICENSE.txt file.  */
  
  package org.apache.log4j.performance;
  
  import org.apache.log4j.Layout;
  import org.apache.log4j.spi.LoggingEvent;
  import org.apache.log4j.AppenderSkeleton;
  
  /**
   * A bogus appender which calls the format method of its layout object
   * but does not write the result anywhere.
   *
   * <p><b> <font color="#FF2222">The
   * <code>org.apache.log4j.performance.NullAppender</code> class is
   * intended for internal use only.</font> Consequently, it is not
   * included in the <em>log4j.jar</em> file.</b> </p>
   * */
  public class NullAppender extends AppenderSkeleton {
  
    public static String s;
    public String t;
  
    public
    NullAppender() {}
  
    public
    NullAppender(Layout layout) {
      this.layout = layout;
    }
  
    public
    void close() {}
  
    public
    void doAppend(LoggingEvent event) {
      if(layout != null) {
        t = layout.format(event);
        s = t;
      }
    }
  
    public
    void append(LoggingEvent event) {
    }
  
    /**
       This is a bogus appender but it still uses a layout.
    */
    public
    boolean requiresLayout() {
      return true;
    }
  }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org


Mime
View raw message