[jboss-cvs] JBossCache/tests/perf/org/jboss/cache ...
Manik Surtani
msurtani at belmont.prod.atl2.jboss.com
Wed Aug 30 15:09:57 EDT 2006
User: msurtani
Date: 06/08/30 15:09:57
Modified: tests/perf/org/jboss/cache IdentityLockPerfTest.java
Log:
removed unnenessary (IDE-generated) TODOs that were becoming noisy
refactored identity lock constructors
Revision Changes Path
1.2 +140 -104 JBossCache/tests/perf/org/jboss/cache/IdentityLockPerfTest.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: IdentityLockPerfTest.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/tests/perf/org/jboss/cache/IdentityLockPerfTest.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- IdentityLockPerfTest.java 8 Jul 2005 05:58:08 -0000 1.1
+++ IdentityLockPerfTest.java 30 Aug 2006 19:09:57 -0000 1.2
@@ -12,17 +12,20 @@
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
-import org.jboss.cache.lock.*;
+import org.jboss.cache.lock.IdentityLock;
+import org.jboss.cache.lock.IsolationLevel;
+import org.jboss.cache.lock.LockStrategyFactory;
/**
* Tests performance of IdentityLock
*
* @author Bela Ban
- * @version $Id: IdentityLockPerfTest.java,v 1.1 2005/07/08 05:58:08 msurtani Exp $
+ * @version $Id: IdentityLockPerfTest.java,v 1.2 2006/08/30 19:09:57 msurtani Exp $
*/
-public class IdentityLockPerfTest extends TestCase {
- final int NUM=1000 * 1000;
- final int NUM_THREADS=10;
+public class IdentityLockPerfTest extends TestCase
+{
+ final int NUM = 1000 * 1000;
+ final int NUM_THREADS = 10;
long start, stop, total;
double locks_per_sec;
IdentityLock lock;
@@ -30,199 +33,231 @@
Object[] results;
- public IdentityLockPerfTest(String name) {
+ public IdentityLockPerfTest(String name)
+ {
super(name);
}
- public void testAcquireReadLocks() throws Exception {
+ public void testAcquireReadLocks() throws Exception
+ {
LockStrategyFactory.setIsolationLevel(IsolationLevel.REPEATABLE_READ);
- lock=new IdentityLock(null, null);
- Thread curr=Thread.currentThread();
+ lock = new IdentityLock(null);
+ Thread curr = Thread.currentThread();
- start=System.currentTimeMillis();
- for(int i=0; i < NUM; i++) {
+ start = System.currentTimeMillis();
+ for (int i = 0; i < NUM; i++)
+ {
lock.acquireReadLock(curr, 5000);
}
- stop=System.currentTimeMillis();
- total=stop-start;
- locks_per_sec=NUM / (total / 1000.0);
+ stop = System.currentTimeMillis();
+ total = stop - start;
+ locks_per_sec = NUM / (total / 1000.0);
System.out.println("Time to acquire " + NUM + " read locks: " + (total / 1000.0) + " secs" +
" (" + locks_per_sec + " locks/sec)");
}
- public void testAcquireAndReleaseReadLocks() throws Exception {
+ public void testAcquireAndReleaseReadLocks() throws Exception
+ {
LockStrategyFactory.setIsolationLevel(IsolationLevel.REPEATABLE_READ);
- lock=new IdentityLock(null, null);
- Thread curr=Thread.currentThread();
+ lock = new IdentityLock(null);
+ Thread curr = Thread.currentThread();
- start=System.currentTimeMillis();
- for(int i=0; i < NUM; i++) {
+ start = System.currentTimeMillis();
+ for (int i = 0; i < NUM; i++)
+ {
lock.acquireReadLock(curr, 5000);
lock.release(curr);
}
- stop=System.currentTimeMillis();
- total=stop-start;
- locks_per_sec=NUM / (total / 1000.0);
+ stop = System.currentTimeMillis();
+ total = stop - start;
+ locks_per_sec = NUM / (total / 1000.0);
System.out.println("Time to acquire and release " + NUM + " read locks: " + (total / 1000.0) + " secs" +
" (" + locks_per_sec + " locks/sec)");
}
- public void testAcquireAndUpgradeReadLocks() throws Exception {
+ public void testAcquireAndUpgradeReadLocks() throws Exception
+ {
LockStrategyFactory.setIsolationLevel(IsolationLevel.REPEATABLE_READ);
- lock=new IdentityLock(null, null);
- Thread curr=Thread.currentThread();
+ lock = new IdentityLock(null);
+ Thread curr = Thread.currentThread();
- start=System.currentTimeMillis();
- for(int i=0; i < NUM; i++) {
+ start = System.currentTimeMillis();
+ for (int i = 0; i < NUM; i++)
+ {
lock.acquireReadLock(curr, 5000);
lock.acquireWriteLock(curr, 5000);
}
- stop=System.currentTimeMillis();
- total=stop-start;
- locks_per_sec=NUM / (total / 1000.0);
+ stop = System.currentTimeMillis();
+ total = stop - start;
+ locks_per_sec = NUM / (total / 1000.0);
System.out.println("Time to acquire and upgrade " + NUM + " read locks: " + (total / 1000.0) + " secs" +
" (" + locks_per_sec + " locks/sec)");
}
- public void testAcquireWriteLocks() throws Exception {
+ public void testAcquireWriteLocks() throws Exception
+ {
LockStrategyFactory.setIsolationLevel(IsolationLevel.REPEATABLE_READ);
- lock=new IdentityLock(null, null);
- Thread curr=Thread.currentThread();
+ lock = new IdentityLock(null);
+ Thread curr = Thread.currentThread();
- start=System.currentTimeMillis();
- for(int i=0; i < NUM; i++) {
+ start = System.currentTimeMillis();
+ for (int i = 0; i < NUM; i++)
+ {
lock.acquireWriteLock(curr, 5000);
}
- stop=System.currentTimeMillis();
- total=stop-start;
- locks_per_sec=NUM / (total / 1000.0);
+ stop = System.currentTimeMillis();
+ total = stop - start;
+ locks_per_sec = NUM / (total / 1000.0);
System.out.println("Time to acquire " + NUM + " write locks: " + (total / 1000.0) + " secs" +
" (" + locks_per_sec + " locks/sec)");
}
- public void testAcquireAndReleaseWriteLocks() throws Exception {
+ public void testAcquireAndReleaseWriteLocks() throws Exception
+ {
LockStrategyFactory.setIsolationLevel(IsolationLevel.REPEATABLE_READ);
- lock=new IdentityLock(null, null);
- Thread curr=Thread.currentThread();
+ lock = new IdentityLock(null);
+ Thread curr = Thread.currentThread();
- start=System.currentTimeMillis();
- for(int i=0; i < NUM; i++) {
+ start = System.currentTimeMillis();
+ for (int i = 0; i < NUM; i++)
+ {
lock.acquireWriteLock(curr, 5000);
lock.release(curr);
}
- stop=System.currentTimeMillis();
- total=stop-start;
- locks_per_sec=NUM / (total / 1000.0);
+ stop = System.currentTimeMillis();
+ total = stop - start;
+ locks_per_sec = NUM / (total / 1000.0);
System.out.println("Time to acquire " + NUM + " write locks: " + (total / 1000.0) + " secs" +
" (" + locks_per_sec + " locks/sec)");
}
- public void testConcurrentReadLockAcquisition() throws Exception {
+ public void testConcurrentReadLockAcquisition() throws Exception
+ {
LockStrategyFactory.setIsolationLevel(IsolationLevel.REPEATABLE_READ);
- lock=new IdentityLock(null, null);
- threads=new Thread[NUM_THREADS];
- results=new Object[NUM_THREADS];
-
- for(int i=0; i < threads.length; i++) {
- threads[i]=new Reader(i);
+ lock = new IdentityLock(null);
+ threads = new Thread[NUM_THREADS];
+ results = new Object[NUM_THREADS];
+
+ for (int i = 0; i < threads.length; i++)
+ {
+ threads[i] = new Reader(i);
}
System.out.println("-- starting all " + NUM_THREADS + " threads");
- start=System.currentTimeMillis();
- for(int i=0; i < threads.length; i++) {
+ start = System.currentTimeMillis();
+ for (int i = 0; i < threads.length; i++)
+ {
threads[i].start();
}
System.out.println("-- waiting for all threads to terminate");
- for(int i=0; i < threads.length; i++) {
+ for (int i = 0; i < threads.length; i++)
+ {
threads[i].join();
}
- stop=System.currentTimeMillis();
+ stop = System.currentTimeMillis();
- for(int i=0; i < results.length; i++) {
- if(results[i] != null && results[i] instanceof Exception)
+ for (int i = 0; i < results.length; i++)
+ {
+ if (results[i] != null && results[i] instanceof Exception)
fail("result[" + i + "]: " + results[i]);
}
- total=stop-start;
- locks_per_sec=NUM * NUM_THREADS / (total / 1000.0);
+ total = stop - start;
+ locks_per_sec = NUM * NUM_THREADS / (total / 1000.0);
System.out.println("Time to acquire " + NUM * NUM_THREADS + " read locks: " + (total / 1000.0) + " secs" +
" (" + locks_per_sec + " locks/sec)");
}
- public void testConcurrentWriteLockAcquisition() throws Exception {
+ public void testConcurrentWriteLockAcquisition() throws Exception
+ {
LockStrategyFactory.setIsolationLevel(IsolationLevel.REPEATABLE_READ);
- lock=new IdentityLock(null, null);
- threads=new Thread[NUM_THREADS];
- results=new Object[NUM_THREADS];
-
- for(int i=0; i < threads.length; i++) {
- threads[i]=new Writer(i);
+ lock = new IdentityLock(null);
+ threads = new Thread[NUM_THREADS];
+ results = new Object[NUM_THREADS];
+
+ for (int i = 0; i < threads.length; i++)
+ {
+ threads[i] = new Writer(i);
}
System.out.println("-- starting all " + NUM_THREADS + " threads");
- start=System.currentTimeMillis();
- for(int i=0; i < threads.length; i++) {
+ start = System.currentTimeMillis();
+ for (int i = 0; i < threads.length; i++)
+ {
threads[i].start();
}
System.out.println("-- waiting for all threads to terminate");
- for(int i=0; i < threads.length; i++) {
+ for (int i = 0; i < threads.length; i++)
+ {
threads[i].join();
}
- stop=System.currentTimeMillis();
+ stop = System.currentTimeMillis();
- for(int i=0; i < results.length; i++) {
- if(results[i] != null && results[i] instanceof Exception)
+ for (int i = 0; i < results.length; i++)
+ {
+ if (results[i] != null && results[i] instanceof Exception)
fail("result[" + i + "]: " + results[i]);
}
- total=stop-start;
- locks_per_sec=NUM * NUM_THREADS / (total / 1000.0);
+ total = stop - start;
+ locks_per_sec = NUM * NUM_THREADS / (total / 1000.0);
System.out.println("Time to acquire " + NUM * NUM_THREADS + " write locks: " + (total / 1000.0) + " secs" +
" (" + locks_per_sec + " locks/sec)");
}
-
- class Reader extends Thread {
- int num=-1;
-
- Reader(int num) {
- this.num=num;
+ class Reader extends Thread
+ {
+ int num = -1;
+
+ Reader(int num)
+ {
+ this.num = num;
}
- public void run() {
- for(int i=0; i < NUM; i++) {
- try {
+ public void run()
+ {
+ for (int i = 0; i < NUM; i++)
+ {
+ try
+ {
lock.acquireReadLock(this, 5000);
}
- catch(Exception e) {
- results[i]=e;
+ catch (Exception e)
+ {
+ results[i] = e;
break;
}
}
}
}
- class Writer extends Thread {
- int num=-1;
-
- Writer(int num) {
- this.num=num;
+ class Writer extends Thread
+ {
+ int num = -1;
+
+ Writer(int num)
+ {
+ this.num = num;
}
- public void run() {
- for(int i=0; i < NUM; i++) {
- try {
+ public void run()
+ {
+ for (int i = 0; i < NUM; i++)
+ {
+ try
+ {
lock.acquireWriteLock(this, 15000);
lock.release(this);
}
- catch(Exception e) {
- results[i]=e;
+ catch (Exception e)
+ {
+ results[i] = e;
break;
}
}
@@ -230,7 +265,8 @@
}
- public static Test suite() throws Exception {
+ public static Test suite() throws Exception
+ {
return new TestSuite(IdentityLockPerfTest.class);
}
More information about the jboss-cvs-commits
mailing list