[jboss-cvs] JBoss Messaging SVN: r7107 - branches/Branch_JBM2_Perf_Clebert/tests/src/org/jboss/messaging/tests/performance/journal.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu May 28 15:13:18 EDT 2009


Author: clebert.suconic at jboss.com
Date: 2009-05-28 15:13:18 -0400 (Thu, 28 May 2009)
New Revision: 7107

Added:
   branches/Branch_JBM2_Perf_Clebert/tests/src/org/jboss/messaging/tests/performance/journal/PerformanceComparissonTest.java
Log:
Simple performance test at journal level

Added: branches/Branch_JBM2_Perf_Clebert/tests/src/org/jboss/messaging/tests/performance/journal/PerformanceComparissonTest.java
===================================================================
--- branches/Branch_JBM2_Perf_Clebert/tests/src/org/jboss/messaging/tests/performance/journal/PerformanceComparissonTest.java	                        (rev 0)
+++ branches/Branch_JBM2_Perf_Clebert/tests/src/org/jboss/messaging/tests/performance/journal/PerformanceComparissonTest.java	2009-05-28 19:13:18 UTC (rev 7107)
@@ -0,0 +1,212 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005-2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.messaging.tests.performance.journal;
+
+import java.io.File;
+
+import org.jboss.messaging.core.journal.EncodingSupport;
+import org.jboss.messaging.core.journal.LoadManager;
+import org.jboss.messaging.core.journal.PreparedTransactionInfo;
+import org.jboss.messaging.core.journal.RecordInfo;
+import org.jboss.messaging.core.journal.SequentialFileFactory;
+import org.jboss.messaging.core.journal.impl.AIOSequentialFileFactory;
+import org.jboss.messaging.core.journal.impl.JournalImpl;
+import org.jboss.messaging.core.journal.impl.NIOSequentialFileFactory;
+import org.jboss.messaging.core.remoting.spi.MessagingBuffer;
+import org.jboss.messaging.tests.util.UnitTestCase;
+
+/**
+ * A PerformanceComparissonTest
+ *
+ * @author <a href="mailto:clebert.suconic at jboss.org">Clebert Suconic</a>
+ *
+ *
+ */
+public class PerformanceComparissonTest extends UnitTestCase
+{
+
+   // Constants -----------------------------------------------------
+
+   // Attributes ----------------------------------------------------
+
+   long NUM_RECORDS = 100000;
+   
+   long WARMUP_RECORDS = 1000;
+   
+   byte ADD_RECORD = 1;
+   byte UPDATE1 = 2;
+   byte UPDATE2 = 3;
+   
+   // Static --------------------------------------------------------
+
+   // Constructors --------------------------------------------------
+
+   // Public --------------------------------------------------------
+
+   protected void setUp() throws Exception
+   {
+      super.setUp();
+      File file = new File(getTestDir());
+
+      deleteDirectory(file);
+
+      file.mkdirs();
+   }
+
+   protected void tearDown() throws Exception
+   {
+      //super.tearDown();
+   }
+   
+   
+   public void testAddUpdateAIO() throws Exception
+   {
+      testAddUpdate(new AIOSequentialFileFactory(getTestDir()));
+   }
+
+   public void testAddUpdateNIO() throws Exception
+   {
+      testAddUpdate(new NIOSequentialFileFactory(getTestDir()));
+   }
+
+   public void testAddUpdate(SequentialFileFactory fileFactory) throws Exception
+   {
+      JournalImpl journal = new JournalImpl(10 * 1024 * 1024, // 10M.. we believe that's the usual cilinder
+                                                                     // size.. not an exact science here
+                                                   10, // number of files pre-allocated
+                                                   true, // sync on commit
+                                                   false, // no sync on non transactional
+                                                   fileFactory, // AIO or NIO
+                                                   "exjournal", // file name
+                                                   "dat", // extension
+                                                   10000, // it's like a semaphore for callback on the AIO layer
+                                                   5 * 1024); // avg buffer size.. it will reuse any buffer smaller than
+                                                              // this during record writes
+      
+      journal.start();
+      journal.load(new LoadManager()
+      {
+
+         public void addPreparedTransaction(PreparedTransactionInfo preparedTransaction)
+         {
+         }
+
+         public void addRecord(RecordInfo info)
+         {
+         }
+
+         public void deleteRecord(long id)
+         {
+         }
+
+         public void updateRecord(RecordInfo info)
+         {
+         }
+         
+      });
+      
+      FakeMessage msg = new FakeMessage();
+      FakeQueueEncoding update = new FakeQueueEncoding();
+      
+      long timeStart = System.currentTimeMillis();
+      for (long i = 0 ; i < NUM_RECORDS; i++)
+      {
+         if (i == WARMUP_RECORDS)
+         {
+            timeStart = System.currentTimeMillis();
+         }
+         journal.appendAddRecord(i, ADD_RECORD, msg);
+         //journal.appendUpdateRecord(i, UPDATE1, update);
+      }
+      
+      
+      journal.stop();
+      
+      
+      System.out.println("Produced records " + (NUM_RECORDS = WARMUP_RECORDS) + " in " + (System.currentTimeMillis() - timeStart) + " milliseconds");
+      
+   }
+   
+   class FakeMessage implements EncodingSupport
+   {
+
+      public void decode(MessagingBuffer buffer)
+      {
+      }
+
+      public void encode(MessagingBuffer buffer)
+      {
+         buffer.writeBytes(new byte[1024]);
+      }
+
+      /* (non-Javadoc)
+       * @see org.jboss.messaging.core.journal.EncodingSupport#getEncodeSize()
+       */
+      public int getEncodeSize()
+      {
+         return 1100;
+      }
+      
+   }
+   
+   private static class FakeQueueEncoding implements EncodingSupport
+   {
+      long queueID;
+
+      public FakeQueueEncoding(final long queueID)
+      {
+         super();
+         this.queueID = queueID;
+      }
+
+      public FakeQueueEncoding()
+      {
+         super();
+      }
+
+      public void decode(final MessagingBuffer buffer)
+      {
+         queueID = buffer.readLong();
+      }
+
+      public void encode(final MessagingBuffer buffer)
+      {
+         buffer.writeLong(queueID);
+      }
+
+      public int getEncodeSize()
+      {
+         return 8;
+      }
+   }
+   
+
+   // Package protected ---------------------------------------------
+
+   // Protected -----------------------------------------------------
+
+   // Private -------------------------------------------------------
+
+   // Inner classes -------------------------------------------------
+
+}




More information about the jboss-cvs-commits mailing list