[logback-dev] [GIT] Logback: the generic, reliable, fast and flexible logging framework. branch, master, updated. v0.9.18-54-g8351663

added by portage for gitosis-gentoo git-noreply at pixie.qos.ch
Wed Mar 3 15:46:09 CET 2010


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Logback: the generic, reliable, fast and flexible logging framework.".

The branch, master has been updated
       via  83516636bda43c43594d34e39f428f82ebeb1a18 (commit)
      from  0b234ba87bac07b450a46fd472e233c9e181f4ec (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
http://git.qos.ch/gitweb/?p=logback.git;a=commit;h=83516636bda43c43594d34e39f428f82ebeb1a18
http://github.com/ceki/logback/commit/83516636bda43c43594d34e39f428f82ebeb1a18

commit 83516636bda43c43594d34e39f428f82ebeb1a18
Author: Ceki Gulcu <ceki at qos.ch>
Date:   Wed Mar 3 15:45:25 2010 +0100

    - IO performace is hardly influenced by flushing

diff --git a/logback-examples/src/main/java/chapters/appenders/IOPerformance.java b/logback-examples/src/main/java/chapters/appenders/IOPerformance.java
new file mode 100644
index 0000000..8804bcb
--- /dev/null
+++ b/logback-examples/src/main/java/chapters/appenders/IOPerformance.java
@@ -0,0 +1,172 @@
+/**
+ * Logback: the reliable, generic, fast and flexible logging framework.
+ * Copyright (C) 1999-2009, QOS.ch. All rights reserved.
+ *
+ * This program and the accompanying materials are dual-licensed under
+ * either the terms of the Eclipse Public License v1.0 as published by
+ * the Eclipse Foundation
+ *
+ *   or (per the licensee's choosing)
+ *
+ * under the terms of the GNU Lesser General Public License version 2.1
+ * as published by the Free Software Foundation.
+ */
+package chapters.appenders;
+
+import java.io.FileWriter;
+import java.io.IOException;
+
+import org.slf4j.Logger;
+
+import ch.qos.logback.classic.LoggerContext;
+import ch.qos.logback.classic.encoder.PatternLayoutEncoder;
+import ch.qos.logback.classic.spi.ILoggingEvent;
+import ch.qos.logback.core.FileAppender;
+import ch.qos.logback.core.util.StatusPrinter;
+
+public class IOPerformance extends Thread {
+  static String MSG = "ABCDEGHIJKLMNOPQRSTUVWXYZabcdeghijklmnopqrstuvwxyz1234567890";
+  static String LOG_FILE;
+  public static String PARALLEL_FILE;
+
+  static int NUM_THREADS = 1;
+  static long l;
+  long len;
+  boolean immediateFlush;
+  Logger logger;
+  LoggerContext context;
+  double throughput;
+
+  public IOPerformance(boolean _immediateFlush, long _len) {
+    this.len = _len;
+    this.immediateFlush = _immediateFlush;
+    context = new LoggerContext();
+    logger = context.getLogger("logger-" + getName());
+
+    // A FileAppender is created according to the buffering and
+    // immediate flush setting of this IO instance.
+    FileAppender<ILoggingEvent> fa = new FileAppender<ILoggingEvent>();
+    fa.setName("FILE");
+    PatternLayoutEncoder pa = new PatternLayoutEncoder();
+    pa.setPattern("%r %5p %c [%t] - %m%n");
+    pa.setContext(context);
+    pa.start();
+    fa.setEncoder(pa);
+
+    fa.setFile(LOG_FILE);
+    fa.setAppend(true);
+    fa.setContext(context);
+    fa.start();
+    
+    ((ch.qos.logback.classic.Logger)logger).addAppender(fa);
+    
+    StatusPrinter.print(context);
+  }
+
+  public static void main(String[] argv) throws Exception {
+    if (argv.length != 3) {
+      usage("Wrong number of arguments.");
+    }
+
+    l = Integer.parseInt(argv[0]);
+    LOG_FILE = argv[1];
+    PARALLEL_FILE = argv[2];
+
+    // ----------------------------------------------------
+    // first test with immediate flushing
+    perfCase(true, l);
+
+    // ----------------------------------------------------
+    // Second test with no immediate flushing
+    perfCase(false, l);
+
+
+    // There is no fourth test as buffered IO and immediate flushing
+    // do not make sense.
+  }
+
+  static void usage(String msg) {
+    System.err.println(msg);
+    System.err.println("Usage: java " + IOPerformance.class.getName()
+        + " runLength logFile otherFile\n"
+        + "   runLength (integer) the number of logs to generate perthread\n"
+        + "   logFile path to a logFile\n"
+        + "   otherFile path to a second file\n");
+    System.exit(1);
+  }
+
+  static void perfCase(boolean immediateFlush, long len)
+      throws Exception {
+    IOPerformance[] threads = new IOPerformance[NUM_THREADS];
+    OtherIO otherIOThread = new OtherIO();
+    otherIOThread.start();
+
+    // First create the threads
+    for (int i = 0; i < NUM_THREADS; i++) {
+      threads[i] = new IOPerformance(immediateFlush, len);
+    }
+
+    // then start them
+    for (int i = 0; i < NUM_THREADS; i++) {
+      threads[i].start();
+    }
+
+    // wait for them to stop, compute the average throughput
+    double sum = 0;
+
+    for (int i = 0; i < NUM_THREADS; i++) {
+      threads[i].join();
+      sum += threads[i].throughput;
+    }
+
+    // setting the interrupted field will cause counterThread to stop
+    otherIOThread.interrupted = true;
+    otherIOThread.join();
+
+    System.out.println("On total throughput of " + (sum) 
+        + " logs per microsecond.");
+    System.out.println("------------------------------------------------");
+  }
+
+  public void run() {
+
+    long before = System.nanoTime();
+
+    for (int i = 0; i < len; i++) {
+      logger.debug(MSG);
+    }
+
+    throughput = (len * 1.0) / ((System.nanoTime() - before)/1000);
+    System.out.println(getName() + ", immediateFlush: " + immediateFlush
+        + ", throughput: " + throughput + " logs per microsecond.");
+  }
+}
+
+class OtherIO extends Thread {
+  public boolean interrupted = false;
+  public int counter = 0;
+
+  public void run() {
+    long before = System.nanoTime();
+    
+    try {
+      FileWriter fw = new FileWriter(IOPerformance.PARALLEL_FILE, true);
+
+      while (!interrupted) {
+//        if (counter++ % 1000 == 0) {
+//          Thread.yield();
+//        }
+        counter++;
+        fw.write("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
+        fw.flush();
+      }
+
+    } catch (IOException e) {
+      e.printStackTrace();
+    }
+
+    double tput = (counter * 1.0) / (System.nanoTime() - before);
+    System.out.println("Counter thread " + getName()
+        + " incremented counter by " + tput + " per nanosecond.");
+  }
+}

-----------------------------------------------------------------------

Summary of changes:
 .../java/chapters/appenders/IOPerformance.java     |  172 ++++++++++++++++++++
 1 files changed, 172 insertions(+), 0 deletions(-)
 create mode 100644 logback-examples/src/main/java/chapters/appenders/IOPerformance.java


hooks/post-receive
-- 
Logback: the generic, reliable, fast and flexible logging framework.


More information about the logback-dev mailing list