[jboss-cvs] JBoss Messaging SVN: r7138 - in branches/Branch_JBM2_Perf_Clebert: src/main/org/jboss/messaging/core/journal and 3 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Sat May 30 02:19:46 EDT 2009


Author: clebert.suconic at jboss.com
Date: 2009-05-30 02:19:46 -0400 (Sat, 30 May 2009)
New Revision: 7138

Modified:
   branches/Branch_JBM2_Perf_Clebert/src/main/org/jboss/messaging/core/asyncio/timedbuffer/TimedBuffer.java
   branches/Branch_JBM2_Perf_Clebert/src/main/org/jboss/messaging/core/journal/SequentialFile.java
   branches/Branch_JBM2_Perf_Clebert/src/main/org/jboss/messaging/core/journal/impl/AIOSequentialFile.java
   branches/Branch_JBM2_Perf_Clebert/src/main/org/jboss/messaging/core/journal/impl/JournalImpl.java
   branches/Branch_JBM2_Perf_Clebert/src/main/org/jboss/messaging/core/journal/impl/NIOSequentialFile.java
   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/unit/core/journal/impl/fakes/FakeSequentialFileFactory.java
Log:
fixes

Modified: branches/Branch_JBM2_Perf_Clebert/src/main/org/jboss/messaging/core/asyncio/timedbuffer/TimedBuffer.java
===================================================================
--- branches/Branch_JBM2_Perf_Clebert/src/main/org/jboss/messaging/core/asyncio/timedbuffer/TimedBuffer.java	2009-05-30 03:42:18 UTC (rev 7137)
+++ branches/Branch_JBM2_Perf_Clebert/src/main/org/jboss/messaging/core/asyncio/timedbuffer/TimedBuffer.java	2009-05-30 06:19:46 UTC (rev 7138)
@@ -67,8 +67,6 @@
    private volatile List<AIOCallback> callbacks;
 
    private volatile long timeLastWrite = 0;
-   
-   private final Lock lock = new ReentrantReadWriteLock().writeLock();
 
    private final ScheduledExecutorService schedule = ScheduledSingleton.getScheduledService();
 
@@ -101,15 +99,7 @@
    {
       if (System.currentTimeMillis() - timeLastWrite > timeout)
       {
-         lock.lock();
-         try
-         {
-            flush();
-         }
-         finally
-         {
-            lock.unlock();
-         }
+         flush();
       }
 
    }
@@ -121,15 +111,15 @@
     */
    public synchronized boolean checkSize(final int sizeChecked)
    {
-      final boolean fits; 
+      final boolean fits;
       if (sizeChecked > bufferSize)
       {
          flush();
 
          // We transfer the bytes, as the bufferObserver has special alignment restrictions on the buffer addressing
          currentBuffer = bufferObserver.newBuffer(sizeChecked, sizeChecked);
-         
-         fits = currentBuffer != null; 
+
+         fits = currentBuffer != null;
       }
       else
       {
@@ -140,46 +130,33 @@
             newBuffer(sizeChecked);
          }
 
-         fits = currentBuffer != null; 
+         fits = currentBuffer != null;
       }
-      
-      // If the size fits, we set the lock as we can't have a flush happening until addBytes was called
-      if (fits)
-      {
-         lock.lock();
-      }
-      
+
       return fits;
    }
 
    public synchronized void addBytes(final ByteBuffer bytes, final AIOCallback callback)
    {
-      try
+      if (currentBuffer == null)
       {
-         if (currentBuffer == null)
-         {
-            newBuffer(0);
-         }
-   
-         currentBuffer.put(bytes);
-         callbacks.add(callback);
-   
-         if (futureTimerRunnable == null)
-         {
-            futureTimerRunnable = schedule.scheduleAtFixedRate(timerRunnable, timeout, timeout, TimeUnit.MILLISECONDS);
-         }
-   
-         timeLastWrite = System.currentTimeMillis();
-   
-         if (currentBuffer.position() == currentBuffer.capacity())
-         {
-            flush();
-         }
+         newBuffer(0);
       }
-      finally
+
+      currentBuffer.put(bytes);
+      callbacks.add(callback);
+
+      if (futureTimerRunnable == null)
       {
-         lock.unlock();
+         futureTimerRunnable = schedule.scheduleAtFixedRate(timerRunnable, timeout, timeout, TimeUnit.MILLISECONDS);
       }
+
+      timeLastWrite = System.currentTimeMillis();
+
+      if (currentBuffer.position() == currentBuffer.capacity())
+      {
+         flush();
+      }
    }
 
    public synchronized void flush()
@@ -190,7 +167,7 @@
          currentBuffer = null;
          callbacks = null;
       }
-      
+
       if (futureTimerRunnable != null)
       {
          futureTimerRunnable.cancel(false);

Modified: branches/Branch_JBM2_Perf_Clebert/src/main/org/jboss/messaging/core/journal/SequentialFile.java
===================================================================
--- branches/Branch_JBM2_Perf_Clebert/src/main/org/jboss/messaging/core/journal/SequentialFile.java	2009-05-30 03:42:18 UTC (rev 7137)
+++ branches/Branch_JBM2_Perf_Clebert/src/main/org/jboss/messaging/core/journal/SequentialFile.java	2009-05-30 06:19:46 UTC (rev 7138)
@@ -80,6 +80,8 @@
 
    long size() throws Exception;
    
+   void flush();
+   
    void renameTo(String newFileName) throws Exception;
 
 }

