1 /* 2 * Logback: the reliable, generic, fast and flexible logging framework. 3 * Copyright (C) 1999-2024, QOS.ch. All rights reserved. 4 * 5 * This program and the accompanying materials are dual-licensed under 6 * either the terms of the Eclipse Public License v1.0 as published by 7 * the Eclipse Foundation 8 * 9 * or (per the licensee's choosing) 10 * 11 * under the terms of the GNU Lesser General Public License version 2.1 12 * as published by the Free Software Foundation. 13 */ 14 package ch.qos.logback.classic.blackbox.issue.lbclassic135; 15 16 import ch.qos.logback.classic.Logger; 17 import ch.qos.logback.classic.LoggerContext; 18 import ch.qos.logback.classic.encoder.PatternLayoutEncoder; 19 import ch.qos.logback.classic.spi.ILoggingEvent; 20 import ch.qos.logback.core.FileAppender; 21 import ch.qos.logback.core.testUtil.RunnableWithCounterAndDone; 22 //import ch.qos.logback.core.contention.ThreadedThroughputCalculator; 23 24 /** 25 * Short sample code testing the throughput of a fair lock. 26 * 27 * @author Ceki Gulcu 28 */ 29 public class LoggingToFileThroughput { 30 31 static int THREAD_COUNT = 1; 32 static long OVERALL_DURATION_IN_MILLIS = 5000; 33 34 public static void main(String args[]) throws InterruptedException { 35 36 // ThreadedThroughputCalculator tp = new ThreadedThroughputCalculator(OVERALL_DURATION_IN_MILLIS); 37 // tp.printEnvironmentInfo("lbclassic135 LoggingToFileThrouhput"); 38 // 39 // LoggerContext lc = new LoggerContext(); 40 // Logger logger = buildLoggerContext(lc); 41 // 42 // for (int i = 0; i < 2; i++) { 43 // tp.execute(buildArray(logger)); 44 // } 45 // 46 // RunnableWithCounterAndDone[] runnnableArray = buildArray(logger); 47 // tp.execute(runnnableArray); 48 // tp.printThroughput(runnnableArray, "File: "); 49 // lc.stop(); 50 } 51 52 static Logger buildLoggerContext(LoggerContext lc) { 53 Logger root = lc.getLogger(Logger.ROOT_LOGGER_NAME); 54 55 PatternLayoutEncoder patternLayout = new PatternLayoutEncoder(); 56 patternLayout.setContext(lc); 57 patternLayout.setPattern("%d %l [%t] - %msg%n"); 58 patternLayout.start(); 59 FileAppender<ILoggingEvent> fileAppender = new FileAppender<ILoggingEvent>(); 60 fileAppender.setContext(lc); 61 fileAppender.setFile("target/lbclassic135.log"); 62 fileAppender.setEncoder(patternLayout); 63 fileAppender.setAppend(false); 64 fileAppender.start(); 65 root.addAppender(fileAppender); 66 return lc.getLogger(LoggingToFileThroughput.class); 67 } 68 69 static LoggingRunnable[] buildArray(Logger logger) { 70 71 LoggingRunnable[] array = new LoggingRunnable[THREAD_COUNT]; 72 for (int i = 0; i < THREAD_COUNT; i++) { 73 array[i] = new LoggingRunnable(logger); 74 } 75 return array; 76 } 77 } 78 79 // === lbclassic135 LoggingToFileThrouhput === 80 // ******** 10 Threads ***** 81 // synchronized doAppend() method 82 // 83 // java.runtime.version = 1.6.0_05-b13 84 // java.vendor = Sun Microsystems Inc. 85 // os.name = Windows XP 86 // 87 // Threads 1: total of 485077 operations, or 97 operations per millisecond 88 // Threads 10: total of 309402 operations, or 61 operations per millisecond 89 90 // * After revision 2310 91 // * Threads 1: total of 462465 operations, or 92 operations per millisecond 92 // * Threads 10: total of 243362 operations, or 48 operations per millisecond 93 94 // ==================== Linux ======================== 95 96 // java.runtime.version = 1.6.0_11-b03 97 // java.vendor = Sun Microsystems Inc. 98 // os.name = Linux 99 // os.version = 2.6.25-gentoo-r6 100 // Threads 1: total of 356355 operations, or 71 operations per millisecond 101 // Threads 10: total of 287943 operations, or 57 operations per millisecond 102 103 // * After revision 2310 104 // * Threads 1: total of 331494 operations, or 66 operations per millisecond 105 // * Threads 10: total of 311104 operations, or 58 operations per millisecond 106 107 // java.runtime.version = jvmxa6460-20081105_25433 108 // java.vendor = IBM Corporation 109 // java.version = 1.6.0 110 // os.name = Linux 111 // os.version = 2.6.25-gentoo-r6 112 // Threads 1: total of 280381 operations, or 56 operations per millisecond 113 // Threads 10 total of 142989 operations, or 28 operations per millisecond 114 115 // * After revision 2310 116 // * Threads 1: total of 305638 operations, or 61 operations per millisecond 117 // * Threads 10: total of 147660 operations, or 29 operations per millisecond