Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: org/activemq/store/journal/ActiveIOJournalBenchmark.java


1   /** 
2    * 
3    * Copyright 2004 Hiram Chirino
4    * 
5    * Licensed under the Apache License, Version 2.0 (the "License"); 
6    * you may not use this file except in compliance with the License. 
7    * You may obtain a copy of the License at 
8    * 
9    * http://www.apache.org/licenses/LICENSE-2.0
10   * 
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS, 
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
14   * See the License for the specific language governing permissions and 
15   * limitations under the License. 
16   * 
17   **/
18  package org.activemq.store.journal;
19  
20  import java.io.File;
21  
22  import junit.framework.TestCase;
23  
24  import org.activeio.Packet;
25  import org.activeio.journal.active.JournalImpl;
26  import org.activeio.packet.ByteArrayPacket;
27  
28  /**
29   * Used to micro benchmark the ActiveIO Journal operations.
30   * 
31   * Make sure you run with jvm option -server (makes a big difference).
32   * The tests simulate storing 100000 1k jms messages to see the rate of 
33   * processing msg/sec.
34   * 
35   * @version $Revision: 1.1 $
36   */
37  public class ActiveIOJournalBenchmark extends TestCase {
38  
39      private static final int MESSAGE_COUNT = 100000;
40      private Packet packet;
41      private JournalImpl journal;
42      
43      public static void main(String[] args) {
44          junit.textui.TestRunner.run(ActiveIOJournalBenchmark.class);
45      }
46  
47      protected void setUp() throws Exception {
48          File file = new File("target/journal");
49          JournalTestHelper.delete(file);
50          journal = new JournalImpl(file);
51          packet = new ByteArrayPacket(new byte[1072]);
52      }
53      
54      protected void tearDown() throws Exception {
55          journal.dispose();
56      }
57      
58      
59      /** 
60       * Runs at about 24000 msg/sec on OS X G4 1.5ghz.  This shows that writing to the
61       * activeio journal is not a bottleneck.
62       */
63      public void testAsyncAddMessage() throws Exception {
64          long start = System.currentTimeMillis();
65          for (int i = 0; i < MESSAGE_COUNT; i++) {
66              journal.write(packet, false);
67          }
68          long end = System.currentTimeMillis();
69          
70          System.out.println(getName()+": test duration: "+(end-start)+" ms, msg/s: "+(MESSAGE_COUNT*1000f/(end-start)));
71          
72       }
73  }