Modified: branches/Branch_JBM2_Perf_Clebert/src/main/org/jboss/messaging/core/journal/impl/AIOSequentialFile.java
===================================================================
--- branches/Branch_JBM2_Perf_Clebert/src/main/org/jboss/messaging/core/journal/impl/AIOSequentialFile.java	2009-05-30 03:42:18 UTC (rev 7137)
+++ branches/Branch_JBM2_Perf_Clebert/src/main/org/jboss/messaging/core/journal/impl/AIOSequentialFile.java	2009-05-30 06:19:46 UTC (rev 7138)
@@ -129,6 +129,11 @@
    {
       return timedBuffer.checkSize(size);
    }
+   
+   public void flush()
+   {
+      timedBuffer.flush();
+   }
 
    public synchronized void close() throws Exception
    {

Modified: branches/Branch_JBM2_Perf_Clebert/src/main/org/jboss/messaging/core/journal/impl/JournalImpl.java
===================================================================
--- branches/Branch_JBM2_Perf_Clebert/src/main/org/jboss/messaging/core/journal/impl/JournalImpl.java	2009-05-30 03:42:18 UTC (rev 7137)
+++ branches/Branch_JBM2_Perf_Clebert/src/main/org/jboss/messaging/core/journal/impl/JournalImpl.java	2009-05-30 06:19:46 UTC (rev 7138)
@@ -1868,12 +1868,6 @@
          if (!currentFile.getFile().fits(size))
          {
             moveNextFile();
-            
-            // Needs to do it again to guarantee locking on timed buffers on AIO
-            if (!currentFile.getFile().fits(size))
-            {
-               throw new IllegalStateException("Inconsistence on sizes on journal");
-            }
          }
 
          if (currentFile == null)
@@ -1889,16 +1883,18 @@
 
          if (callback != null)
          {
-            // We are 100% sure currentFile won't change, since rwLock.readLock is
-            // locked
             currentFile.getFile().write(bb, callback);
-            // callback.waitCompletion() should be done on the caller of this
-            // method, so we would have better performance
+            
+            // TODO: Do we need to do this?
+            //       it wouldn't scale, but it is probably useful in some usecases? 
+            //       It should be configurable at least
+            if (sync)
+            {
+               currentFile.getFile().flush();
+            }
          }
          else
          {
-            // We are 100% sure currentFile won't change, since rwLock.readLock is
-            // locked
             currentFile.getFile().write(bb, sync);
          }
 

Modified: branches/Branch_JBM2_Perf_Clebert/src/main/org/jboss/messaging/core/journal/impl/NIOSequentialFile.java
===================================================================
--- branches/Branch_JBM2_Perf_Clebert/src/main/org/jboss/messaging/core/journal/impl/NIOSequentialFile.java	2009-05-30 03:42:18 UTC (rev 7137)
+++ branches/Branch_JBM2_Perf_Clebert/src/main/org/jboss/messaging/core/journal/impl/NIOSequentialFile.java	2009-05-30 06:19:46 UTC (rev 7138)
@@ -66,6 +66,10 @@
    {
       return 1;
    }
+   
+   public void flush()
+   {
+   }
 
    public int calculateBlockStart(final int position) throws Exception
    {

Modified: 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	2009-05-30 03:42:18 UTC (rev 7137)
+++ branches/Branch_JBM2_Perf_Clebert/tests/src/org/jboss/messaging/tests/performance/journal/PerformanceComparissonTest.java	2009-05-30 06:19:46 UTC (rev 7138)
@@ -253,7 +253,8 @@
    
    public void testTransactional() throws Exception
    {
-      SequentialFileFactory factory = new AIOSequentialFileFactory(getTestDir(), 1024 * 1024, 1);
+      //SequentialFileFactory factory = new AIOSequentialFileFactory(getTestDir(), 1024 * 1024, 1);
+      SequentialFileFactory factory = new NIOSequentialFileFactory(getTestDir());
       
       JournalImpl journal = new JournalImpl(1024 * 1024 * 10, // 10M.. we believe that's the usual cilinder
                                             // size.. not an exact science here
@@ -268,9 +269,20 @@
       journal.start();
       journal.load(dummyLoader);
       
-      journal.appendAddRecordTransactional(1, 1, (byte)1, new byte[]{(byte)1});
-      journal.appendCommitRecord(1);
+      long id = 1;
       
+      long start = System.currentTimeMillis();
+      for (int i = 0 ; i < 200; i++)
+      {
+         journal.appendAddRecordTransactional(i, id++, (byte)1, new byte[]{(byte)1});
+         journal.appendCommitRecord(i);
+         
+      }
+      long end = System.currentTimeMillis();
+      
+      
+      System.out.println("Value = " + (end - start));
+      
       journal.stop();
       
       

Modified: branches/Branch_JBM2_Perf_Clebert/tests/src/org/jboss/messaging/tests/unit/core/journal/impl/fakes/FakeSequentialFileFactory.java
===================================================================
--- branches/Branch_JBM2_Perf_Clebert/tests/src/org/jboss/messaging/tests/unit/core/journal/impl/fakes/FakeSequentialFileFactory.java	2009-05-30 03:42:18 UTC (rev 7137)
+++ branches/Branch_JBM2_Perf_Clebert/tests/src/org/jboss/messaging/tests/unit/core/journal/impl/fakes/FakeSequentialFileFactory.java	2009-05-30 06:19:46 UTC (rev 7138)
@@ -321,6 +321,10 @@
          // + open);
          return open;
       }
+      
+      public void flush()
+      {
+      }
 
       public FakeSequentialFile(final String fileName)
       {




More information about the jboss-cvs-commits mailing list