[jboss-cvs] JBoss Messaging SVN: r3796 - in projects/jaio/trunk/jaio: java/tests/org/jboss/jaio/libaioimpl/test and 1 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Feb 25 16:13:47 EST 2008


Author: clebert.suconic at jboss.com
Date: 2008-02-25 16:13:47 -0500 (Mon, 25 Feb 2008)
New Revision: 3796

Modified:
   projects/jaio/trunk/jaio/java/build.xml
   projects/jaio/trunk/jaio/java/tests/org/jboss/jaio/libaioimpl/test/MultiThreadTests.java
   projects/jaio/trunk/jaio/native/README
Log:
Adding assertions on MultiThreadTest

Modified: projects/jaio/trunk/jaio/java/build.xml
===================================================================
--- projects/jaio/trunk/jaio/java/build.xml	2008-02-25 19:32:17 UTC (rev 3795)
+++ projects/jaio/trunk/jaio/java/build.xml	2008-02-25 21:13:47 UTC (rev 3796)
@@ -46,7 +46,7 @@
 			<batchtest todir="./output/testresult">
 				<formatter type="plain" usefile="${junit.formatter.usefile}"/>
 				<fileset dir="./output/testclasses">
-					<include name="**/TestController.class"/>
+					<include name="**/*Tests.class"/>
 				</fileset>
 			</batchtest>
 		</junit>

Modified: projects/jaio/trunk/jaio/java/tests/org/jboss/jaio/libaioimpl/test/MultiThreadTests.java
===================================================================
--- projects/jaio/trunk/jaio/java/tests/org/jboss/jaio/libaioimpl/test/MultiThreadTests.java	2008-02-25 19:32:17 UTC (rev 3795)
+++ projects/jaio/trunk/jaio/java/tests/org/jboss/jaio/libaioimpl/test/MultiThreadTests.java	2008-02-25 21:13:47 UTC (rev 3796)
@@ -5,7 +5,8 @@
 import java.util.LinkedList;
 import java.util.ArrayList;
 import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.ScheduledThreadPoolExecutor;
+import java.util.concurrent.Executor;
+import java.util.concurrent.Executors;
 import java.util.concurrent.Semaphore;
 import java.util.concurrent.atomic.AtomicInteger;
 
@@ -28,11 +29,11 @@
     
     static final int SIZE = 1024;
     static final int NUMBER_OF_THREADS = 40;
-    static final int NUMBER_OF_LINES = 1000;
+    static final int NUMBER_OF_LINES = 5000;
     
 //    Executor exec
     
-    static ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(1);
+    static Executor executor = Executors.newSingleThreadExecutor();
     
     static Semaphore semaphore = new Semaphore(1, false);
 
@@ -77,17 +78,17 @@
     private static void addData(JLibAIO aio, ByteBuffer buffer, AIOCallback callback) throws Exception
     {
         //aio.write(getNewPosition()*SIZE, SIZE, buffer, callback);
-        //executor.execute(new ExecClass(aio, buffer, callback));
+        executor.execute(new ExecClass(aio, buffer, callback));
         
-        semaphore.acquire();
-        try
-        {
-            aio.write(getNewPosition()*SIZE, SIZE, buffer, callback);
-        }
-        finally
-        {
-            semaphore.release();
-        }
+        //semaphore.acquire();
+        //try
+        //{
+            //aio.write(getNewPosition()*SIZE, SIZE, buffer, callback);
+        //}
+        //finally
+        //{
+        //    semaphore.release();
+        //}
         
         
         
@@ -121,15 +122,15 @@
         JLibAIO jlibAIO = new JLibAIO();
         jlibAIO.open(FILE_NAME, 21000);
         log.debug("Preallocating file");
-        jlibAIO.preAllocate(1, NUMBER_OF_THREADS * SIZE * NUMBER_OF_LINES);
+        jlibAIO.preAllocate(NUMBER_OF_THREADS,  SIZE * NUMBER_OF_LINES);
         log.debug("Done Preallocating file");
         
         CountDownLatch latchStart = new CountDownLatch (NUMBER_OF_THREADS + 1);
-        CountDownLatch latchEnd = new CountDownLatch (NUMBER_OF_THREADS);
+        
         ArrayList<ThreadProducer> list = new ArrayList<ThreadProducer>(NUMBER_OF_THREADS);
         for(int i=0;i<NUMBER_OF_THREADS;i++)
         {
-            ThreadProducer producer = new ThreadProducer("Thread " + i, latchStart, latchEnd, jlibAIO, sync);
+            ThreadProducer producer = new ThreadProducer("Thread " + i, latchStart, jlibAIO, sync);
             list.add(producer);
             producer.start();
         }
@@ -140,13 +141,6 @@
         
         long startTime = System.currentTimeMillis();
         
-        log.debug("Every started");
-        
-        latchEnd.await();
-        
-        long endTime = System.currentTimeMillis();
-        
-        log.debug((sync?"Sync result:":"Async result:") + " Records/Second = " + (NUMBER_OF_THREADS * NUMBER_OF_LINES * 1000 / (endTime - startTime)));
 
         
         for (ThreadProducer producer: list)
@@ -157,6 +151,10 @@
                 throw producer.failed;
             }
         }
