[jboss-cvs] JBoss Messaging SVN: r3738 - in projects/jaio/trunk/jaio/java: src/org/jboss/jaio/api and 2 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Feb 19 21:08:12 EST 2008


Author: clebert.suconic at jboss.com
Date: 2008-02-19 21:08:12 -0500 (Tue, 19 Feb 2008)
New Revision: 3738

Modified:
   projects/jaio/trunk/jaio/java/
   projects/jaio/trunk/jaio/java/build.xml
   projects/jaio/trunk/jaio/java/src/org/jboss/jaio/api/AIOController.java
   projects/jaio/trunk/jaio/java/src/org/jboss/jaio/libaioimpl/LibAIOController.java
   projects/jaio/trunk/jaio/java/tests/org/jboss/jaio/libaioimpl/test/TestController.java
Log:
Few tweaks


Property changes on: projects/jaio/trunk/jaio/java
___________________________________________________________________
Name: svn:ignore
   - output

   + output
eclipse-bin


Modified: projects/jaio/trunk/jaio/java/build.xml
===================================================================
--- projects/jaio/trunk/jaio/java/build.xml	2008-02-20 02:05:59 UTC (rev 3737)
+++ projects/jaio/trunk/jaio/java/build.xml	2008-02-20 02:08:12 UTC (rev 3738)
@@ -41,7 +41,7 @@
 
 	<target name="tests" depends="compile" description="run tests">
 
-		<junit printsummary="yes" haltonfailure="yes" haltonerror="yes">
+		<junit printsummary="yes" haltonfailure="yes" haltonerror="yes" fork="yes">
 			<classpath refid="test.classpath"/>
 			<formatter type="xml"/>
 			<batchtest todir="./output/testresult">

Modified: projects/jaio/trunk/jaio/java/src/org/jboss/jaio/api/AIOController.java
===================================================================
--- projects/jaio/trunk/jaio/java/src/org/jboss/jaio/api/AIOController.java	2008-02-20 02:05:59 UTC (rev 3737)
+++ projects/jaio/trunk/jaio/java/src/org/jboss/jaio/api/AIOController.java	2008-02-20 02:08:12 UTC (rev 3738)
@@ -25,9 +25,7 @@
     
     void recoverContent(AIORecoveryCallback callbackRecover);
     
-    void pollEvents();
-
-    void validateLowRate();
+    void preAllocate(int blocks, long size);
     
     
 }

Modified: projects/jaio/trunk/jaio/java/src/org/jboss/jaio/libaioimpl/LibAIOController.java
===================================================================
--- projects/jaio/trunk/jaio/java/src/org/jboss/jaio/libaioimpl/LibAIOController.java	2008-02-20 02:05:59 UTC (rev 3737)
+++ projects/jaio/trunk/jaio/java/src/org/jboss/jaio/libaioimpl/LibAIOController.java	2008-02-20 02:08:12 UTC (rev 3738)
@@ -14,6 +14,7 @@
 public class LibAIOController implements AIOController
 {
     private boolean opened = false;
+    private String fileName;
     private Thread poller;
     /**
      *  Warning: Beware of the C++ pointer! It will bite you! :-)
@@ -40,39 +41,28 @@
     public void open(String fileName)
     {
         opened = true;
+        this.fileName=fileName;
         handler = init (fileName, AIOPackage.class);
+        startPoller();
     }
     
-    static class PollerThread extends Thread
+    class PollerThread extends Thread
     {
-        PollerThread (LibAIOController lib)
+        PollerThread ()
         {
-            this.lib = lib;
+            super("NativePoller for " + fileName);
         }
-        LibAIOController lib;
         public void run()
         {
-            while (lib.opened)
-            {
-                try
-                {
-                    System.out.println("poll");
-                    Thread.sleep(500);
-                    lib.pollEvents();
-                }
-                catch (Exception e)
-                {
-                    e.printStackTrace();
-                }
-            }
+            pollEvents();
         }
     }
     
-    public void startPoller()
+    private void startPoller()
     {
         if (handler == 0)
             throw new RuntimeException("not opened");
-        poller = new PollerThread(this); 
+        poller = new PollerThread(); 
         poller.start();
     }
     
@@ -87,7 +77,6 @@
         if (poller!=null)
         {
             opened = false;
-            try {poller.join();} catch (Exception ignored){}
         }
         closeInternal(handler);
         handler = 0;
@@ -97,10 +86,7 @@
     public void append(AIOPackage aioPackage)
     {
         
-        synchronized (lock)
-        {
-            append(handler, aioPackage);
-        }
+        append(handler, aioPackage);
         
     }
 
@@ -128,19 +114,16 @@
         
     }
     
-    public void pollEvents()
+    public void preAllocate(int blocks, long size)
     {
-        synchronized (lock)
-        {
-            internalPollEvents(handler);
-        }
+        preAllocate(handler, blocks, size);
     }
-    
-    public void validateLowRate()
+
+    private void pollEvents()
     {
-        validateLowRate(handler);
+        internalPollEvents(handler);
     }
-
+    
     @SuppressWarnings("unchecked")
     private static native long init(String fileName, Class aioPackageClazz);
     
@@ -148,12 +131,13 @@
     private static native long init(String fileName, int pageSize, Class aioPackageClazz);
     
     private static native void append(long handle, AIOPackage aioPackage);
+    
+    private static native void preAllocate(long handle, int blocks, long size);
 
     private static native void closeInternal(long handler);
     
     /** Poll asynchrounous events from internal queues */
     private static native void internalPollEvents(long handler);
    
-    /** Poll asynchrounous events from internal queues */
-    private static native void validateLowRate(long handler);
+    
 }

