View Javadoc
1   /**
2    * Logback: the reliable, generic, fast and flexible logging framework.
3    * Copyright (C) 1999-2015, 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;
15  
16  import org.junit.Before;
17  import org.junit.Ignore;
18  import org.junit.Test;
19  
20  import ch.qos.logback.classic.corpus.CorpusModel;
21  import ch.qos.logback.core.contention.RunnableWithCounterAndDone;
22  import ch.qos.logback.core.contention.ThreadedThroughputCalculator;
23  
24  @Ignore
25  public class LoggerContextPerfTest {
26  
27      static int THREAD_COUNT = 10000;
28      int totalTestDuration = 4000;
29  
30      LoggerContext loggerContext = new LoggerContext();
31  
32      ThreadedThroughputCalculator harness = new ThreadedThroughputCalculator(totalTestDuration);
33      RunnableWithCounterAndDone[] runnableArray = buildRunnableArray();
34  
35      CorpusModel corpusMaker;
36  
37      @Before
38      public void setUp() throws Exception {
39      }
40  
41      private RunnableWithCounterAndDone[] buildRunnableArray() {
42          RunnableWithCounterAndDone[] runnableArray = new RunnableWithCounterAndDone[THREAD_COUNT];
43          for (int i = 0; i < THREAD_COUNT; i++) {
44              runnableArray[i] = new GetLoggerRunnable();
45          }
46          return runnableArray;
47      }
48  
49      // Results computed on a Intel i7
50      // 1 thread
51      // 13'107 ops per milli using Hashtable for LoggerContext.loggerCache
52      // 15'258 ops per milli using ConcurrentHashMap for LoggerContext.loggerCache
53  
54      // 10 threads
55      // 8'468 ops per milli using Hashtable for LoggerContext.loggerCache
56      // 58'945 ops per milli using ConcurrentHashMap for LoggerContext.loggerCache
57  
58      // 100 threads
59      // 8'863 ops per milli using Hashtable for LoggerContext.loggerCache
60      // 34'810 ops per milli using ConcurrentHashMap for LoggerContext.loggerCache
61  
62      // 1'000 threads
63      // 8'188 ops per milli using Hashtable for LoggerContext.loggerCache
64      // 24'012 ops per milli using ConcurrentHashMap for LoggerContext.loggerCache
65  
66      // 10'000 threads
67      // 7'595 ops per milli using Hashtable for LoggerContext.loggerCache
68      // 8'989 ops per milli using ConcurrentHashMap for LoggerContext.loggerCache
69  
70      @Test
71      public void computeResults() throws InterruptedException {
72          harness.execute(runnableArray);
73          harness.printThroughput("getLogger performance: ", true);
74      }
75  
76      private class GetLoggerRunnable extends RunnableWithCounterAndDone {
77  
78          final int burstLength = 3;
79  
80          public void run() {
81              while (!isDone()) {
82                  long i = counter % burstLength;
83  
84                  loggerContext.getLogger("a" + i);
85                  counter++;
86                  if (i == 0) {
87                      Thread.yield();
88                  }
89              }
90          }
91      }
92  }