+        long endTime = System.currentTimeMillis();
+        
+        log.debug((sync?"Sync result:":"Async result:") + " Records/Second = " + (NUMBER_OF_THREADS * NUMBER_OF_LINES * 1000 / (endTime - startTime)) + " total time = " + (endTime - startTime) + " total number of records = " + (NUMBER_OF_THREADS * NUMBER_OF_LINES));
+
         jlibAIO.close();
         
     }
@@ -171,32 +169,20 @@
     
     static class ThreadProducer extends Thread
     {
-        
-        //private CharsetEncoder UTF_8_ENCODER = Charset.forName("UTF-8").newEncoder();
 
         Throwable failed = null;
         CountDownLatch latchStart;
-        CountDownLatch latchEnd;
         boolean sync;
         JLibAIO libaio;
 
-        public ThreadProducer(String name, CountDownLatch latchStart, CountDownLatch latchEnd, JLibAIO libaio, boolean sync)
+        public ThreadProducer(String name, CountDownLatch latchStart, JLibAIO libaio, boolean sync)
         {
             super(name);
             this.latchStart = latchStart;
             this.libaio = libaio;
-            this.latchEnd = latchEnd;
             this.sync = sync;
         }
         
-        /*private void addString(String str, ByteBuffer buffer)
-        {
-            CharBuffer charBuffer = CharBuffer.wrap(str);
-            UTF_8_ENCODER.encode(charBuffer, buffer, true);
-            
-        }*/
-
-        
         public void run()
         {
             super.run();
@@ -205,6 +191,18 @@
             try
             {
                 
+                ByteBuffer buffer = libaio.newBuffer(SIZE);
+
+                // I'm aways reusing the same buffer, as I don't want any noise from malloc on the measurement
+                // Encoding buffer
+                addString ("Thread name=" + Thread.currentThread().getName() + ";" + "\n", buffer);
+                for (int local = buffer.position(); local < buffer.capacity() - 1; local++)
+                {
+                    buffer.put((byte)' ');
+                }
+                buffer.put((byte)'\n');
+
+
                 latchStart.countDown();
                 latchStart.await();
                 
@@ -219,36 +217,30 @@
                 
                 for (int i=0;i<NUMBER_OF_LINES;i++)
                 {
-                    ByteBuffer buffer = libaio.newBuffer(SIZE);
-
-                    //log.debug("Thread " + Thread.currentThread().getName() + " Adding a line");
-                    addString ("Thread name=" + Thread.currentThread().getName() + ";" + i + "\n", buffer);
-                    for (int local = buffer.position(); local < buffer.capacity() - 1; local++)
-                    {
-                        buffer.put((byte)' ');
-                    }
-                    buffer.put((byte)'\n');
                  
                     if (sync) latchFinishThread = new CountDownLatch(1);
                     LocalCallback callback = new LocalCallback(latchFinishThread, buffer, libaio);
-                    list.add(callback);
+                    if (!sync) list.add(callback);
                     addData(libaio, buffer,callback);
-                    //Thread.yield();
                     if (sync)
                     {
-                        //log.debug("Waiting to write");
                         latchFinishThread.await();
-                        //log.debug("done");
+                        assertTrue(callback.doneCalled);
+                        assertFalse(callback.errorCalled);
                     }
-                    //libaio.write(getNewPosition() * SIZE, SIZE, buffer, callback);
                 }
                 if (!sync) latchFinishThread.await();
+                for (LocalCallback callback: list)
+                {
+                    assertTrue (callback.doneCalled);
+                    assertFalse (callback.errorCalled);
+                }
                 
                 long endtime = System.currentTimeMillis();
                 
-                log.debug(Thread.currentThread().getName() + " Rec/Sec= " + (NUMBER_OF_LINES * 1000 / (endtime-startTime)));
+                log.debug(Thread.currentThread().getName() + " Rec/Sec= " + (NUMBER_OF_LINES * 1000 / (endtime-startTime)) + " total time = " + (endtime-startTime) + " number of lines=" + NUMBER_OF_LINES);
                 
-                latchEnd.countDown();
+                libaio.destroyBuffer(buffer);
                 
                 
                 for (LocalCallback callback: list)
@@ -296,7 +288,7 @@
         {
             doneCalled=true;
             latchDone.countDown();
-            libaio.destroyBuffer(releaseMe);
+            //libaio.destroyBuffer(releaseMe);
         }
 
         public void onError(int errorCode, String errorMessage)

Modified: projects/jaio/trunk/jaio/native/README
===================================================================
--- projects/jaio/trunk/jaio/native/README	2008-02-25 19:32:17 UTC (rev 3795)
+++ projects/jaio/trunk/jaio/native/README	2008-02-25 21:13:47 UTC (rev 3796)
@@ -1,13 +1,58 @@
+How to build jLibAIO:
+
+You will need to make sure you these following dependencies:
+
+ - G++
+ - Gcc
+ - autotools-dev (including libtool, automake, autoconf)
+ - Make
+ - libaio (0.3.106)
+ - libaio-dev
+ - JDK (full JDK)
+
+
+To build the native part:
+ Make sure you have JAVA_HOME defined, and pointing to the root of your JDK:
+ Example:
+ 
+ $> export JAVA_HOME=/usr/share/jdk1.5.0_13
+ 
+ 
+ Go to ./native and call bootstrap. Bootstrap will call all the initial scripts you need
+ $>  ./bootstrap
+ 
+ if you are missing any dependencies, autoconf would tell you what you're missing.
+ 
+ After bootstrap is called for the first time, you can aways build it by just calling make
+ 
+
+To run the java part:
+ Add <pathToYourProject>/native/src/.lib to LD_LIBRARY_PATH
+ Example:
+ 
+ $> export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/myWorkspace/native/src/.lib
+ 
+ $> cd ./java
+ 
+ $> ant tests
+ 
+ 
+ 
+
+
 Todo on the implementation:
-   - if queue is full, it needs to retry until it can find a slot
+   - if queue is full, it needs to retry until it can find a slot (ok)
 
 Todo on the API:
   - initialize with number of slots (ok)
   - newAlignedBuffer (ok)
   - destroyAlignedBuffer (ok)
-  - write (position, ByteBuffer, Callback)
-  - read (position, ByteBuffer, Callback)
+  - write (position, ByteBuffer, Callback) (ok)
+  - read (position, ByteBuffer, Callback) (ok)
   - Logging (callback in Java); (ok
+  - Add more logging on the native layer
+  - Organize error codes
+  
 
 
 
@@ -23,3 +68,5 @@
       - Update example
       - Max events ( /proc/sys/fs/aio-max-nr )
       - is io_submit should be thread safe if you sumit on different io_cbs
+
+ 




More information about the jboss-cvs-commits mailing list