Modified: projects/jaio/trunk/jaio/java/tests/org/jboss/jaio/libaioimpl/test/TestController.java
===================================================================
--- projects/jaio/trunk/jaio/java/tests/org/jboss/jaio/libaioimpl/test/TestController.java	2008-02-20 02:05:59 UTC (rev 3737)
+++ projects/jaio/trunk/jaio/java/tests/org/jboss/jaio/libaioimpl/test/TestController.java	2008-02-20 02:08:12 UTC (rev 3738)
@@ -8,8 +8,6 @@
 import org.jboss.jaio.api.AIOPackage;
 import org.jboss.jaio.libaioimpl.LibAIOController;
 
-import sun.rmi.transport.LiveRef;
-
 import junit.framework.TestCase;
 
 public class TestController extends TestCase
@@ -17,6 +15,7 @@
     
     byte commonBuffer[] = null; 
     
+    String FILE_NAME="/tmp/libaio.log";
     
     
     @Override
@@ -24,21 +23,21 @@
     {
         super.setUp();
         LocalAIO.staticDone = 0;
-        File file = new File("/tmp/libaio.log");
-        file.delete();
+        //File file = new File(FILE_NAME);
+        //file.delete();
     }
 
     public void aatestOpen()throws Exception
     {
         LibAIOController controller = new LibAIOController();
-        controller.open("/tmp/libaio.log");
+        controller.open(FILE_NAME);
         controller.close();
     }
     
     public void aatestAddData() throws Exception
     {
         LibAIOController controller = new LibAIOController();
-        controller.open("/tmp/libaio.log", 1024*1024);
+        controller.open(FILE_NAME, 1024*1024);
         LocalAIO aio = new LocalAIO();
         
         controller.append(aio);
@@ -48,7 +47,7 @@
         assertTrue(aio.encodeSizeCalled);
         assertFalse(aio.doneCalled);
         
-        controller.pollEvents();
+//        controller.pollEvents();
         
         assertTrue(aio.doneCalled);
         controller.close();
@@ -57,68 +56,77 @@
     
     public void testDirectDataNoPage() throws Exception
     {
-        final int NUMBER_LINES = 200; 
-        final int SIZE = 512;
-        
-        commonBuffer = new byte[SIZE];
-        for (int i=0; i< commonBuffer.length-1; i++)
+        try
         {
-            commonBuffer[i] = (byte)('A' + (i%10));
-        }
-        commonBuffer[commonBuffer.length -1] = '\n';
-        
-        CountDownLatch latchDone = new CountDownLatch(NUMBER_LINES);
-        final LibAIOController controller = new LibAIOController();
-        controller.open("/tmp/libaio.log");
-        ArrayList<LocalAIO> list = new ArrayList<LocalAIO>();
-        
-        for (int i=0; i<NUMBER_LINES; i++)
-        {
-            list.add(new LocalAIO(SIZE, commonBuffer, latchDone));
-        }
-        
-       
-        long valueInitial = System.currentTimeMillis();
-        int counterFile=0;
-
-        System.out.println("Adding data");
-        
-        for (LocalAIO tmp: list)
-        {
-            controller.append(tmp);
-        }
-        
-        System.out.println("Data added " + (System.currentTimeMillis() - valueInitial));
-        
-        
-        new Thread()
-        {
-            public void run()
+            System.out.println("++testDirectDataNoPage"); System.out.flush();
+            final int NUMBER_LINES = 500000; 
+            final int SIZE = 1024;
+            //final int SIZE = 512;
+            
+            CountDownLatch latchDone = new CountDownLatch(NUMBER_LINES);
+            final LibAIOController controller = new LibAIOController();
+            controller.open(FILE_NAME);
+            System.out.println("Pre allocating file"); System.out.flush();
+            
+            long startPreAllocate = System.currentTimeMillis();
+            controller.preAllocate(1, NUMBER_LINES * SIZE);
+            long endPreAllocate = System.currentTimeMillis() - startPreAllocate;
+            if (endPreAllocate != 0) System.out.println("PreAllocated the file in " + endPreAllocate + " What means " + ((100 * 1024*1024)/endPreAllocate) + " bytes per millisecond");
+            System.out.println("Pre allocating file done");  System.out.flush();
+            ArrayList<LocalAIO> list = new ArrayList<LocalAIO>();
+    
+            for (int i=0; i<NUMBER_LINES; i++)
             {
-                controller.pollEvents();
+                list.add(new LocalAIO(SIZE, latchDone));
             }
-        }.start();
-        
-        //controller.pollEvents();
-        //controller.startPoller();
-        System.out.println("Finished append " + (System.currentTimeMillis() - valueInitial) + " received = " + LocalAIO.staticDone);
-        System.out.println("Flush now");
-        System.out.println("Received " + LocalAIO.staticDone);
-        latchDone.await();
-
-        long timeTotal = System.currentTimeMillis() - valueInitial;
-        System.out.println("Flushed " + timeTotal);
-        System.out.println("time = " + timeTotal + " for " + NUMBER_LINES + " registers " + " size each line = " + SIZE  + " Records/Sec=" + (NUMBER_LINES*1000/timeTotal));
-
-        for (LocalAIO tmp: list)
+            
+           
+            long valueInitial = System.currentTimeMillis();
+            int counterFile=0;
+    
+            System.out.println("Adding data");
+            
+            long lastTime = System.currentTimeMillis();
+            int counter = 0;
+            for (LocalAIO tmp: list)
+            {
+                if (SIZE > 1024*1024) System.out.println("adding"); System.out.flush(); // deleteme
+                controller.append(tmp);
+                if (++counter % 500 == 0)
+                {
+                    System.out.println(500*1000/(System.currentTimeMillis()-lastTime) + " rec/sec");
+                    lastTime = System.currentTimeMillis();
+                }
+                
+            }
+            
+            System.out.println("Data added " + (System.currentTimeMillis() - valueInitial));
+            
+            
+            System.out.println("Finished append " + (System.currentTimeMillis() - valueInitial) + " received = " + LocalAIO.staticDone);
+            System.out.println("Flush now");
+            System.out.println("Received " + LocalAIO.staticDone);
+            latchDone.await();
+    
+            long timeTotal = System.currentTimeMillis() - valueInitial;
+            System.out.println("Flushed " + timeTotal);
+            System.out.println("time = " + timeTotal + " for " + NUMBER_LINES + " registers " + " size each line = " + SIZE  + " Records/Sec=" + (NUMBER_LINES*1000/timeTotal));
+    
+            for (LocalAIO tmp: list)
+            {
+                assertEquals(1, tmp.timesDoneCalled);
+                //assertTrue(tmp.encodeCalled);
+                //assertTrue(tmp.encodeSizeCalled);
+                assertTrue(tmp.doneCalled);
+            }
+            
+            
+            controller.close();
+        }
+        catch (Exception e)
         {
-            assertEquals(1, tmp.timesDoneCalled);
-            assertTrue(tmp.encodeCalled);
-            assertTrue(tmp.encodeSizeCalled);
-            assertTrue(tmp.doneCalled);
+            System.out.println("Received " + LocalAIO.staticDone + " before it failed");
         }
-
-        controller.close();
         
     }
     
