Author: manik.surtani(a)jboss.com
Date: 2008-02-05 22:22:00 -0500 (Tue, 05 Feb 2008)
New Revision: 5311
Modified:
core/trunk/src/main/java/org/jboss/cache/InvocationContext.java
core/trunk/src/main/java/org/jboss/cache/factories/InterceptorChainFactory.java
core/trunk/src/main/java/org/jboss/cache/interceptors/MethodDispacherInterceptor.java
core/trunk/src/main/java/org/jboss/cache/interceptors/PessimisticLockInterceptor.java
core/trunk/src/main/java/org/jboss/cache/interceptors/UnlockInterceptor.java
core/trunk/src/main/java/org/jboss/cache/lock/LockMap.java
core/trunk/src/test/java/org/jboss/cache/factories/InterceptorChainFactoryTest.java
core/trunk/src/test/java/org/jboss/cache/profiling/ProfileTest.java
Log:
Improved performance in a few places, including:
1) Getting rid of the UnlockInterceptor and combining this with the pessimistic lock
interceptor
2) Getting rid of the LockMap, which was only used to share invocation scope locks betweek
the above 2 interceptors
3) Got rid of the ConcurrentHashSet in LockMap in favour of a synchronised LinkedList
which performed better.
Modified: core/trunk/src/main/java/org/jboss/cache/InvocationContext.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/InvocationContext.java 2008-02-06 03:16:44
UTC (rev 5310)
+++ core/trunk/src/main/java/org/jboss/cache/InvocationContext.java 2008-02-06 03:22:00
UTC (rev 5311)
@@ -7,10 +7,14 @@
package org.jboss.cache;
import org.jboss.cache.config.Option;
+import org.jboss.cache.lock.NodeLock;
import org.jboss.cache.marshall.MethodCall;
import org.jboss.cache.transaction.GlobalTransaction;
import javax.transaction.Transaction;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
/**
* This context holds information specific to a method invocation.
@@ -150,6 +154,32 @@
return originLocal;
}
+ List<NodeLock> invocationLocks;
+
+ public List<NodeLock> getInvocationLocksAcquired()
+ {
+ return invocationLocks;
+ }
+
+ public void addInvocationLocksAcquired(Collection<NodeLock> locks)
+ {
+ // no need to worry about concurrency here - a context is only valid for a single
thread.
+ if (invocationLocks == null) invocationLocks = new ArrayList<NodeLock>(5);
+ invocationLocks.addAll(locks);
+ }
+
+ public void addInvocationLockAcquired(NodeLock l)
+ {
+ // no need to worry about concurrency here - a context is only valid for a single
thread.
+ if (invocationLocks == null) invocationLocks = new ArrayList<NodeLock>(5);
+ invocationLocks.add(l);
+ }
+
+ public void clearInvocationLocksAcquired()
+ {
+ invocationLocks = null;
+ }
+
/**
* If set to true, the invocation is assumed to have originated locally. If set to
false,
* assumed to have originated from a remote cache.
@@ -198,6 +228,7 @@
optionOverrides = null;
originLocal = true;
txHasMods = false;
+ invocationLocks = null;
}
public InvocationContext clone() throws CloneNotSupportedException
Modified: core/trunk/src/main/java/org/jboss/cache/factories/InterceptorChainFactory.java
===================================================================
---
core/trunk/src/main/java/org/jboss/cache/factories/InterceptorChainFactory.java 2008-02-06
03:16:44 UTC (rev 5310)
+++
core/trunk/src/main/java/org/jboss/cache/factories/InterceptorChainFactory.java 2008-02-06
03:22:00 UTC (rev 5311)
@@ -115,7 +115,7 @@
if (!optimistic)
{
addInterceptor(first, PessimisticLockInterceptor.class);
- addInterceptor(first, UnlockInterceptor.class);
+// addInterceptor(first, UnlockInterceptor.class);
}
if (isUsingCacheLoaders())
Modified:
core/trunk/src/main/java/org/jboss/cache/interceptors/MethodDispacherInterceptor.java
===================================================================
---
core/trunk/src/main/java/org/jboss/cache/interceptors/MethodDispacherInterceptor.java 2008-02-06
03:16:44 UTC (rev 5310)
+++
core/trunk/src/main/java/org/jboss/cache/interceptors/MethodDispacherInterceptor.java 2008-02-06
03:22:00 UTC (rev 5311)
@@ -51,16 +51,13 @@
{
if (trace) log.trace("Invoked with method call " + ctx.getMethodCall());
- if (skipMethodCall(ctx))
- {
- return nextInterceptor(ctx);
- }
MethodCall m = ctx.getMethodCall();
- if (!overriddenMethods.contains(m.getMethodId()))
+ if (!overriddenMethods.contains(m.getMethodId()) || skipMethodCall(ctx))
{
- if (trace) log.trace("Not registered for any handlers, passing up the
chain.");
+ if (trace) log.trace("Not registered for any handlers, or instructed to
skip call. Passing up the chain.");
return nextInterceptor(ctx);
}
+
Object[] args = m.getArgs();
Object result;
switch (m.getMethodId())
@@ -288,7 +285,7 @@
}
/**
- * Handles {@link org.jboss.cache.CacheImpl#evict(org.jboss.cache.Fqn)}
+ * Handles evict()
*/
protected Object handleEvictMethod(InvocationContext ctx, Fqn fqn) throws Throwable
{
Modified:
core/trunk/src/main/java/org/jboss/cache/interceptors/PessimisticLockInterceptor.java
===================================================================
---
core/trunk/src/main/java/org/jboss/cache/interceptors/PessimisticLockInterceptor.java 2008-02-06
03:16:44 UTC (rev 5310)
+++
core/trunk/src/main/java/org/jboss/cache/interceptors/PessimisticLockInterceptor.java 2008-02-06
03:22:00 UTC (rev 5311)
@@ -12,7 +12,6 @@
import org.jboss.cache.Node;
import org.jboss.cache.NodeSPI;
import org.jboss.cache.config.Configuration;
-import org.jboss.cache.factories.annotations.ComponentName;
import org.jboss.cache.factories.annotations.Inject;
import org.jboss.cache.lock.IsolationLevel;
import org.jboss.cache.lock.LockingException;
@@ -24,7 +23,7 @@
import org.jboss.cache.transaction.TransactionTable;
import org.jgroups.Address;
-import java.util.Collections;
+import javax.transaction.Transaction;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
@@ -57,7 +56,6 @@
/**
* Map<Thread, List<NodeLock>>. Keys = threads, values = lists of locks
held by that thread
*/
- private Map<Thread, List<NodeLock>> lockTable;
// private ThreadLocal<List<NodeLock>> lockTable;
private long lock_acquisition_timeout;
@@ -67,10 +65,10 @@
}
@Inject
- public void injectDependencies(@ComponentName("LockTable")Map<Thread,
List<NodeLock>> lockTable, Configuration configuration, CacheImpl cacheImpl,
TransactionTable txTable)
-// public void
injectDependencies(@ComponentName("LockTable")ThreadLocal<List<NodeLock>>
lockTable, Configuration configuration, CacheImpl cacheImpl, TransactionTable txTable)
+ public void injectDependencies(Configuration configuration, CacheImpl cacheImpl,
TransactionTable txTable)
+// public void injectDependencies(@ComponentName("LockTable")Map<Thread,
List<NodeLock>> lockTable, Configuration configuration, CacheImpl cacheImpl,
TransactionTable txTable)
{
- this.lockTable = lockTable;
+// this.lockTable = lockTable;
lock_acquisition_timeout = configuration.getLockAcquisitionTimeout();
this.cacheImpl = cacheImpl;
this.tx_table = txTable;
@@ -84,18 +82,55 @@
{
return super.invoke(ctx);
}
- catch (LockingException le)
+// catch (LockingException le)
+// {
+// if (trace) log.trace("Locking exception occured, cleaning up
locks.", le);
+// releaseLocks(ctx);
+// throw le;
+// }
+// catch (TimeoutException te)
+// {
+// if (trace) log.trace("Locking exception occured, cleaning up
locks.", te);
+// releaseLocks(ctx);
+// throw te;
+// }
+ finally
{
- if (trace) log.trace("Locking exception occured, cleaning up locks.",
le);
- releaseLocks(ctx);
- throw le;
+ // This is functionality from the UnlockInterceptor:
+ // for non-tx calls, release any locks acquired. These used to be in a separate
Map<Thread, List<NodeLock>> called a lockTable,
+ // but that has been dropped in facour of storing the invocation-specific locks
in the invocation context. Cleaner to have it all
+ // in one place, plus much more performant.
+
+ if (ctx.getOptionOverrides() == null ||
!ctx.getOptionOverrides().isSuppressLocking())
+ {
+ Transaction tx = ctx.getTransaction();
+ if (tx == null || !isValid(tx))
+ { // no TX
+ List<NodeLock> locks = ctx.getInvocationLocksAcquired();
+ if (trace)
+ log.trace("Attempting to release locks on current thread. Locks
for the invocation is " + locks);
+
+ if (locks != null && locks.size() > 0)
+ {
+ Thread currentThread = Thread.currentThread();
+ try
+ {
+ // make sure we release locks in *reverse* order!
+ for (int i = locks.size() - 1; i > -1; i--)
+ {
+ NodeLock nl = locks.get(i);
+ if (trace) log.trace("releasing lock for " +
nl.getFqn() + ": " + nl);
+ nl.release(currentThread);
+ }
+ }
+ finally
+ {
+ ctx.clearInvocationLocksAcquired();
+ }
+ }
+ }
+ }
}
- catch (TimeoutException te)
- {
- if (trace) log.trace("Locking exception occured, cleaning up locks.",
te);
- releaseLocks(ctx);
- throw te;
- }
}
/**
@@ -104,22 +139,27 @@
*/
private void releaseLocks(InvocationContext ctx)
{
- GlobalTransaction gtx = ctx.getGlobalTransaction();
- if (trace) log.trace("Releasing existing locks. Global tx?" + gtx);
- if (gtx != null)
- {
- TransactionEntry te = cache.getTransactionTable().get(gtx);
- te.releaseAllLocksFIFO(gtx);
- }
- else
- {
- Thread currentThread = Thread.currentThread();
- List<NodeLock> locks = getLocks(currentThread);
- for (NodeLock aLock : locks)
- {
- aLock.release(currentThread);
- }
- }
+ // This should not be necessary - the finally block above will take care of non-tx
calls that need cleaning up, even
+ // if there is an exception.
+ // For tx calls, the TxManager will call a rollback to free up resources. -- MS
+
+// GlobalTransaction gtx = ctx.getGlobalTransaction();
+// if (trace) log.trace("Releasing existing locks. Global tx?" + gtx);
+// if (gtx != null)
+// {
+// TransactionEntry te = cache.getTransactionTable().get(gtx);
+// te.releaseAllLocksFIFO(gtx);
+// }
+// else
+// {
+// Thread currentThread = Thread.currentThread();
+// List<NodeLock> locks = ctx.getInvocationLocksAcquired();
+// if (locks != null)
+// for (NodeLock aLock : locks)
+// {
+// aLock.release(currentThread);
+// }
+// }
}
@@ -470,7 +510,7 @@
Fqn currentNodeFqn = currentNode.getFqn();
// actually acquire the lock we need. This method blocks.
- acquireNodeLock(currentNode, owner, gtx, lockTypeRequired, timeout);
+ acquireNodeLock(ctx, currentNode, owner, gtx, lockTypeRequired, timeout);
manageReverseRemove(gtx, currentNode, reverseRemoveCheck);
// make sure the lock we acquired isn't on a deleted node/is an orphan!!
@@ -556,8 +596,7 @@
}
else
{
- List<NodeLock> locks = getLocks(Thread.currentThread());
- locks.addAll(acquiredLocks);
+ ctx.addInvocationLocksAcquired(acquiredLocks);
}
}
}
@@ -589,7 +628,7 @@
return lockType == NodeLock.LockType.WRITE && isTargetNode;//write lock
explicitly requested and this is the target to be written to.
}
- private void acquireNodeLock(NodeSPI node, Object owner, GlobalTransaction gtx,
NodeLock.LockType lockType, long lockTimeout) throws LockingException, TimeoutException,
InterruptedException
+ private void acquireNodeLock(InvocationContext ctx, NodeSPI node, Object owner,
GlobalTransaction gtx, NodeLock.LockType lockType, long lockTimeout) throws
LockingException, TimeoutException, InterruptedException
{
NodeLock lock = node.getLock();
boolean acquired = lock.acquire(owner, lockTimeout, lockType);
@@ -602,32 +641,11 @@
}
else
{
- Thread currentThread = Thread.currentThread();
- List<NodeLock> locks = getLocks(currentThread);
- if (!locks.contains(lock))
- {
- locks.add(lock);
- lockTable.put(currentThread, locks);
- }
+ ctx.addInvocationLockAcquired(lock);
}
}
}
- private List<NodeLock> getLocks(Thread currentThread)
- {
- // This sort of looks like a get/put race condition, but
- // since we key off the Thread, it's not
- List<NodeLock> locks = lockTable.get(currentThread);
- if (locks == null)
- {
- locks = Collections.synchronizedList(new LinkedList<NodeLock>());
-// lockTable.set(locks);
- lockTable.put(currentThread, locks);
- }
- return locks;
- }
-
-
/**
* Test if this node needs to be 'undeleted'
* reverse the "remove" if the node has been previously removed in the same
tx, if this operation is a put()
Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/UnlockInterceptor.java
===================================================================
---
core/trunk/src/main/java/org/jboss/cache/interceptors/UnlockInterceptor.java 2008-02-06
03:16:44 UTC (rev 5310)
+++
core/trunk/src/main/java/org/jboss/cache/interceptors/UnlockInterceptor.java 2008-02-06
03:22:00 UTC (rev 5311)
@@ -16,6 +16,7 @@
* @author Bela Ban
* @version $Id$
*/
+@Deprecated
public class UnlockInterceptor extends Interceptor
{
Modified: core/trunk/src/main/java/org/jboss/cache/lock/LockMap.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/lock/LockMap.java 2008-02-06 03:16:44 UTC
(rev 5310)
+++ core/trunk/src/main/java/org/jboss/cache/lock/LockMap.java 2008-02-06 03:22:00 UTC
(rev 5311)
@@ -6,11 +6,10 @@
*/
package org.jboss.cache.lock;
-import org.jboss.cache.util.concurrent.ConcurrentHashSet;
-
import java.util.Collection;
import java.util.Collections;
-import java.util.Set;
+import java.util.LinkedList;
+import java.util.List;
/**
* Provide lock ownership mapping.
@@ -28,8 +27,8 @@
// This is more efficient (lower CPU utilisation and better concurrency) than a
CopyOnWriteArraySet or ConcurrentHashSet.
// for some reason this barfs with concurrent mod exceptions. Need to see why.
- // private final List<Object> readOwnerList_ = Collections.synchronizedList(new
LinkedList<Object>());
- private final Set<Object> readOwnerList_ = new
ConcurrentHashSet<Object>();
+ private final List<Object> readOwnerList_ = Collections.synchronizedList(new
LinkedList<Object>());
+// private final Set<Object> readOwnerList_ = new
ConcurrentHashSet<Object>();
/**
* Check whether this owner has reader or writer ownership.
@@ -49,7 +48,7 @@
switch (ownership)
{
case OWNER_ANY:
- return (writeOwner_ != null && caller.equals(writeOwner_) ||
readOwnerList_.contains(caller));
+ return ((writeOwner_ != null && caller.equals(writeOwner_)) ||
readOwnerList_.contains(caller));
case OWNER_READ:
return (readOwnerList_.contains(caller));
case OWNER_WRITE:
@@ -117,8 +116,8 @@
*/
public Collection<Object> readerOwners()
{
- //return Collections.unmodifiableList(readOwnerList_);
- return Collections.unmodifiableSet(readOwnerList_);
+ return readOwnerList_;
+// return Collections.unmodifiableSet(readOwnerList_);
}
public void releaseReaderOwners(LockStrategy lock)
Modified:
core/trunk/src/test/java/org/jboss/cache/factories/InterceptorChainFactoryTest.java
===================================================================
---
core/trunk/src/test/java/org/jboss/cache/factories/InterceptorChainFactoryTest.java 2008-02-06
03:16:44 UTC (rev 5310)
+++
core/trunk/src/test/java/org/jboss/cache/factories/InterceptorChainFactoryTest.java 2008-02-06
03:22:00 UTC (rev 5311)
@@ -51,13 +51,12 @@
System.out.println("testBareConfig interceptors are:\n" + list);
assertNotNull(list);
- assertEquals(6, list.size());
+ assertEquals(5, list.size());
assertEquals(InvocationContextInterceptor.class, interceptors.next().getClass());
assertEquals(TxInterceptor.class, interceptors.next().getClass());
assertEquals(NotificationInterceptor.class, interceptors.next().getClass());
assertEquals(PessimisticLockInterceptor.class, interceptors.next().getClass());
- assertEquals(UnlockInterceptor.class, interceptors.next().getClass());
assertEquals(CallInterceptor.class, interceptors.next().getClass());
assertInterceptorLinkage(list);
@@ -75,13 +74,12 @@
System.out.println("testTxConfig interceptors are:\n" + list);
assertNotNull(list);
- assertEquals(6, list.size());
+ assertEquals(5, list.size());
assertEquals(InvocationContextInterceptor.class, interceptors.next().getClass());
assertEquals(TxInterceptor.class, interceptors.next().getClass());
assertEquals(NotificationInterceptor.class, interceptors.next().getClass());
assertEquals(PessimisticLockInterceptor.class, interceptors.next().getClass());
- assertEquals(UnlockInterceptor.class, interceptors.next().getClass());
assertEquals(CallInterceptor.class, interceptors.next().getClass());
assertInterceptorLinkage(list);
@@ -124,14 +122,13 @@
System.out.println("testSharedCacheLoaderConfig interceptors are:\n" +
list);
assertNotNull(list);
- assertEquals(9, list.size());
+ assertEquals(8, list.size());
assertEquals(InvocationContextInterceptor.class, interceptors.next().getClass());
assertEquals(TxInterceptor.class, interceptors.next().getClass());
assertEquals(NotificationInterceptor.class, interceptors.next().getClass());
assertEquals(ReplicationInterceptor.class, interceptors.next().getClass());
assertEquals(PessimisticLockInterceptor.class, interceptors.next().getClass());
- assertEquals(UnlockInterceptor.class, interceptors.next().getClass());
assertEquals(CacheLoaderInterceptor.class, interceptors.next().getClass());
assertEquals(CacheStoreInterceptor.class, interceptors.next().getClass());
assertEquals(CallInterceptor.class, interceptors.next().getClass());
@@ -154,14 +151,13 @@
System.out.println("testUnsharedCacheLoaderConfig interceptors are:\n" +
list);
assertNotNull(list);
- assertEquals(9, list.size());
+ assertEquals(8, list.size());
assertEquals(InvocationContextInterceptor.class, interceptors.next().getClass());
assertEquals(TxInterceptor.class, interceptors.next().getClass());
assertEquals(NotificationInterceptor.class, interceptors.next().getClass());
assertEquals(ReplicationInterceptor.class, interceptors.next().getClass());
assertEquals(PessimisticLockInterceptor.class, interceptors.next().getClass());
- assertEquals(UnlockInterceptor.class, interceptors.next().getClass());
assertEquals(CacheLoaderInterceptor.class, interceptors.next().getClass());
assertEquals(CacheStoreInterceptor.class, interceptors.next().getClass());
assertEquals(CallInterceptor.class, interceptors.next().getClass());
@@ -181,14 +177,13 @@
System.out.println("testTxAndRepl interceptors are:\n" + list);
assertNotNull(list);
- assertEquals(7, list.size());
+ assertEquals(6, list.size());
assertEquals(InvocationContextInterceptor.class, interceptors.next().getClass());
assertEquals(TxInterceptor.class, interceptors.next().getClass());
assertEquals(NotificationInterceptor.class, interceptors.next().getClass());
assertEquals(ReplicationInterceptor.class, interceptors.next().getClass());
assertEquals(PessimisticLockInterceptor.class, interceptors.next().getClass());
- assertEquals(UnlockInterceptor.class, interceptors.next().getClass());
assertEquals(CallInterceptor.class, interceptors.next().getClass());
assertInterceptorLinkage(list);
@@ -314,14 +309,13 @@
List<Interceptor> list = getInterceptorChainFactory(cache).asList(chain);
Iterator<Interceptor> interceptors = list.iterator();
- assertEquals(7, list.size());
+ assertEquals(6, list.size());
assertEquals(InvocationContextInterceptor.class, interceptors.next().getClass());
assertEquals(TxInterceptor.class, interceptors.next().getClass());
assertEquals(NotificationInterceptor.class, interceptors.next().getClass());
assertEquals(ReplicationInterceptor.class, interceptors.next().getClass());
assertEquals(PessimisticLockInterceptor.class, interceptors.next().getClass());
- assertEquals(UnlockInterceptor.class, interceptors.next().getClass());
assertEquals(CallInterceptor.class, interceptors.next().getClass());
// ok, my replication chain looks good.
@@ -335,14 +329,13 @@
list = getInterceptorChainFactory(cache).asList(chain);
interceptors = list.iterator();
- assertEquals(7, list.size());
+ assertEquals(6, list.size());
assertEquals(InvocationContextInterceptor.class, interceptors.next().getClass());
assertEquals(TxInterceptor.class, interceptors.next().getClass());
assertEquals(NotificationInterceptor.class, interceptors.next().getClass());
assertEquals(InvalidationInterceptor.class, interceptors.next().getClass());
assertEquals(PessimisticLockInterceptor.class, interceptors.next().getClass());
- assertEquals(UnlockInterceptor.class, interceptors.next().getClass());
assertEquals(CallInterceptor.class, interceptors.next().getClass());
assertInterceptorLinkage(list);
@@ -357,14 +350,13 @@
System.out.println("testCacheMgmtConfig interceptors are:\n" + list);
assertNotNull(list);
- assertEquals(7, list.size());
+ assertEquals(6, list.size());
assertEquals(InvocationContextInterceptor.class, interceptors.next().getClass());
assertEquals(CacheMgmtInterceptor.class, interceptors.next().getClass());
assertEquals(TxInterceptor.class, interceptors.next().getClass());
assertEquals(NotificationInterceptor.class, interceptors.next().getClass());
assertEquals(PessimisticLockInterceptor.class, interceptors.next().getClass());
- assertEquals(UnlockInterceptor.class, interceptors.next().getClass());
assertEquals(CallInterceptor.class, interceptors.next().getClass());
assertInterceptorLinkage(list);
@@ -389,14 +381,13 @@
System.out.println("testEvictionInterceptorConfig interceptors are:\n" +
list);
assertNotNull(list);
- assertEquals(8, list.size());
+ assertEquals(7, list.size());
assertEquals(InvocationContextInterceptor.class, interceptors.next().getClass());
assertEquals(CacheMgmtInterceptor.class, interceptors.next().getClass());
assertEquals(TxInterceptor.class, interceptors.next().getClass());
assertEquals(NotificationInterceptor.class, interceptors.next().getClass());
assertEquals(PessimisticLockInterceptor.class, interceptors.next().getClass());
- assertEquals(UnlockInterceptor.class, interceptors.next().getClass());
assertEquals(EvictionInterceptor.class, interceptors.next().getClass());
assertEquals(CallInterceptor.class, interceptors.next().getClass());
@@ -465,7 +456,7 @@
System.out.println("testEvictionInterceptorConfig interceptors are:\n" +
list);
assertNotNull(list);
- assertEquals(9, list.size());
+ assertEquals(8, list.size());
assertEquals(InvocationContextInterceptor.class, interceptors.next().getClass());
assertEquals(CacheMgmtInterceptor.class, interceptors.next().getClass());
@@ -473,7 +464,6 @@
assertEquals(NotificationInterceptor.class, interceptors.next().getClass());
assertEquals(ReplicationInterceptor.class, interceptors.next().getClass());
assertEquals(PessimisticLockInterceptor.class, interceptors.next().getClass());
- assertEquals(UnlockInterceptor.class, interceptors.next().getClass());
assertEquals(DataGravitatorInterceptor.class, interceptors.next().getClass());
assertEquals(CallInterceptor.class, interceptors.next().getClass());
Modified: core/trunk/src/test/java/org/jboss/cache/profiling/ProfileTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/profiling/ProfileTest.java 2008-02-06
03:16:44 UTC (rev 5310)
+++ core/trunk/src/test/java/org/jboss/cache/profiling/ProfileTest.java 2008-02-06
03:22:00 UTC (rev 5311)
@@ -193,17 +193,10 @@
long end = System.currentTimeMillis() + DURATION;
long startTime = System.currentTimeMillis();
log.warn("Starting test");
+ int i = 0;
while (System.currentTimeMillis() < end)
{
- exec.execute(new Runnable()
- {
- public void run()
- {
- String k = getRandomString();
- String v = getRandomString();
- cache.put(fqns.get(r.nextInt(MAX_OVERALL_NODES)), k, v);
- }
- });
+ exec.execute(new MyRunnable(i++));
TestingUtil.sleepRandom(MAX_RANDOM_SLEEP_MILLIS);
}
log.warn("Finished generating runnables; awaiting executor completion");
@@ -214,6 +207,24 @@
log.warn("Finished test. " + printDuration(duration));
}
+ private class MyRunnable implements Runnable
+ {
+ int id;
+
+ private MyRunnable(int id)
+ {
+ this.id = id;
+ }
+
+ public void run()
+ {
+ if (id % 100 == 0) log.warn("Processing iteration " + id);
+ String k = getRandomString();
+ String v = getRandomString();
+ cache.put(fqns.get(r.nextInt(MAX_OVERALL_NODES)), k, v);
+ }
+ }
+
private String getRandomString()
{
StringBuilder sb = new StringBuilder();