@@ -129,7 +137,7 @@
         LocalAIO aio = new LocalAIO(500);
         
         controller.append(aio);
-        controller.pollEvents();
+//        controller.pollEvents();
         assertTrue(aio.doneCalled);
         assertEquals(1, aio.timesDoneCalled);
         controller.close();
@@ -141,7 +149,6 @@
 
         CountDownLatch latch;
         int size = 1;
-        byte[] buffer = null;
         public LocalAIO()
         {
             this(10);
@@ -152,11 +159,10 @@
             this.size = size;
         }
         
-        public LocalAIO(int size, byte[] buffer, CountDownLatch latch)
+        public LocalAIO(int size, CountDownLatch latch)
         {
             this(size);
             this.latch = latch;
-            this.buffer = buffer;
         }
         
         boolean encodeCalled = false;
@@ -172,11 +178,11 @@
 
         public void done()
         {
-            System.out.println("done - " + staticDone);
-            /*if (latch != null) 
+            //System.out.println("Received Done"); System.out.flush();
+            if (latch != null) 
             {
                 latch.countDown();
-            }*/
+            }
             doneCalled = true;
             timesDoneCalled++;
             staticDone++;
@@ -186,18 +192,11 @@
         public void encode(ByteBuffer buffer)
         {
             encodeCalled = true;
-            if (this.buffer!=null)
+            for (int i=0; i<size-1; i++)
             {
-                buffer.put(this.buffer);
+                buffer.put((byte)('A' + (i%10)));
             }
-            else
-            {
-                for (int i=0; i<size-1; i++)
-                {
-                    buffer.put((byte)('A' + (i%10)));
-                }
-                buffer.put((byte)'\n');
-            }
+            buffer.put((byte)'\n');
         }
 
         public int encodeSize()
@@ -208,7 +207,7 @@
 
         public void onError(int errorCode, String errorMessage)
         {
-            System.out.println("Error - " + errorCode + " message=" + errorMessage);
+            System.out.println("Received an Error - " + errorCode + " message=" + errorMessage);
             
         }
         




More information about the jboss-cvs-commits mailing list