[jboss-cvs] JBossCache/tests/perf/org/jboss/cache ...
Manik Surtani
msurtani at jboss.com
Wed Sep 6 11:31:02 EDT 2006
User: msurtani
Date: 06/09/06 11:31:01
Modified: tests/perf/org/jboss/cache FieldUpdateEmulator.java
LocalMapPerfTest.java LocalPerfTest.java
ReplicatedAsyncMapPerfTest.java
ReplicatedAsyncPerfTest.java
ReplicatedSyncMapPerfTest.java
ReplicatedSyncPerfTest.java Server.java
Log:
Removed TreeCache dependency on ServiceMBeanSupport
Revision Changes Path
1.8 +133 -95 JBossCache/tests/perf/org/jboss/cache/FieldUpdateEmulator.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: FieldUpdateEmulator.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/tests/perf/org/jboss/cache/FieldUpdateEmulator.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -b -r1.7 -r1.8
--- FieldUpdateEmulator.java 16 Aug 2006 10:52:52 -0000 1.7
+++ FieldUpdateEmulator.java 6 Sep 2006 15:31:01 -0000 1.8
@@ -32,7 +32,8 @@
/**
* Use the same configuration as PojoCache but don't do any AOP. Just emulates it.
*/
-public class FieldUpdateEmulator {
+public class FieldUpdateEmulator
+{
static PojoCache cache_;
Properties props_ = new Properties();
static int threads_; // how many threads to send the put.
@@ -54,11 +55,12 @@
static long endTime_ = 0;
static int operationType_ = 1;
- void initCache() throws Exception {
+ void initCache() throws Exception
+ {
cache_ = new PojoCache();
- String file = (String)props_.get("cache_config");
- if(file==null)
+ String file = (String) props_.get("cache_config");
+ if (file == null)
{
throw new RuntimeException("Cache config xml is not specified.");
}
@@ -66,21 +68,25 @@
cache_.getConfiguration().setTransactionManagerLookupClass("org.jboss.cache.DummyTransactionManagerLookup");
}
- void destroyCache() throws Exception {
- cache_.stopService();
+ void destroyCache() throws Exception
+ {
+ cache_.stop();
cache_ = null;
}
- TreeCache getCache() {
+ TreeCache getCache()
+ {
return cache_;
}
- void parseConfig(String fileName) throws Exception {
+ void parseConfig(String fileName) throws Exception
+ {
String line;
StringTokenizer st;
String key, val;
BufferedReader fileReader = new BufferedReader(new FileReader(fileName));
- while ((line = fileReader.readLine()) != null) {
+ while ((line = fileReader.readLine()) != null)
+ {
if (line.startsWith("#"))
continue;
line = line.trim();
@@ -90,44 +96,45 @@
key = st.nextToken().toLowerCase();
val = st.nextToken();
props_.put(key, val);
- System.out.println("Read in config key, value: "+ key + " "+ val);
+ System.out.println("Read in config key, value: " + key + " " + val);
}
fileReader.close();
}
- void startLoadTest() throws InterruptedException, CacheException {
- String str = (String)props_.get("threads");
- if(str == null)
+ void startLoadTest() throws InterruptedException, CacheException
+ {
+ String str = (String) props_.get("threads");
+ if (str == null)
throw new RuntimeException("Can't find threads property");
threads_ = Integer.parseInt(str);
- str = (String)props_.get("loops");
- if(str == null)
+ str = (String) props_.get("loops");
+ if (str == null)
throw new RuntimeException("Can't find loops property");
loops_ = Integer.parseInt(str);
- str = (String)props_.get("sleep_interval_millis");
- if(str == null)
+ str = (String) props_.get("sleep_interval_millis");
+ if (str == null)
throw new RuntimeException("Can't find sleepIntervalInMillis property");
sleepIntervalInMillis_ = Integer.parseInt(str);
- str = (String)props_.get("random_sleep_interval");
- if(str == null)
+ str = (String) props_.get("random_sleep_interval");
+ if (str == null)
throw new RuntimeException("Can't find random_sleep_interval property");
randomSleep_ = new Boolean(str).booleanValue();
- str = (String)props_.get("object_list_size");
- if(str == null)
+ str = (String) props_.get("object_list_size");
+ if (str == null)
throw new RuntimeException("Can't find objectListSize property");
objectListSize_ = Integer.parseInt(str);
- str = (String)props_.get("transaction");
- if(str == null)
+ str = (String) props_.get("transaction");
+ if (str == null)
throw new RuntimeException("Can't find transaction property");
transaction_ = new Boolean(str).booleanValue();
@@ -139,14 +146,14 @@
operationType_ = Integer.parseInt(str); */
- str = (String)props_.get("run_pojocache");
- if(str == null)
+ str = (String) props_.get("run_pojocache");
+ if (str == null)
throw new RuntimeException("Can't find run_PojoCache property");
runPojoCache_ = new Boolean(str).booleanValue();
- str = (String)props_.get("update_pojo_interval");
- if(str == null)
+ str = (String) props_.get("update_pojo_interval");
+ if (str == null)
throw new RuntimeException("Can't find update_pojo_interval property");
updatePojoInterval_ = Integer.parseInt(str);
@@ -154,7 +161,7 @@
countdown_ = new CountDown(threads_);
// Warm up the cache first to avoid any simultaneous write contention.
- if(cache_.getCoordinator().equals(cache_.getLocalAddress()))
+ if (cache_.getCoordinator().equals(cache_.getLocalAddress()))
{
System.out.println("I am the coordinator: " + cache_.getLocalAddress());
cache_.put(ROOT + cache_.getLocalAddress().toString(), "test", "test");
@@ -163,7 +170,7 @@
sleep_(300);
startTime_ = System.currentTimeMillis();
- for(int i=0; i < threads_ ; i++)
+ for (int i = 0; i < threads_; i++)
{
Loader loader = new Loader(cache_, i, cache_.getLocalAddress().toString());
loader.start();
@@ -172,12 +179,13 @@
static int getSleepInterval()
{
- if(sleepIntervalInMillis_ ==0) return sleepIntervalInMillis_;
+ if (sleepIntervalInMillis_ == 0) return sleepIntervalInMillis_;
- if(randomSleep_)
+ if (randomSleep_)
{
return random.nextInt(sleepIntervalInMillis_);
- } else
+ }
+ else
{
return sleepIntervalInMillis_;
}
@@ -187,7 +195,7 @@
{
StringTokenizer tok = new StringTokenizer(addrListStr, ",");
List list = new ArrayList();
- while(tok.hasMoreTokens())
+ while (tok.hasMoreTokens())
{
list.add(tok.nextToken());
}
@@ -197,12 +205,16 @@
static void sleep_(long msec)
{
- try {
+ try
+ {
Thread.sleep(msec);
- } catch (InterruptedException e) {
+ }
+ catch (InterruptedException e)
+ {
e.printStackTrace();
}
}
+
void printUsage()
{
System.out.println("Options: -config to specify config file (like bench.txt)\n" +
@@ -214,24 +226,31 @@
System.out.println("\n************************************");
System.out.println("\nThis is a simple performance test for JBossCache.\n" +
"The load pattern is like those of http session repl, that is,\neach put " +
- "is under a separate sub-tree.\n" +"As a result, there should not be write contention.\n");
+ "is under a separate sub-tree.\n" + "As a result, there should not be write contention.\n");
}
- public static void main(String[] args) throws Exception {
+ public static void main(String[] args) throws Exception
+ {
FieldUpdateEmulator server = new FieldUpdateEmulator();
- if(args.length ==0)
+ if (args.length == 0)
{
server.printUsage();
return;
}
- for (int i = 0; i < args.length; i++) {
- if ("-config".equals(args[i])) {
- System.out.println("Configuration file is: " + args[i+1]);
+ for (int i = 0; i < args.length; i++)
+ {
+ if ("-config".equals(args[i]))
+ {
+ System.out.println("Configuration file is: " + args[i + 1]);
server.parseConfig(args[++i]);
- } else if("-receiver".equals(args[i])) {
+ }
+ else if ("-receiver".equals(args[i]))
+ {
receiver_ = true;
- } else {
+ }
+ else
+ {
System.err.println("Unknown argument:" + args[i]);
server.printUsage();
return;
@@ -240,23 +259,24 @@
server.printInfo();
- String addrListStr = (String)server.props_.get("members");
+ String addrListStr = (String) server.props_.get("members");
List addrList = server.getMembers(addrListStr);
server.initCache();
ViewListener listener = new ViewListener(addrList);
cache_.getNotifier().addCacheListener(listener); // register for view change
- cache_.startService();
+ cache_.start();
System.out.println("Cache started .. ");
System.out.println("Waiting for the other nodes to start up...");
- while (!isReady_) {
+ while (!isReady_)
+ {
sleep_(100);
}
sleep_(2000);
- if(!receiver_)
+ if (!receiver_)
{
server.startLoadTest();
System.out.println("Waiting for the test to finish...");
@@ -264,23 +284,24 @@
countdown_.acquire();
endTime_ = System.currentTimeMillis();
System.out.println("\nThroughtput for this node with:\n" + "threads = " + threads_
- +"\nloops = " + loops_
+ + "\nloops = " + loops_
+ "\nsleep interval = " + sleepIntervalInMillis_ + "\nobject list size = "
- + objectListSize_ + "\ntranasaction? " + transaction_ +"\n"
- + "is: " + (loops_ * threads_ *1000)/(endTime_ - startTime_) + " requests/sec\n");
- } else
+ + objectListSize_ + "\ntranasaction? " + transaction_ + "\n"
+ + "is: " + (loops_ * threads_ * 1000) / (endTime_ - startTime_) + " requests/sec\n");
+ }
+ else
{
System.out.println("Receiver mode only. Won't send request...");
}
- if(ex_ != null)
+ if (ex_ != null)
{
System.err.println("Exception counts: " + exceptionCounts_);
throw new RuntimeException("Exception occurred during the run: " + ex_);
}
System.out.println("Test is finished. hit ctrl-c to kill the process ...");
- while(true)
+ while (true)
{
sleep_(1000);
}
@@ -292,20 +313,22 @@
{
List addrList_; // List of address
- public ViewListener(List addrList) {
+ public ViewListener(List addrList)
+ {
addrList_ = addrList;
}
+
public void viewChange(View new_view) // might be MergeView after merging
{
Vector vector = new_view.getMembers();
- if(vector.size() > addrList_.size())
+ if (vector.size() > addrList_.size())
{
// We have more members than is specified!
throw new RuntimeException("You have more members in the cluster group than specified in the config."
- + " size of members now: " +vector.size());
+ + " size of members now: " + vector.size());
}
// Need to match individually but let's just assum the size matters then.
- if(vector.size() == addrList_.size())
+ if (vector.size() == addrList_.size())
{
// good to go
isReady_ = true;
@@ -329,7 +352,8 @@
// System.out.println("Local addres is: " +localAddress.toString());
}
- public void run() {
+ public void run()
+ {
Object obj = null;
Object obj1 = Loader.constructObject();
Object obj2 = Loader.constructObject();
@@ -337,24 +361,25 @@
boolean transaction = true;
long start_time = System.currentTimeMillis();
- for(int i=0; i < loops_; i++)
+ for (int i = 0; i < loops_; i++)
{
- if(getSleepInterval() !=0)
+ if (getSleepInterval() != 0)
sleep_(getSleepInterval());
Transaction tx = null;
- try {
+ try
+ {
boolean update = true;
- if(runPojoCache_ && updatePojoInterval_ != 1)
+ if (runPojoCache_ && updatePojoInterval_ != 1)
{
- if((i% updatePojoInterval_) != 0 )
+ if ((i % updatePojoInterval_) != 0)
{
transaction = false; // no transaction for field update.
update = false;
}
}
- if(transaction)
+ if (transaction)
{
tm_.begin();
tx = tm_.getTransaction();
@@ -364,62 +389,71 @@
* Need this for PojoCache. Otherwise, it'd be cheating becuase another putObject of thee
* same pojo is fast.
*/
- if(update)
+ if (update)
{
- if( ((i+1)%2) == 0)
+ if (((i + 1) % 2) == 0)
obj = obj1;
else
obj = obj2;
}
doWork(fqn, localAddress, obj, update);
- if(transaction)
+ if (transaction)
{
tx.commit();
}
- } catch (Exception e) {
+ }
+ catch (Exception e)
+ {
exceptionCounts_++;
ex_ = e;
e.printStackTrace();
- if(transaction)
+ if (transaction)
+ {
+ try
{
- try {
tx.rollback();
- } catch (SystemException e1) {
+ }
+ catch (SystemException e1)
+ {
e1.printStackTrace();
ex_ = e1;
}
}
- } finally
+ }
+ finally
{
}
// System.out.println("Processing at loop: " +i);
- if( (i%50) ==0 && threadId == 0)
+ if ((i % 50) == 0 && threadId == 0)
{
- System.out.println("Processing at loop: " +i);
+ System.out.println("Processing at loop: " + i);
}
}
long end_time = System.currentTimeMillis();
long time = end_time - start_time;
- if(threadId == 0)
- System.out.println("Total time spent (ms) on thread id 0: " +time + " for "+ loops_ +" loops");
+ if (threadId == 0)
+ System.out.println("Total time spent (ms) on thread id 0: " + time + " for " + loops_ + " loops");
countdown_.release();
}
- void doWork(String fqn, Object key, Object pojo, boolean update) throws CacheException {
- if(!runPojoCache_)
+ void doWork(String fqn, Object key, Object pojo, boolean update) throws CacheException
+ {
+ if (!runPojoCache_)
{
doPlainCacheWork(fqn, key, pojo);
- } else
+ }
+ else
{
- if(update)
+ if (update)
{
// System.out.println("Running pojo cache update");
Object obj = Loader.constructObject();
doPojoCacheWork(fqn, obj);
- } else
+ }
+ else
{
// System.out.println("Running field update");
doPojoCacheFieldWork(fqn, pojo);
@@ -427,21 +461,23 @@
}
}
- void doPlainCacheWork(String fqn, Object key, Object pojo) throws CacheException {
- if(operationType_ == 1)
+ void doPlainCacheWork(String fqn, Object key, Object pojo) throws CacheException
+ {
+ if (operationType_ == 1)
{
cache_.put(fqn, key, pojo);
Object obj = cache_.get(fqn, key);
- if(!((Student)obj).getName().equals("Joe"))
+ if (!((Student) obj).getName().equals("Joe"))
{
throw new RuntimeException("Value returned not Joe");
}
- } else
+ }
+ else
{
cache_.remove(fqn, key);
cache_.put(fqn, key, pojo);
Object obj = cache_.get(fqn, key);
- if(!((Student)obj).getName().equals("Joe"))
+ if (!((Student) obj).getName().equals("Joe"))
{
throw new RuntimeException("Value returned not Joe");
}
@@ -449,12 +485,14 @@
}
// Fake it
- void doPojoCacheWork(String fqn, Object pojo) throws CacheException {
+ void doPojoCacheWork(String fqn, Object pojo) throws CacheException
+ {
cache_.put(fqn, "test", pojo);
cache_.get(fqn, "test");
}
- void doPojoCacheFieldWork(String fqn, Object pojo) throws CacheException {
+ void doPojoCacheFieldWork(String fqn, Object pojo) throws CacheException
+ {
Object obj = cache_.get(fqn, "test");
cache_.put(fqn, "test1", "Pingtung");
}
@@ -471,14 +509,14 @@
joe.setAddress(add);
String str;
- for(int i=0; i < objectListSize_; i++)
+ for (int i = 0; i < objectListSize_; i++)
{
Course course = new Course();
- str = RandomString.randomstring(10,20);
+ str = RandomString.randomstring(10, 20);
course.setInstructor(str);
- str = RandomString.randomstring(10,20);
+ str = RandomString.randomstring(10, 20);
course.setTitle(str);
- str = RandomString.randomstring(10,20);
+ str = RandomString.randomstring(10, 20);
course.setRoom(str);
joe.addCourse(course);
}
1.5 +54 -32 JBossCache/tests/perf/org/jboss/cache/LocalMapPerfTest.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: LocalMapPerfTest.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/tests/perf/org/jboss/cache/LocalMapPerfTest.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -b -r1.4 -r1.5
--- LocalMapPerfTest.java 20 Jul 2006 11:48:27 -0000 1.4
+++ LocalMapPerfTest.java 6 Sep 2006 15:31:01 -0000 1.5
@@ -12,12 +12,11 @@
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
+import org.jboss.cache.config.Configuration;
+import org.jboss.cache.factories.XmlConfigurationParser;
import org.jboss.cache.lock.IsolationLevel;
import org.jboss.cache.lock.LockStrategyFactory;
import org.jboss.cache.transaction.DummyTransactionManager;
-import org.jboss.cache.config.Configuration;
-import org.jboss.cache.factories.XmlConfigurationParser;
-import org.apache.log4j.PropertyConfigurator;
import javax.naming.Context;
import javax.naming.InitialContext;
@@ -32,8 +31,8 @@
/**
* Local mode performance test for TreeCache.
*
- * @version $Revision: 1.4 $
* @author <a href="mailto:bwang at jboss.org">Ben Wang</a> May 20 2003
+ * @version $Revision: 1.5 $
*/
public class LocalMapPerfTest extends TestCase
{
@@ -84,16 +83,20 @@
int depth = depth_;
int children = children_;
int total = 0;
- while (depth > 0) {
- for (int i = 0; i < total; i++) {
- for (int j = 0; j < children; j++) {
+ while (depth > 0)
+ {
+ for (int i = 0; i < total; i++)
+ {
+ for (int j = 0; j < children; j++)
+ {
total++;
}
}
depth--;
}
- for (int i = 0; i < total; i++) {
+ for (int i = 0; i < total; i++)
+ {
String key = Integer.toString(i);
String value = "This is a test for performance of get and set of regular treecache and aop";
map_.put(key, value);
@@ -107,7 +110,8 @@
DummyTransactionManager.destroy();
destroyCaches();
- if (oldFactory_ != null) {
+ if (oldFactory_ != null)
+ {
System.setProperty(Context.INITIAL_CONTEXT_FACTORY, oldFactory_);
oldFactory_ = null;
}
@@ -121,12 +125,12 @@
cache_ = new TreeCache();
cache_.setConfiguration(new XmlConfigurationParser().parseFile("META-INF/local-service.xml"));
cache_.getConfiguration().setTransactionManagerLookupClass("org.jboss.cache.DummyTransactionManagerLookup");
- cache_.startService();
+ cache_.start();
}
void destroyCaches() throws Exception
{
- cache_.stopService();
+ cache_.stop();
cache_ = null;
}
@@ -184,19 +188,24 @@
private int _put(boolean hasTx) throws Exception
{
UserTransaction tx = null;
- if (hasTx) {
+ if (hasTx)
+ {
tx = (UserTransaction) new InitialContext(p_).lookup("UserTransaction");
}
String value = "This is a modified value for the unit testing";
- for (int i = 0; i < nodeList_.size(); i++) {
+ for (int i = 0; i < nodeList_.size(); i++)
+ {
String key = Integer.toString(i);
map_.put(key, value);
- if (hasTx) {
+ if (hasTx)
+ {
tx.begin();
cache_.put((String) nodeList_.get(i), key, map_);
tx.commit();
- } else {
+ }
+ else
+ {
cache_.put((String) nodeList_.get(i), key, map_);
}
}
@@ -207,19 +216,24 @@
private int _get(boolean hasTx) throws Exception
{
UserTransaction tx = null;
- if (hasTx) {
+ if (hasTx)
+ {
tx = (UserTransaction) new InitialContext(p_).lookup("UserTransaction");
}
- for (int i = 0; i < nodeList_.size(); i++) {
+ for (int i = 0; i < nodeList_.size(); i++)
+ {
String key = Integer.toString(i);
- if (hasTx) {
+ if (hasTx)
+ {
tx.begin();
Map map = (Map) cache_.get((String) nodeList_.get(i), key);
String str = (String) map.get(key);
// log("_get(): key: " + key + " value: " +str);
tx.commit();
- } else {
+ }
+ else
+ {
Map map = (Map) cache_.get((String) nodeList_.get(i), key);
String str = (String) map.get(key);
// log("_get(): key: " + key + " value: " +str);
@@ -232,18 +246,23 @@
private int _remove(boolean hasTx) throws Exception
{
UserTransaction tx = null;
- if (hasTx) {
+ if (hasTx)
+ {
tx = (UserTransaction) new InitialContext(p_).lookup("UserTransaction");
}
- for (int i = 0; i < nodeList_.size(); i++) {
+ for (int i = 0; i < nodeList_.size(); i++)
+ {
String key = Integer.toString(i);
- if (hasTx) {
+ if (hasTx)
+ {
tx.begin();
Map map = (Map) cache_.get((String) nodeList_.get(i), key);
map.remove(key);
tx.commit();
- } else {
+ }
+ else
+ {
Map map = (Map) cache_.get((String) nodeList_.get(i), key);
map.remove(key);
}
@@ -268,11 +287,14 @@
newList.add("/");
strList.add("/");
- while (depth > 0) {
+ while (depth > 0)
+ {
// Trying to produce node name at this depth.
newList = new ArrayList();
- for (int i = 0; i < oldList.size(); i++) {
- for (int j = 0; j < children; j++) {
+ for (int i = 0; i < oldList.size(); i++)
+ {
+ for (int j = 0; j < children; j++)
+ {
String tmp = (String) oldList.get(i);
tmp += Integer.toString(j);
if (depth != 1) tmp += "/";
1.5 +50 -31 JBossCache/tests/perf/org/jboss/cache/LocalPerfTest.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: LocalPerfTest.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/tests/perf/org/jboss/cache/LocalPerfTest.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -b -r1.4 -r1.5
--- LocalPerfTest.java 20 Jul 2006 11:48:27 -0000 1.4
+++ LocalPerfTest.java 6 Sep 2006 15:31:01 -0000 1.5
@@ -29,8 +29,8 @@
/**
* Local mode performance test for TreeCache.
*
- * @version $Revision: 1.4 $
* @author <a href="mailto:bwang at jboss.org">Ben Wang</a> May 20 2003
+ * @version $Revision: 1.5 $
*/
public class LocalPerfTest extends TestCase
{
@@ -78,7 +78,8 @@
DummyTransactionManager.destroy();
destroyCaches();
- if (oldFactory_ != null) {
+ if (oldFactory_ != null)
+ {
System.setProperty(Context.INITIAL_CONTEXT_FACTORY, oldFactory_);
oldFactory_ = null;
}
@@ -91,12 +92,12 @@
cache_ = new TreeCache();
cache_.setConfiguration(new XmlConfigurationParser().parseFile("META-INF/local-service.xml"));
cache_.getConfiguration().setTransactionManagerLookupClass("org.jboss.cache.DummyTransactionManagerLookup");
- cache_.startService();
+ cache_.start();
}
void destroyCaches() throws Exception
{
- cache_.stopService();
+ cache_.stop();
cache_ = null;
}
@@ -205,18 +206,23 @@
private int _add(boolean hasTx) throws Exception
{
UserTransaction tx = null;
- if (hasTx) {
+ if (hasTx)
+ {
tx = (UserTransaction) new InitialContext(p_).lookup("UserTransaction");
}
- for (int i = 0; i < nodeList_.size(); i++) {
+ for (int i = 0; i < nodeList_.size(); i++)
+ {
String key = Integer.toString(i);
String value = Integer.toString(i);
- if (hasTx) {
+ if (hasTx)
+ {
tx.begin();
cache_.put((String) nodeList_.get(i), key, value);
tx.commit();
- } else {
+ }
+ else
+ {
cache_.put((String) nodeList_.get(i), key, value);
}
}
@@ -227,17 +233,22 @@
private int _get(boolean hasTx) throws Exception
{
UserTransaction tx = null;
- if (hasTx) {
+ if (hasTx)
+ {
tx = (UserTransaction) new InitialContext(p_).lookup("UserTransaction");
}
- for (int i = 0; i < nodeList_.size(); i++) {
+ for (int i = 0; i < nodeList_.size(); i++)
+ {
String key = Integer.toString(i);
- if (hasTx) {
+ if (hasTx)
+ {
tx.begin();
cache_.get((String) nodeList_.get(i), key);
tx.commit();
- } else {
+ }
+ else
+ {
cache_.get((String) nodeList_.get(i), key);
}
}
@@ -248,17 +259,22 @@
private int _remove(boolean hasTx) throws Exception
{
UserTransaction tx = null;
- if (hasTx) {
+ if (hasTx)
+ {
tx = (UserTransaction) new InitialContext(p_).lookup("UserTransaction");
}
- for (int i = 0; i < nodeList_.size(); i++) {
+ for (int i = 0; i < nodeList_.size(); i++)
+ {
String key = Integer.toString(i);
- if (hasTx) {
+ if (hasTx)
+ {
tx.begin();
cache_.remove((String) nodeList_.get(i), key);
tx.commit();
- } else {
+ }
+ else
+ {
cache_.remove((String) nodeList_.get(i), key);
}
}
@@ -281,11 +297,14 @@
newList.add("/");
strList.add("/");
- while (depth > 0) {
+ while (depth > 0)
+ {
// Trying to produce node name at this depth.
newList = new ArrayList();
- for (int i = 0; i < oldList.size(); i++) {
- for (int j = 0; j < children; j++) {
+ for (int i = 0; i < oldList.size(); i++)
+ {
+ for (int j = 0; j < children; j++)
+ {
String tmp = (String) oldList.get(i);
tmp += Integer.toString(j);
if (depth != 1) tmp += "/";
1.6 +59 -33 JBossCache/tests/perf/org/jboss/cache/ReplicatedAsyncMapPerfTest.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: ReplicatedAsyncMapPerfTest.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/tests/perf/org/jboss/cache/ReplicatedAsyncMapPerfTest.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -b -r1.5 -r1.6
--- ReplicatedAsyncMapPerfTest.java 20 Jul 2006 11:48:27 -0000 1.5
+++ ReplicatedAsyncMapPerfTest.java 6 Sep 2006 15:31:01 -0000 1.6
@@ -29,8 +29,8 @@
/**
* Local mode performance test for TreeCache.
*
- * @version $Revision: 1.5 $
* @author <a href="mailto:bwang at jboss.org">Ben Wang</a> May 20 2003
+ * @version $Revision: 1.6 $
*/
public class ReplicatedAsyncMapPerfTest extends TestCase
{
@@ -86,7 +86,8 @@
private void generateString()
{
- while (originalStrBuf_.length() < mapValueSize_) {
+ while (originalStrBuf_.length() < mapValueSize_)
+ {
originalStrBuf_.append(seed1_);
newStrBuf_.append(seed2_);
}
@@ -97,16 +98,20 @@
int depth = depth_;
int children = children_;
int total = 0;
- while (depth > 0) {
- for (int i = 0; i < total; i++) {
- for (int j = 0; j < children; j++) {
+ while (depth > 0)
+ {
+ for (int i = 0; i < total; i++)
+ {
+ for (int j = 0; j < children; j++)
+ {
total++;
}
}
depth--;
}
- for (int i = 0; i < total; i++) {
+ for (int i = 0; i < total; i++)
+ {
String key = Integer.toString(i);
String value = originalStrBuf_.toString();
map_.put(key, value);
@@ -120,7 +125,8 @@
DummyTransactionManager.destroy();
destroyCaches();
- if (oldFactory_ != null) {
+ if (oldFactory_ != null)
+ {
System.setProperty(Context.INITIAL_CONTEXT_FACTORY, oldFactory_);
oldFactory_ = null;
}
@@ -134,20 +140,23 @@
cache_ = new TreeCache();
cache_.setConfiguration(new XmlConfigurationParser().parseFile("META-INF/replAsync-service.xml")); // read in generic replAsync xml
cache_.getConfiguration().setTransactionManagerLookupClass("org.jboss.cache.DummyTransactionManagerLookup");
- cache_.startService();
+ cache_.start();
}
void destroyCaches() throws Exception
{
- cache_.stopService();
+ cache_.stop();
cache_ = null;
}
public void testAll() throws Exception
{
- try {
+ try
+ {
Thread.sleep(5000);
- } catch (Exception ex) {
+ }
+ catch (Exception ex)
+ {
}
log("=== Transaction ===");
// Formating
@@ -187,23 +196,27 @@
}
-
private int _put(boolean hasTx) throws Exception
{
UserTransaction tx = null;
- if (hasTx) {
+ if (hasTx)
+ {
tx = (UserTransaction) new InitialContext(p_).lookup("UserTransaction");
}
String value = newStrBuf_.toString();
- for (int i = 0; i < nodeList_.size(); i++) {
+ for (int i = 0; i < nodeList_.size(); i++)
+ {
String key = Integer.toString(i);
map_.put(key, value);
- if (hasTx) {
+ if (hasTx)
+ {
tx.begin();
cache_.put((String) nodeList_.get(i), key, map_);
tx.commit();
- } else {
+ }
+ else
+ {
cache_.put((String) nodeList_.get(i), key, map_);
}
}
@@ -214,18 +227,23 @@
private int _get(boolean hasTx) throws Exception
{
UserTransaction tx = null;
- if (hasTx) {
+ if (hasTx)
+ {
tx = (UserTransaction) new InitialContext(p_).lookup("UserTransaction");
}
- for (int i = 0; i < nodeList_.size(); i++) {
+ for (int i = 0; i < nodeList_.size(); i++)
+ {
String key = Integer.toString(i);
- if (hasTx) {
+ if (hasTx)
+ {
tx.begin();
Map map = (Map) cache_.get((String) nodeList_.get(i), key);
map.get(key);
tx.commit();
- } else {
+ }
+ else
+ {
Map map = (Map) cache_.get((String) nodeList_.get(i), key);
map.get(key);
}
@@ -237,18 +255,23 @@
private int _remove(boolean hasTx) throws Exception
{
UserTransaction tx = null;
- if (hasTx) {
+ if (hasTx)
+ {
tx = (UserTransaction) new InitialContext(p_).lookup("UserTransaction");
}
- for (int i = 0; i < nodeList_.size(); i++) {
+ for (int i = 0; i < nodeList_.size(); i++)
+ {
String key = Integer.toString(i);
- if (hasTx) {
+ if (hasTx)
+ {
tx.begin();
Map map = (Map) cache_.get((String) nodeList_.get(i), key);
map.remove(key);
tx.commit();
- } else {
+ }
+ else
+ {
Map map = (Map) cache_.get((String) nodeList_.get(i), key);
map.remove(key);
}
@@ -273,11 +296,14 @@
newList.add("/");
strList.add("/");
- while (depth > 0) {
+ while (depth > 0)
+ {
// Trying to produce node name at this depth.
newList = new ArrayList();
- for (int i = 0; i < oldList.size(); i++) {
- for (int j = 0; j < children; j++) {
+ for (int i = 0; i < oldList.size(); i++)
+ {
+ for (int j = 0; j < children; j++)
+ {
String tmp = (String) oldList.get(i);
tmp += Integer.toString(j);
if (depth != 1) tmp += "/";
1.4 +71 -51 JBossCache/tests/perf/org/jboss/cache/ReplicatedAsyncPerfTest.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: ReplicatedAsyncPerfTest.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/tests/perf/org/jboss/cache/ReplicatedAsyncPerfTest.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- ReplicatedAsyncPerfTest.java 20 Jul 2006 08:05:19 -0000 1.3
+++ ReplicatedAsyncPerfTest.java 6 Sep 2006 15:31:01 -0000 1.4
@@ -28,8 +28,8 @@
/**
* Replicated asynchronous mode performance test for transactional TreeCache
*
- * @version $Revision: 1.3 $
* @author <a href="mailto:bwang at jboss.org">Ben Wang</a> May 20 2003
+ * @version $Revision: 1.4 $
*/
public class ReplicatedAsyncPerfTest extends TestCase
{
@@ -81,7 +81,8 @@
DummyTransactionManager.destroy();
- if (oldFactory_ != null) {
+ if (oldFactory_ != null)
+ {
System.setProperty(Context.INITIAL_CONTEXT_FACTORY, oldFactory_);
oldFactory_ = null;
}
@@ -100,9 +101,10 @@
private void destroyCache(TreeCache cache) throws Exception
{
- if(cache != null) {
+ if (cache != null)
+ {
cache.remove("/");
- cache.stopService();
+ cache.stop();
}
}
@@ -122,7 +124,7 @@
log("=== 1 cache with transaction (no concurrent access) ===");
cache1_ = createCache(level);
cache1_.getConfiguration().setTransactionManagerLookupClass("org.jboss.cache.JBossTransactionManagerLookup");
- cache1_.startService();
+ cache1_.start();
// Formating
DecimalFormat form = new DecimalFormat("#.00");
@@ -179,8 +181,8 @@
cache2_ = createCache(level);
cache1_.getConfiguration().setTransactionManagerLookupClass("org.jboss.cache.JBossTransactionManagerLookup");
cache2_.getConfiguration().setTransactionManagerLookupClass("org.jboss.cache.JBossTransactionManagerLookup");
- cache1_.startService();
- cache2_.startService();
+ cache1_.start();
+ cache2_.start();
// Formating
DecimalFormat form = new DecimalFormat("#.00");
@@ -247,8 +249,8 @@
cache1_.getConfiguration().setTransactionManagerLookupClass("org.jboss.cache.JBossTransactionManagerLookup");
cache2_.getConfiguration().setTransactionManagerLookupClass("org.jboss.cache.JBossTransactionManagerLookup");
- cache1_.startService();
- cache2_.startService();
+ cache1_.start();
+ cache2_.start();
// Formating
DecimalFormat form = new DecimalFormat("#.00");
@@ -308,9 +310,9 @@
cache1_.getConfiguration().setTransactionManagerLookupClass("org.jboss.cache.JBossTransactionManagerLookup");
cache2_.getConfiguration().setTransactionManagerLookupClass("org.jboss.cache.JBossTransactionManagerLookup");
cache3_.getConfiguration().setTransactionManagerLookupClass("org.jboss.cache.JBossTransactionManagerLookup");
- cache1_.startService();
- cache2_.startService();
- cache3_.startService();
+ cache1_.start();
+ cache2_.start();
+ cache3_.start();
// Formating
DecimalFormat form = new DecimalFormat("#.00");
@@ -355,18 +357,23 @@
private int _add(TreeCache cache, boolean hasTx) throws Exception
{
UserTransaction tx = null;
- if (hasTx) {
+ if (hasTx)
+ {
tx = (UserTransaction) new InitialContext(p_).lookup("UserTransaction");
}
- for (int i = 0; i < nodeList_.size(); i++) {
+ for (int i = 0; i < nodeList_.size(); i++)
+ {
String key = Integer.toString(i);
String value = Integer.toString(i);
- if (hasTx) {
+ if (hasTx)
+ {
tx.begin();
cache.put((String) nodeList_.get(i), key, value);
tx.commit();
- } else {
+ }
+ else
+ {
cache.put((String) nodeList_.get(i), key, value);
}
}
@@ -377,17 +384,22 @@
private int _get(TreeCache cache, boolean hasTx) throws Exception
{
UserTransaction tx = null;
- if (hasTx) {
+ if (hasTx)
+ {
tx = (UserTransaction) new InitialContext(p_).lookup("UserTransaction");
}
- for (int i = 0; i < nodeList_.size(); i++) {
+ for (int i = 0; i < nodeList_.size(); i++)
+ {
String key = Integer.toString(i);
- if (hasTx) {
+ if (hasTx)
+ {
tx.begin();
cache.get((String) nodeList_.get(i), key);
tx.commit();
- } else {
+ }
+ else
+ {
cache.get((String) nodeList_.get(i), key);
}
}
@@ -398,17 +410,22 @@
private int _remove(TreeCache cache, boolean hasTx) throws Exception
{
UserTransaction tx = null;
- if (hasTx) {
+ if (hasTx)
+ {
tx = (UserTransaction) new InitialContext(p_).lookup("UserTransaction");
}
- for (int i = nodeList_.size()-1; i >= 0; i--) {
+ for (int i = nodeList_.size() - 1; i >= 0; i--)
+ {
String key = Integer.toString(i);
- if (hasTx) {
+ if (hasTx)
+ {
tx.begin();
cache.remove((String) nodeList_.get(i), key);
tx.commit();
- } else {
+ }
+ else
+ {
cache.remove((String) nodeList_.get(i), key);
}
}
@@ -430,11 +447,14 @@
newList.add("/");
strList.add("/");
- while (depth > 0) {
+ while (depth > 0)
+ {
// Trying to produce node name at this depth.
newList = new ArrayList();
- for (int i = 0; i < oldList.size(); i++) {
- for (int j = 0; j < children; j++) {
+ for (int i = 0; i < oldList.size(); i++)
+ {
+ for (int j = 0; j < children; j++)
+ {
String tmp = (String) oldList.get(i);
tmp += Integer.toString(j);
if (depth != 1) tmp += "/";
1.5 +59 -32 JBossCache/tests/perf/org/jboss/cache/ReplicatedSyncMapPerfTest.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: ReplicatedSyncMapPerfTest.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/tests/perf/org/jboss/cache/ReplicatedSyncMapPerfTest.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -b -r1.4 -r1.5
--- ReplicatedSyncMapPerfTest.java 20 Jul 2006 11:48:27 -0000 1.4
+++ ReplicatedSyncMapPerfTest.java 6 Sep 2006 15:31:01 -0000 1.5
@@ -31,8 +31,8 @@
/**
* Local mode performance test for TreeCache.
*
- * @version $Revision: 1.4 $
* @author <a href="mailto:bwang at jboss.org">Ben Wang</a> May 20 2003
+ * @version $Revision: 1.5 $
*/
public class ReplicatedSyncMapPerfTest extends TestCase
{
@@ -90,7 +90,8 @@
{
int length = seed1_.length();
boolean isTrue = false;
- while (originalStrBuf_.length() < mapValueSize_) {
+ while (originalStrBuf_.length() < mapValueSize_)
+ {
originalStrBuf_.append(seed1_);
newStrBuf_.append(seed2_);
}
@@ -101,16 +102,20 @@
int depth = depth_;
int children = children_;
int total = 0;
- while (depth > 0) {
- for (int i = 0; i < total; i++) {
- for (int j = 0; j < children; j++) {
+ while (depth > 0)
+ {
+ for (int i = 0; i < total; i++)
+ {
+ for (int j = 0; j < children; j++)
+ {
total++;
}
}
depth--;
}
- for (int i = 0; i < total; i++) {
+ for (int i = 0; i < total; i++)
+ {
String key = Integer.toString(i);
String value = originalStrBuf_.toString();
map_.put(key, value);
@@ -124,7 +129,8 @@
DummyTransactionManager.destroy();
destroyCaches();
- if (oldFactory_ != null) {
+ if (oldFactory_ != null)
+ {
System.setProperty(Context.INITIAL_CONTEXT_FACTORY, oldFactory_);
oldFactory_ = null;
}
@@ -138,21 +144,24 @@
cache_ = new TreeCache();
cache_.setConfiguration(new XmlConfigurationParser().parseFile("META-INF/replSync-service.xml"));
cache_.getConfiguration().setTransactionManagerLookupClass("org.jboss.cache.DummyTransactionManagerLookup");
- cache_.startService();
+ cache_.start();
// org.jgroups.log.Trace.init();
}
void destroyCaches() throws Exception
{
- cache_.stopService();
+ cache_.stop();
cache_ = null;
}
public void testAll() throws Exception
{
- try {
+ try
+ {
Thread.sleep(5000);
- } catch (Exception ex) {
+ }
+ catch (Exception ex)
+ {
}
log("=== Transaction ===");
// Formating
@@ -206,19 +215,24 @@
private int _put(boolean hasTx) throws Exception
{
UserTransaction tx = null;
- if (hasTx) {
+ if (hasTx)
+ {
tx = (UserTransaction) new InitialContext(p_).lookup("UserTransaction");
}
String value = newStrBuf_.toString();
- for (int i = 0; i < nodeList_.size(); i++) {
+ for (int i = 0; i < nodeList_.size(); i++)
+ {
String key = Integer.toString(i);
map_.put(key, value);
- if (hasTx) {
+ if (hasTx)
+ {
tx.begin();
cache_.put((String) nodeList_.get(i), key, map_);
tx.commit();
- } else {
+ }
+ else
+ {
cache_.put((String) nodeList_.get(i), key, map_);
}
}
@@ -229,19 +243,24 @@
private int _get(boolean hasTx) throws Exception
{
UserTransaction tx = null;
- if (hasTx) {
+ if (hasTx)
+ {
tx = (UserTransaction) new InitialContext(p_).lookup("UserTransaction");
}
- for (int i = 0; i < nodeList_.size(); i++) {
+ for (int i = 0; i < nodeList_.size(); i++)
+ {
String key = Integer.toString(i);
- if (hasTx) {
+ if (hasTx)
+ {
tx.begin();
Map map = (Map) cache_.get((String) nodeList_.get(i), key);
String str = (String) map.get(key);
// log("_get(): key: " + key + " value: " +str);
tx.commit();
- } else {
+ }
+ else
+ {
Map map = (Map) cache_.get((String) nodeList_.get(i), key);
String str = (String) map.get(key);
// log("_get(): key: " + key + " value: " +str);
@@ -254,20 +273,25 @@
private int _remove(boolean hasTx) throws Exception
{
UserTransaction tx = null;
- if (hasTx) {
+ if (hasTx)
+ {
tx = (UserTransaction) new InitialContext(p_).lookup("UserTransaction");
}
- for (int i = 0; i < nodeList_.size(); i++) {
+ for (int i = 0; i < nodeList_.size(); i++)
+ {
String key = Integer.toString(i);
- if (hasTx) {
+ if (hasTx)
+ {
tx.begin();
Map map = (Map) cache_.get((String) nodeList_.get(i), key);
map.remove(key);
// Need to put this back in for the replication to take place.
cache_.put((String) nodeList_.get(i), key, map);
tx.commit();
- } else {
+ }
+ else
+ {
Map map = (Map) cache_.get((String) nodeList_.get(i), key);
map.remove(key);
// Need to put this back in for the replication to take place.
@@ -294,11 +318,14 @@
newList.add("/");
strList.add("/");
- while (depth > 0) {
+ while (depth > 0)
+ {
// Trying to produce node name at this depth.
newList = new ArrayList();
- for (int i = 0; i < oldList.size(); i++) {
- for (int j = 0; j < children; j++) {
+ for (int i = 0; i < oldList.size(); i++)
+ {
+ for (int j = 0; j < children; j++)
+ {
String tmp = (String) oldList.get(i);
tmp += Integer.toString(j);
if (depth != 1) tmp += "/";
1.4 +282 -231 JBossCache/tests/perf/org/jboss/cache/ReplicatedSyncPerfTest.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: ReplicatedSyncPerfTest.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/tests/perf/org/jboss/cache/ReplicatedSyncPerfTest.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- ReplicatedSyncPerfTest.java 20 Jul 2006 08:53:08 -0000 1.3
+++ ReplicatedSyncPerfTest.java 6 Sep 2006 15:31:01 -0000 1.4
@@ -12,10 +12,10 @@
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
+import org.jboss.cache.config.Configuration;
+import org.jboss.cache.factories.XmlConfigurationParser;
import org.jboss.cache.lock.IsolationLevel;
import org.jboss.cache.transaction.DummyTransactionManager;
-import org.jboss.cache.factories.XmlConfigurationParser;
-import org.jboss.cache.config.Configuration;
import org.jgroups.util.Util;
import javax.transaction.Transaction;
@@ -27,40 +27,45 @@
* Replicated synchronous mode performance test for transactional TreeCache.
*
* @author Bela Ban
- * @version $Revision: 1.3 $
* @author <a href="mailto:bwang at jboss.org">Ben Wang</a> May 20 2003
+ * @version $Revision: 1.4 $
*/
-public class ReplicatedSyncPerfTest extends TestCase {
+public class ReplicatedSyncPerfTest extends TestCase
+{
TreeCache cache1_, cache2_, cache3_;
- final String groupName_="TreeCacheTestGroup";
+ final String groupName_ = "TreeCacheTestGroup";
Transaction tx;
ArrayList nodeList_;
// (4, 4) combination will generate 340 nodes.
- static final int depth_=3;
- static final int children_=4;
+ static final int depth_ = 3;
+ static final int children_ = 4;
- public ReplicatedSyncPerfTest(String name) {
+ public ReplicatedSyncPerfTest(String name)
+ {
super(name);
}
- public void setUp() throws Exception {
+ public void setUp() throws Exception
+ {
super.setUp();
- nodeList_=nodeGen(depth_, children_);
+ nodeList_ = nodeGen(depth_, children_);
}
- public void tearDown() throws Exception {
+ public void tearDown() throws Exception
+ {
super.tearDown();
destroyCache(cache1_);
destroyCache(cache2_);
destroyCache(cache3_);
- if(tx != null)
+ if (tx != null)
tx.rollback();
}
- TreeCache createCache(IsolationLevel level) throws Exception {
- TreeCache cache=new TreeCache();
+ TreeCache createCache(IsolationLevel level) throws Exception
+ {
+ TreeCache cache = new TreeCache();
cache.setConfiguration(new XmlConfigurationParser().parseFile("META-INF/replSync-service.xml"));
cache.getConfiguration().setIsolationLevel(level);
cache.getConfiguration().setTransactionManagerLookupClass("org.jboss.cache.DummyTransactionManagerLookup");
@@ -70,15 +75,18 @@
return cache;
}
- void destroyCache(TreeCache cache) throws Exception {
- if(cache != null) {
+ void destroyCache(TreeCache cache) throws Exception
+ {
+ if (cache != null)
+ {
// cache.remove("/");
- cache.stopService();
+ cache.stop();
}
}
- private Transaction startTransaction() throws Exception {
- DummyTransactionManager mgr=DummyTransactionManager.getInstance();
+ private Transaction startTransaction() throws Exception
+ {
+ DummyTransactionManager mgr = DummyTransactionManager.getInstance();
mgr.begin();
return mgr.getTransaction();
}
@@ -87,274 +95,287 @@
/**
* Executes a lot of put() operations against the cache
*/
- public void testPuts() throws Exception {
+ public void testPuts() throws Exception
+ {
log("=== 1 cache with transaction (no concurrent access) many puts ===");
- cache1_=createCache(IsolationLevel.REPEATABLE_READ);
+ cache1_ = createCache(IsolationLevel.REPEATABLE_READ);
cache1_.getConfiguration().setCacheMode(Configuration.CacheMode.REPL_SYNC);
- cache1_.startService();
+ cache1_.start();
- int nOps=10000, realOps=0, failedOps=0;
- long time1=System.currentTimeMillis();
+ int nOps = 10000, realOps = 0, failedOps = 0;
+ long time1 = System.currentTimeMillis();
- try {
- for(int i=0; i < nOps; i++) {
- if(i % 1000 == 0 && i > 0)
+ try
+ {
+ for (int i = 0; i < nOps; i++)
+ {
+ if (i % 1000 == 0 && i > 0)
System.out.println(i);
- tx=startTransaction();
+ tx = startTransaction();
cache1_.put("/hello/world", "name", "Bela Ban");
tx.commit();
realOps++;
}
}
- catch(Throwable t) {
+ catch (Throwable t)
+ {
failedOps++;
t.printStackTrace();
System.out.println("tree is " + cache1_.printLockInfo());
- if(tx != null)
+ if (tx != null)
tx.rollback();
}
- long time2=System.currentTimeMillis();
+ long time2 = System.currentTimeMillis();
assertEquals("failedOps=" + failedOps, nOps, realOps);
- double d=(double)(time2 - time1) / realOps;
+ double d = (double) (time2 - time1) / realOps;
log("Time elapsed for _add is " + (time2 - time1) + " with " + realOps
+ " operations. Average per ops is: " + d + " msec.");
}
-
-
- public void testRandomPuts() throws Exception {
- cache1_=createCache(IsolationLevel.REPEATABLE_READ);
+ public void testRandomPuts() throws Exception
+ {
+ cache1_ = createCache(IsolationLevel.REPEATABLE_READ);
cache1_.getConfiguration().setCacheMode(Configuration.CacheMode.REPL_SYNC);
- cache1_.startService();
+ cache1_.start();
- int nOps=5000, realOps=0, failedOps=0;
- long time1=System.currentTimeMillis();
+ int nOps = 5000, realOps = 0, failedOps = 0;
+ long time1 = System.currentTimeMillis();
String fqn;
long key;
log("=== 1 cache with transaction (no concurrent access) " + nOps + " puts ===");
- try {
- for(int i=0; i < nOps; i++) {
- if(i % 1000 == 0 && i > 0)
+ try
+ {
+ for (int i = 0; i < nOps; i++)
+ {
+ if (i % 1000 == 0 && i > 0)
System.out.println(i);
- tx=startTransaction();
- key=Util.random(nOps);
- fqn="/random/" + key;
+ tx = startTransaction();
+ key = Util.random(nOps);
+ fqn = "/random/" + key;
cache1_.put(fqn, "name", "Bela Ban");
tx.commit();
assertEquals(0, cache1_.getNumberOfLocksHeld());
realOps++;
}
}
- catch(Throwable t) {
+ catch (Throwable t)
+ {
failedOps++;
t.printStackTrace();
System.out.println("cache1_ locks: " + cache1_.printLockInfo());
- if(tx != null)
+ if (tx != null)
tx.rollback();
}
- long time2=System.currentTimeMillis();
+ long time2 = System.currentTimeMillis();
assertEquals("failedOps=" + failedOps, nOps, realOps);
- double d=(double)(time2 - time1) / realOps;
+ double d = (double) (time2 - time1) / realOps;
log("Time elapsed for _add is " + (time2 - time1) + " with " + realOps
+ " operations. Average per ops is: " + d + " msec.");
}
- public void testOneCacheTx() throws Exception {
+ public void testOneCacheTx() throws Exception
+ {
log("=== 1 cache with transaction (no concurrent access) ===");
- cache1_=createCache(IsolationLevel.REPEATABLE_READ);
- cache1_.startService();
+ cache1_ = createCache(IsolationLevel.REPEATABLE_READ);
+ cache1_.start();
// Formating
- DecimalFormat form=new DecimalFormat("#.00");
- FieldPosition fieldPos=new FieldPosition(0);
- StringBuffer dumbStr=new StringBuffer();
- boolean hasTx=true;
- boolean oneTxOnly=false;
+ DecimalFormat form = new DecimalFormat("#.00");
+ FieldPosition fieldPos = new FieldPosition(0);
+ StringBuffer dumbStr = new StringBuffer();
+ boolean hasTx = true;
+ boolean oneTxOnly = false;
System.out.println("sync comm phase: " + cache1_.getConfiguration().isSyncCommitPhase() + ", sync rollback phase: " +
cache1_.getConfiguration().isSyncRollbackPhase());
// Step 1. Add entries to the cache
System.out.println("-- before add: number of locks held is " + cache1_.getNumberOfLocksHeld());
- long time1=System.currentTimeMillis();
- int nOps=add(cache1_, hasTx, oneTxOnly);
- long time2=System.currentTimeMillis();
+ long time1 = System.currentTimeMillis();
+ int nOps = add(cache1_, hasTx, oneTxOnly);
+ long time2 = System.currentTimeMillis();
System.out.println("-- after add: number of locks held is " + cache1_.getNumberOfLocksHeld());
- double d=(double)(time2 - time1) / nOps;
+ double d = (double) (time2 - time1) / nOps;
log("Time elapsed for _add is " + (time2 - time1) + " with " + nOps
+ " operations. Average per ops is: " + form.format(d, dumbStr, fieldPos) +
" msec.");
- dumbStr=new StringBuffer();
+ dumbStr = new StringBuffer();
// Step 2. Query the cache
System.out.println("-- before get: number of locks held is " + cache1_.getNumberOfLocksHeld());
- time1=System.currentTimeMillis();
- nOps=get(cache1_, hasTx, oneTxOnly);
- time2=System.currentTimeMillis();
+ time1 = System.currentTimeMillis();
+ nOps = get(cache1_, hasTx, oneTxOnly);
+ time2 = System.currentTimeMillis();
System.out.println("-- after get: number of locks held is " + cache1_.getNumberOfLocksHeld());
- d=(double)(time2 - time1) / nOps;
+ d = (double) (time2 - time1) / nOps;
log("Time elapsed for _get is " + (time2 - time1) + " with " + nOps
+ " operations. Average per ops is: " + form.format(d, dumbStr, fieldPos) +
" msec.");
- dumbStr=new StringBuffer();
+ dumbStr = new StringBuffer();
// Step 3. Remove entries from the cache
System.out.println("-- before remove: number of locks held is " + cache1_.getNumberOfLocksHeld());
- time1=System.currentTimeMillis();
- nOps=remove(cache1_, hasTx, oneTxOnly);
- time2=System.currentTimeMillis();
+ time1 = System.currentTimeMillis();
+ nOps = remove(cache1_, hasTx, oneTxOnly);
+ time2 = System.currentTimeMillis();
System.out.println("-- after remove: number of locks held is " + cache1_.getNumberOfLocksHeld());
- d=(double)(time2 - time1) / nOps;
+ d = (double) (time2 - time1) / nOps;
log("Time elapsed for _remove is " + (time2 - time1) + " with " + nOps
+ " operations. Average per ops is: " + form.format(d, dumbStr, fieldPos) +
" msec.");
}
- public void test2CachesTx() throws Exception {
+ public void test2CachesTx() throws Exception
+ {
log("=== 2 caches with transaction (no concurrent access) ===");
- cache1_=createCache(IsolationLevel.REPEATABLE_READ);
- cache2_=createCache(IsolationLevel.REPEATABLE_READ);
- cache1_.startService();
- cache2_.startService();
+ cache1_ = createCache(IsolationLevel.REPEATABLE_READ);
+ cache2_ = createCache(IsolationLevel.REPEATABLE_READ);
+ cache1_.start();
+ cache2_.start();
// Formating
- DecimalFormat form=new DecimalFormat("#.00");
- FieldPosition fieldPos=new FieldPosition(0);
- StringBuffer dumbStr=new StringBuffer();
- boolean hasTx=true;
- boolean oneTxOnly=false;
+ DecimalFormat form = new DecimalFormat("#.00");
+ FieldPosition fieldPos = new FieldPosition(0);
+ StringBuffer dumbStr = new StringBuffer();
+ boolean hasTx = true;
+ boolean oneTxOnly = false;
// Step 1. Add entries to the cache
- long time1=System.currentTimeMillis();
- int nOps=add(cache1_, hasTx, oneTxOnly);
- long time2=System.currentTimeMillis();
- double d=(double)(time2 - time1) / nOps;
+ long time1 = System.currentTimeMillis();
+ int nOps = add(cache1_, hasTx, oneTxOnly);
+ long time2 = System.currentTimeMillis();
+ double d = (double) (time2 - time1) / nOps;
log("Time elapsed for _add is " + (time2 - time1) + " with " + nOps
+ " operations. Average per ops is: " + form.format(d, dumbStr, fieldPos) +
" msec.");
- dumbStr=new StringBuffer();
+ dumbStr = new StringBuffer();
// Step 2. Query the cache
- time1=System.currentTimeMillis();
- nOps=get(cache1_, hasTx, oneTxOnly);
- time2=System.currentTimeMillis();
- d=(double)(time2 - time1) / nOps;
+ time1 = System.currentTimeMillis();
+ nOps = get(cache1_, hasTx, oneTxOnly);
+ time2 = System.currentTimeMillis();
+ d = (double) (time2 - time1) / nOps;
log("Time elapsed for _get is " + (time2 - time1) + " with " + nOps
+ " operations. Average per ops is: " + form.format(d, dumbStr, fieldPos) +
" msec.");
- dumbStr=new StringBuffer();
+ dumbStr = new StringBuffer();
// Step 3. Remove entries from the cache
- time1=System.currentTimeMillis();
- nOps=remove(cache2_, hasTx, oneTxOnly); // Note we remove nodes from cache2.
- time2=System.currentTimeMillis();
- d=(double)(time2 - time1) / nOps;
+ time1 = System.currentTimeMillis();
+ nOps = remove(cache2_, hasTx, oneTxOnly); // Note we remove nodes from cache2.
+ time2 = System.currentTimeMillis();
+ d = (double) (time2 - time1) / nOps;
log("Time elapsed for _remove is " + (time2 - time1) + " with " + nOps
+ " operations. Average per ops is: " + form.format(d, dumbStr, fieldPos) +
" msec.");
}
- public void test2CachesOneTxOnly() throws Exception {
+ public void test2CachesOneTxOnly() throws Exception
+ {
log("=== 2 caches with single transaction only (no concurrent access) ===");
- cache1_=createCache(IsolationLevel.REPEATABLE_READ);
- cache2_=createCache(IsolationLevel.REPEATABLE_READ);
- cache1_.startService();
- cache2_.startService();
+ cache1_ = createCache(IsolationLevel.REPEATABLE_READ);
+ cache2_ = createCache(IsolationLevel.REPEATABLE_READ);
+ cache1_.start();
+ cache2_.start();
// Formating
- DecimalFormat form=new DecimalFormat("#.00");
- FieldPosition fieldPos=new FieldPosition(0);
- StringBuffer dumbStr=new StringBuffer();
- boolean hasTx=true;
- boolean oneTxOnly=true;
+ DecimalFormat form = new DecimalFormat("#.00");
+ FieldPosition fieldPos = new FieldPosition(0);
+ StringBuffer dumbStr = new StringBuffer();
+ boolean hasTx = true;
+ boolean oneTxOnly = true;
// Step 1. Add entries to the cache
- long time1=System.currentTimeMillis();
- int nOps=add(cache1_, hasTx, oneTxOnly);
- long time2=System.currentTimeMillis();
- double d=(double)(time2 - time1) / nOps;
+ long time1 = System.currentTimeMillis();
+ int nOps = add(cache1_, hasTx, oneTxOnly);
+ long time2 = System.currentTimeMillis();
+ double d = (double) (time2 - time1) / nOps;
log("Time elapsed for _add is " + (time2 - time1) + " with " + nOps
+ " operations. Average per ops is: " + form.format(d, dumbStr, fieldPos) +
" msec.");
- dumbStr=new StringBuffer();
+ dumbStr = new StringBuffer();
// Step 2. Query the cache
- time1=System.currentTimeMillis();
- nOps=get(cache1_, hasTx, oneTxOnly);
- time2=System.currentTimeMillis();
- d=(double)(time2 - time1) / nOps;
+ time1 = System.currentTimeMillis();
+ nOps = get(cache1_, hasTx, oneTxOnly);
+ time2 = System.currentTimeMillis();
+ d = (double) (time2 - time1) / nOps;
log("Time elapsed for _get is " + (time2 - time1) + " with " + nOps
+ " operations. Average per ops is: " + form.format(d, dumbStr, fieldPos) +
" msec.");
- dumbStr=new StringBuffer();
+ dumbStr = new StringBuffer();
// Step 3. Remove entries from the cache
- time1=System.currentTimeMillis();
- nOps=remove(cache2_, hasTx, oneTxOnly); // Note we remove nodes from cache2.
- time2=System.currentTimeMillis();
- d=(double)(time2 - time1) / nOps;
+ time1 = System.currentTimeMillis();
+ nOps = remove(cache2_, hasTx, oneTxOnly); // Note we remove nodes from cache2.
+ time2 = System.currentTimeMillis();
+ d = (double) (time2 - time1) / nOps;
log("Time elapsed for _remove is " + (time2 - time1) + " with " + nOps
+ " operations. Average per ops is: " + form.format(d, dumbStr, fieldPos) +
" msec.");
}
- public void test3CachesTx() throws Exception {
+ public void test3CachesTx() throws Exception
+ {
log("=== 3 caches with transaction (no concurrent access) ===");
- cache1_=createCache(IsolationLevel.REPEATABLE_READ);
- cache2_=createCache(IsolationLevel.REPEATABLE_READ);
- cache3_=createCache(IsolationLevel.REPEATABLE_READ);
- cache1_.startService();
- cache2_.startService();
- cache3_.startService();
+ cache1_ = createCache(IsolationLevel.REPEATABLE_READ);
+ cache2_ = createCache(IsolationLevel.REPEATABLE_READ);
+ cache3_ = createCache(IsolationLevel.REPEATABLE_READ);
+ cache1_.start();
+ cache2_.start();
+ cache3_.start();
// Formating
- DecimalFormat form=new DecimalFormat("#.00");
- FieldPosition fieldPos=new FieldPosition(0);
- StringBuffer dumbStr=new StringBuffer();
- boolean hasTx=true;
- boolean oneTxOnly=false;
+ DecimalFormat form = new DecimalFormat("#.00");
+ FieldPosition fieldPos = new FieldPosition(0);
+ StringBuffer dumbStr = new StringBuffer();
+ boolean hasTx = true;
+ boolean oneTxOnly = false;
// Step 1. Add entries to the cache
- long time1=System.currentTimeMillis();
- int nOps=add(cache1_, hasTx, oneTxOnly);
- long time2=System.currentTimeMillis();
- double d=(double)(time2 - time1) / nOps;
+ long time1 = System.currentTimeMillis();
+ int nOps = add(cache1_, hasTx, oneTxOnly);
+ long time2 = System.currentTimeMillis();
+ double d = (double) (time2 - time1) / nOps;
log("Time elapsed for _add is " + (time2 - time1) + " with " + nOps
+ " operations. Average per ops is: " + form.format(d, dumbStr, fieldPos) +
" msec.");
- dumbStr=new StringBuffer();
+ dumbStr = new StringBuffer();
// Step 2. Query the cache
- time1=System.currentTimeMillis();
- nOps=get(cache2_, hasTx, oneTxOnly); // Note query is from cache2
- time2=System.currentTimeMillis();
- d=(double)(time2 - time1) / nOps;
+ time1 = System.currentTimeMillis();
+ nOps = get(cache2_, hasTx, oneTxOnly); // Note query is from cache2
+ time2 = System.currentTimeMillis();
+ d = (double) (time2 - time1) / nOps;
log("Time elapsed for _get is " + (time2 - time1) + " with " + nOps
+ " operations. Average per ops is: " + form.format(d, dumbStr, fieldPos) +
" msec.");
- dumbStr=new StringBuffer();
+ dumbStr = new StringBuffer();
// Step 3. Remove entries from the cache
- time1=System.currentTimeMillis();
- nOps=remove(cache3_, hasTx, oneTxOnly); // Note remove is from cache3
- time2=System.currentTimeMillis();
- d=(double)(time2 - time1) / nOps;
+ time1 = System.currentTimeMillis();
+ nOps = remove(cache3_, hasTx, oneTxOnly); // Note remove is from cache3
+ time2 = System.currentTimeMillis();
+ d = (double) (time2 - time1) / nOps;
log("Time elapsed for _remove is " + (time2 - time1) + " with " + nOps
+ " operations. Average per ops is: " + form.format(d, dumbStr, fieldPos) +
" msec.");
}
- private int add(TreeCache cache, boolean hasTx, boolean oneTxOnly) throws Exception {
- try {
+ private int add(TreeCache cache, boolean hasTx, boolean oneTxOnly) throws Exception
+ {
+ try
+ {
return _add(cache, hasTx, oneTxOnly);
}
- catch(Throwable t) {
+ catch (Throwable t)
+ {
t.printStackTrace();
System.out.println("cache locks: " + cache.printLockInfo());
return 0;
@@ -362,60 +383,75 @@
}
}
- private int _add(TreeCache cache, boolean hasTx, boolean oneTxOnly) throws Exception {
- if(hasTx && oneTxOnly) {
- tx=startTransaction();
+ private int _add(TreeCache cache, boolean hasTx, boolean oneTxOnly) throws Exception
+ {
+ if (hasTx && oneTxOnly)
+ {
+ tx = startTransaction();
}
- for(int i=0; i < nodeList_.size(); i++) {
- String key=Integer.toString(i);
- String value=Integer.toString(i);
- if(hasTx && !oneTxOnly) {
- tx=startTransaction();
- cache.put((String)nodeList_.get(i), key, value);
+ for (int i = 0; i < nodeList_.size(); i++)
+ {
+ String key = Integer.toString(i);
+ String value = Integer.toString(i);
+ if (hasTx && !oneTxOnly)
+ {
+ tx = startTransaction();
+ cache.put((String) nodeList_.get(i), key, value);
tx.commit();
}
- else {
- cache.put((String)nodeList_.get(i), key, value);
+ else
+ {
+ cache.put((String) nodeList_.get(i), key, value);
}
}
- if(hasTx && oneTxOnly) {
+ if (hasTx && oneTxOnly)
+ {
tx.commit();
}
return nodeList_.size();
}
- private int get(TreeCache cache, boolean hasTx, boolean oneTxOnly) throws Exception {
- try {
+ private int get(TreeCache cache, boolean hasTx, boolean oneTxOnly) throws Exception
+ {
+ try
+ {
return _get(cache, hasTx, oneTxOnly);
}
- catch(Throwable t) {
+ catch (Throwable t)
+ {
t.printStackTrace();
System.out.println("cache locks: " + cache.printLockInfo());
- throw (Exception)t;
+ throw (Exception) t;
}
}
- private int _get(TreeCache cache, boolean hasTx, boolean oneTxOnly) throws Exception {
- if(hasTx && oneTxOnly) {
- tx=startTransaction();
+ private int _get(TreeCache cache, boolean hasTx, boolean oneTxOnly) throws Exception
+ {
+ if (hasTx && oneTxOnly)
+ {
+ tx = startTransaction();
}
- for(int i=0; i < nodeList_.size(); i++) {
- String key=Integer.toString(i);
- if(hasTx && !oneTxOnly) {
- tx=startTransaction();
- cache.get((String)nodeList_.get(i), key);
+ for (int i = 0; i < nodeList_.size(); i++)
+ {
+ String key = Integer.toString(i);
+ if (hasTx && !oneTxOnly)
+ {
+ tx = startTransaction();
+ cache.get((String) nodeList_.get(i), key);
tx.commit();
}
- else {
- cache.get((String)nodeList_.get(i), key);
+ else
+ {
+ cache.get((String) nodeList_.get(i), key);
}
}
- if(hasTx && oneTxOnly) {
+ if (hasTx && oneTxOnly)
+ {
tx.commit();
}
@@ -423,35 +459,44 @@
}
- private int remove(TreeCache cache, boolean hasTx, boolean oneTxOnly) throws Exception {
- try {
+ private int remove(TreeCache cache, boolean hasTx, boolean oneTxOnly) throws Exception
+ {
+ try
+ {
return _remove(cache, hasTx, oneTxOnly);
}
- catch(Throwable t) {
+ catch (Throwable t)
+ {
t.printStackTrace();
System.out.println("cache locks: " + cache.printLockInfo());
- throw (Exception)t;
+ throw (Exception) t;
}
}
- private int _remove(TreeCache cache, boolean hasTx, boolean oneTxOnly) throws Exception {
- if(hasTx && oneTxOnly) {
- tx=startTransaction();
+ private int _remove(TreeCache cache, boolean hasTx, boolean oneTxOnly) throws Exception
+ {
+ if (hasTx && oneTxOnly)
+ {
+ tx = startTransaction();
}
- for(int i=0; i < nodeList_.size(); i++) {
- String key=Integer.toString(i);
- if(hasTx && !oneTxOnly) {
- tx=startTransaction();
- cache.remove((String)nodeList_.get(i), key);
+ for (int i = 0; i < nodeList_.size(); i++)
+ {
+ String key = Integer.toString(i);
+ if (hasTx && !oneTxOnly)
+ {
+ tx = startTransaction();
+ cache.remove((String) nodeList_.get(i), key);
tx.commit();
}
- else {
- cache.remove((String)nodeList_.get(i), key);
+ else
+ {
+ cache.remove((String) nodeList_.get(i), key);
}
}
- if(hasTx && oneTxOnly) {
+ if (hasTx && oneTxOnly)
+ {
tx.commit();
}
@@ -462,28 +507,32 @@
* Generate the tree nodes quasi-exponentially. I.e., depth is the level
* of the hierarchy and children is the number of children under each node.
*/
- private ArrayList nodeGen(int depth, int children) {
- ArrayList strList=new ArrayList();
- ArrayList oldList=new ArrayList();
- ArrayList newList=new ArrayList();
+ private ArrayList nodeGen(int depth, int children)
+ {
+ ArrayList strList = new ArrayList();
+ ArrayList oldList = new ArrayList();
+ ArrayList newList = new ArrayList();
oldList.add("/");
newList.add("/");
strList.add("/");
- while(depth > 0) {
+ while (depth > 0)
+ {
// Trying to produce node name at this depth.
- newList=new ArrayList();
- for(int i=0; i < oldList.size(); i++) {
- for(int j=0; j < children; j++) {
- String tmp=(String)oldList.get(i);
- tmp+=Integer.toString(j);
- if(depth != 1) tmp+="/";
+ newList = new ArrayList();
+ for (int i = 0; i < oldList.size(); i++)
+ {
+ for (int j = 0; j < children; j++)
+ {
+ String tmp = (String) oldList.get(i);
+ tmp += Integer.toString(j);
+ if (depth != 1) tmp += "/";
newList.add(tmp);
}
}
strList.addAll(newList);
- oldList=newList;
+ oldList = newList;
depth--;
}
@@ -491,11 +540,13 @@
return strList;
}
- public static Test suite() throws Exception {
+ public static Test suite() throws Exception
+ {
return new TestSuite(ReplicatedSyncPerfTest.class);
}
- private void log(String str) {
+ private void log(String str)
+ {
// System.out.println(this.getClass().getName() +": " +str);
System.out.println(str);
}
1.54 +149 -109 JBossCache/tests/perf/org/jboss/cache/Server.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: Server.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/tests/perf/org/jboss/cache/Server.java,v
retrieving revision 1.53
retrieving revision 1.54
diff -u -b -r1.53 -r1.54
--- Server.java 16 Aug 2006 10:52:52 -0000 1.53
+++ Server.java 6 Sep 2006 15:31:01 -0000 1.54
@@ -11,13 +11,13 @@
import EDU.oswego.cs.dl.util.concurrent.CountDown;
import org.jboss.cache.aop.PojoCache;
+import org.jboss.cache.config.Configuration;
import org.jboss.cache.data.Address;
import org.jboss.cache.data.Course;
import org.jboss.cache.data.RandomString;
import org.jboss.cache.data.Student;
-import org.jboss.cache.transaction.DummyTransactionManager;
import org.jboss.cache.factories.XmlConfigurationParser;
-import org.jboss.cache.config.Configuration;
+import org.jboss.cache.transaction.DummyTransactionManager;
import org.jgroups.View;
import javax.transaction.SystemException;
@@ -35,7 +35,8 @@
/**
* A standalone dummy server that accepts data from other replicated cache.
*/
-public class Server {
+public class Server
+{
static PojoCache cache_;
Properties props_ = new Properties();
static int threads_; // how many threads to send the put.
@@ -57,10 +58,11 @@
static long endTime_ = 0;
static int operationType_ = 1;
- void initCache() throws Exception {
+ void initCache() throws Exception
+ {
cache_ = new PojoCache();
- String file = (String)props_.get("cache_config");
- if(file==null)
+ String file = (String) props_.get("cache_config");
+ if (file == null)
{
throw new RuntimeException("Cache config xml is not specified.");
}
@@ -70,21 +72,25 @@
c.setTransactionManagerLookupClass("org.jboss.cache.DummyTransactionManagerLookup");
}
- void destroyCache() throws Exception {
- cache_.stopService();
+ void destroyCache() throws Exception
+ {
+ cache_.stop();
cache_ = null;
}
- TreeCache getCache() {
+ TreeCache getCache()
+ {
return cache_;
}
- void parseConfig(String fileName) throws Exception {
+ void parseConfig(String fileName) throws Exception
+ {
String line;
StringTokenizer st;
String key, val;
BufferedReader fileReader = new BufferedReader(new FileReader(fileName));
- while ((line = fileReader.readLine()) != null) {
+ while ((line = fileReader.readLine()) != null)
+ {
if (line.startsWith("#"))
continue;
line = line.trim();
@@ -94,44 +100,45 @@
key = st.nextToken().toLowerCase();
val = st.nextToken();
props_.put(key, val);
- System.out.println("Read in config key, value: "+ key + " "+ val);
+ System.out.println("Read in config key, value: " + key + " " + val);
}
fileReader.close();
}
- void startLoadTest() throws InterruptedException, CacheException {
- String str = (String)props_.get("threads");
- if(str == null)
+ void startLoadTest() throws InterruptedException, CacheException
+ {
+ String str = (String) props_.get("threads");
+ if (str == null)
throw new RuntimeException("Can't find threads property");
threads_ = Integer.parseInt(str);
- str = (String)props_.get("loops");
- if(str == null)
+ str = (String) props_.get("loops");
+ if (str == null)
throw new RuntimeException("Can't find loops property");
loops_ = Integer.parseInt(str);
- str = (String)props_.get("sleep_interval_millis");
- if(str == null)
+ str = (String) props_.get("sleep_interval_millis");
+ if (str == null)
throw new RuntimeException("Can't find sleepIntervalInMillis property");
sleepIntervalInMillis_ = Integer.parseInt(str);
- str = (String)props_.get("random_sleep_interval");
- if(str == null)
+ str = (String) props_.get("random_sleep_interval");
+ if (str == null)
throw new RuntimeException("Can't find random_sleep_interval property");
randomSleep_ = new Boolean(str).booleanValue();
- str = (String)props_.get("object_list_size");
- if(str == null)
+ str = (String) props_.get("object_list_size");
+ if (str == null)
throw new RuntimeException("Can't find objectListSize property");
objectListSize_ = Integer.parseInt(str);
- str = (String)props_.get("transaction");
- if(str == null)
+ str = (String) props_.get("transaction");
+ if (str == null)
throw new RuntimeException("Can't find transaction property");
transaction_ = new Boolean(str).booleanValue();
@@ -143,14 +150,14 @@
operationType_ = Integer.parseInt(str); */
- str = (String)props_.get("run_pojocache");
- if(str == null)
+ str = (String) props_.get("run_pojocache");
+ if (str == null)
throw new RuntimeException("Can't find run_PojoCache property");
runPojoCache_ = new Boolean(str).booleanValue();
- str = (String)props_.get("update_pojo_interval");
- if(str == null)
+ str = (String) props_.get("update_pojo_interval");
+ if (str == null)
throw new RuntimeException("Can't find update_pojo_interval property");
updatePojoInterval_ = Integer.parseInt(str);
@@ -158,22 +165,22 @@
countdown_ = new CountDown(threads_);
// Warm up the cache first to avoid any simultaneous write contention.
- if(cache_.getCoordinator().equals(cache_.getLocalAddress()))
+ if (cache_.getCoordinator().equals(cache_.getLocalAddress()))
{
- System.out.println("I am the coordinator: " +cache_.getLocalAddress());
- cache_.put(ROOT +cache_.getLocalAddress().toString(), "test", "test");
+ System.out.println("I am the coordinator: " + cache_.getLocalAddress());
+ cache_.put(ROOT + cache_.getLocalAddress().toString(), "test", "test");
}
sleep_(300);
- if(runPojoCache_)
+ if (runPojoCache_)
{
// This is to pre-load the POJO class definition
Object pojo = Loader.constructObject();
- cache_.putObject(ROOT + cache_.getLocalAddress().toString() +"/test", pojo);
+ cache_.putObject(ROOT + cache_.getLocalAddress().toString() + "/test", pojo);
}
startTime_ = System.currentTimeMillis();
- for(int i=0; i < threads_ ; i++)
+ for (int i = 0; i < threads_; i++)
{
Loader loader = new Loader(cache_, i, cache_.getLocalAddress().toString());
loader.start();
@@ -182,12 +189,13 @@
static int getSleepInterval()
{
- if(sleepIntervalInMillis_ ==0) return sleepIntervalInMillis_;
+ if (sleepIntervalInMillis_ == 0) return sleepIntervalInMillis_;
- if(randomSleep_)
+ if (randomSleep_)
{
return random.nextInt(sleepIntervalInMillis_);
- } else
+ }
+ else
{
return sleepIntervalInMillis_;
}
@@ -197,7 +205,7 @@
{
StringTokenizer tok = new StringTokenizer(addrListStr, ",");
List list = new ArrayList();
- while(tok.hasMoreTokens())
+ while (tok.hasMoreTokens())
{
list.add(tok.nextToken());
}
@@ -207,12 +215,16 @@
static void sleep_(long msec)
{
- try {
+ try
+ {
Thread.sleep(msec);
- } catch (InterruptedException e) {
+ }
+ catch (InterruptedException e)
+ {
e.printStackTrace();
}
}
+
void printUsage()
{
System.out.println("Options: -config to specify config file (like bench.txt)\n" +
@@ -224,24 +236,31 @@
System.out.println("\n************************************");
System.out.println("\nThis is a simple performance test for JBossCache.\n" +
"The load pattern is like those of http session repl, that is,\neach put " +
- "is under a separate sub-tree.\n" +"As a result, there should not be write contention.\n");
+ "is under a separate sub-tree.\n" + "As a result, there should not be write contention.\n");
}
- public static void main(String[] args) throws Exception {
+ public static void main(String[] args) throws Exception
+ {
Server server = new Server();
- if(args.length ==0)
+ if (args.length == 0)
{
server.printUsage();
return;
}
- for (int i = 0; i < args.length; i++) {
- if ("-config".equals(args[i])) {
- System.out.println("Configuration file is: " + args[i+1]);
+ for (int i = 0; i < args.length; i++)
+ {
+ if ("-config".equals(args[i]))
+ {
+ System.out.println("Configuration file is: " + args[i + 1]);
server.parseConfig(args[++i]);
- } else if("-receiver".equals(args[i])) {
+ }
+ else if ("-receiver".equals(args[i]))
+ {
receiver_ = true;
- } else {
+ }
+ else
+ {
System.err.println("Unknown argument:" + args[i]);
server.printUsage();
return;
@@ -250,17 +269,18 @@
server.printInfo();
- String addrListStr = (String)server.props_.get("members");
+ String addrListStr = (String) server.props_.get("members");
List addrList = server.getMembers(addrListStr);
server.initCache();
ViewListener listener = new ViewListener(addrList);
cache_.getNotifier().addCacheListener(listener);
- cache_.startService();
+ cache_.start();
System.out.println("Cache started .. ");
System.out.println("Waiting for the other nodes to start up...");
- while (!isReady_) {
+ while (!isReady_)
+ {
sleep_(100);
}
@@ -270,7 +290,7 @@
sleep_(2000);
- if(!receiver_)
+ if (!receiver_)
{
server.startLoadTest();
System.out.println("Waiting for the test to finish...");
@@ -278,19 +298,20 @@
countdown_.acquire();
endTime_ = System.currentTimeMillis();
System.out.println("\nThroughtput for this node with:\n" + "threads = " + threads_
- +"\nloops = " +loops_
- + "\nsleep interval = " +sleepIntervalInMillis_ + "\nobject list size = "
- + objectListSize_ + "\ntranasaction? " +transaction_ +"\n"
- + "is: " + (loops_ *threads_ *1000)/(endTime_ -startTime_) + " requests/sec\n");
- } else
+ + "\nloops = " + loops_
+ + "\nsleep interval = " + sleepIntervalInMillis_ + "\nobject list size = "
+ + objectListSize_ + "\ntranasaction? " + transaction_ + "\n"
+ + "is: " + (loops_ * threads_ * 1000) / (endTime_ - startTime_) + " requests/sec\n");
+ }
+ else
{
System.out.println("Receiver mode only. Won't send request...");
}
- if(ex_ != null)
+ if (ex_ != null)
{
- System.err.println("Exception counts: " +exceptionCounts_);
- throw new RuntimeException("Exception occurred during the run: " +ex_);
+ System.err.println("Exception counts: " + exceptionCounts_);
+ throw new RuntimeException("Exception occurred during the run: " + ex_);
}
System.out.println("Test is finished. hit ctrl-c to kill the process ...");
@@ -302,23 +323,26 @@
// server.destroyCache();
}
- public static class ViewListener extends AbstractCacheListener {
+ public static class ViewListener extends AbstractCacheListener
+ {
List addrList_; // List of address
- public ViewListener(List addrList) {
+ public ViewListener(List addrList)
+ {
addrList_ = addrList;
}
+
public void viewChange(View new_view) // might be MergeView after merging
{
Vector vector = new_view.getMembers();
- if(vector.size() > addrList_.size())
+ if (vector.size() > addrList_.size())
{
// We have more members than is specified!
throw new RuntimeException("You have more members in the cluster group than specified in the config."
- + " size of members now: " +vector.size());
+ + " size of members now: " + vector.size());
}
// Need to match individually but let's just assum the size matters then.
- if(vector.size() == addrList_.size())
+ if (vector.size() == addrList_.size())
{
// good to go
isReady_ = true;
@@ -342,7 +366,8 @@
// System.out.println("Local addres is: " +localAddress.toString());
}
- public void run() {
+ public void run()
+ {
Object obj = null;
Object obj1 = constructObject();
Object obj2 = constructObject();
@@ -350,22 +375,23 @@
long start_time = System.currentTimeMillis();
boolean isEven = true;
- for(int i=0; i < loops_; i++)
+ for (int i = 0; i < loops_; i++)
{
- if(getSleepInterval() !=0)
+ if (getSleepInterval() != 0)
sleep_(getSleepInterval());
Transaction tx = null;
- try {
- if(transaction_)
+ try
+ {
+ if (transaction_)
{
tm_.begin();
tx = tm_.getTransaction();
}
boolean update = true;
- if(runPojoCache_ && updatePojoInterval_!= 1)
+ if (runPojoCache_ && updatePojoInterval_ != 1)
{
- if((i%updatePojoInterval_) != 0 )
+ if ((i % updatePojoInterval_) != 0)
{
update = false;
}
@@ -375,9 +401,9 @@
* Need this for PojoCache. Otherwise, it'd be cheating becuase another putObject of thee
* same pojo is fast.
*/
- if(update)
+ if (update)
{
- if(isEven)
+ if (isEven)
{
obj = obj1;
isEven = false;
@@ -390,53 +416,62 @@
}
doWork(fqn, localAddress, obj, update);
- if(transaction_)
+ if (transaction_)
{
tx.commit();
}
- } catch (Exception e) {
+ }
+ catch (Exception e)
+ {
exceptionCounts_++;
ex_ = e;
e.printStackTrace();
- if(transaction_)
+ if (transaction_)
+ {
+ try
{
- try {
tx.rollback();
- } catch (SystemException e1) {
+ }
+ catch (SystemException e1)
+ {
e1.printStackTrace();
ex_ = e1;
}
}
- } finally
+ }
+ finally
{
}
// System.out.println("Processing at loop: " +i);
- if( (i%50) ==0 && threadId == 0)
+ if ((i % 50) == 0 && threadId == 0)
{
- System.out.println("Processing at loop: " +i);
+ System.out.println("Processing at loop: " + i);
}
}
long end_time = System.currentTimeMillis();
long time = end_time - start_time;
- if(threadId == 0)
- System.out.println("Total time spent (ms) on thread id 0: " +time + " for "+ loops_ +" loops");
+ if (threadId == 0)
+ System.out.println("Total time spent (ms) on thread id 0: " + time + " for " + loops_ + " loops");
countdown_.release();
}
- void doWork(String fqn, Object key, Object pojo, boolean update) throws CacheException {
+ void doWork(String fqn, Object key, Object pojo, boolean update) throws CacheException
+ {
// Note that we still need to reconstruct object every loop to avoid cheating false identity problem.
- if(!runPojoCache_)
+ if (!runPojoCache_)
{
doPlainCacheWork(fqn, key, pojo);
- } else
+ }
+ else
{
- if(update)
+ if (update)
{
// System.out.println("Running pojo cache update");
doPojoCacheWork(fqn, pojo);
- } else
+ }
+ else
{
// System.out.println("Running field update");
doPojoCacheFieldWork(fqn, pojo);
@@ -444,53 +479,58 @@
}
}
- void doPlainCacheWork(String fqn, Object key, Object pojo) throws CacheException {
- if(operationType_ == 1)
+ void doPlainCacheWork(String fqn, Object key, Object pojo) throws CacheException
+ {
+ if (operationType_ == 1)
{
Object obj1 = constructObject();
cache_.put(fqn, key, obj1);
Object obj = cache_.get(fqn, key);
- if(!((Student)obj).getName().equals("Joe"))
+ if (!((Student) obj).getName().equals("Joe"))
{
throw new RuntimeException("Value returned not Joe");
}
- } else
+ }
+ else
{
cache_.remove(fqn, key);
cache_.put(fqn, key, pojo);
Object obj = cache_.get(fqn, key);
- if(!((Student)obj).getName().equals("Joe"))
+ if (!((Student) obj).getName().equals("Joe"))
{
throw new RuntimeException("Value returned not Joe");
}
}
}
- void doPojoCacheWork(String fqn, Object pojo) throws CacheException {
- if(operationType_ == 1)
+ void doPojoCacheWork(String fqn, Object pojo) throws CacheException
+ {
+ if (operationType_ == 1)
{
cache_.putObject(fqn, pojo);
Object obj = cache_.getObject(fqn);
- if(!((Student)obj).getName().equals("Joe"))
+ if (!((Student) obj).getName().equals("Joe"))
{
throw new RuntimeException("Value returned not Joe");
}
- } else
+ }
+ else
{
cache_.removeObject(fqn);
cache_.putObject(fqn, pojo);
Object obj = cache_.getObject(fqn);
- if(!((Student)obj).getName().equals("Joe"))
+ if (!((Student) obj).getName().equals("Joe"))
{
throw new RuntimeException("Value returned not Joe");
}
}
}
- void doPojoCacheFieldWork(String fqn, Object pojo) throws CacheException {
+ void doPojoCacheFieldWork(String fqn, Object pojo) throws CacheException
+ {
Object obj = cache_.getObject(fqn);
- List list = (List)((Student)obj).getCourses();
- ((Course)list.get(0)).setInstructor("Ben Wang");
+ List list = (List) ((Student) obj).getCourses();
+ ((Course) list.get(0)).setInstructor("Ben Wang");
// ((Student)obj).setSchool("Pingtung");
}
@@ -506,14 +546,14 @@
joe.setAddress(add);
String str;
- for(int i=0; i < objectListSize_; i++)
+ for (int i = 0; i < objectListSize_; i++)
{
Course course = new Course();
- str = RandomString.randomstring(10,20);
+ str = RandomString.randomstring(10, 20);
course.setInstructor(str);
- str = RandomString.randomstring(10,20);
+ str = RandomString.randomstring(10, 20);
course.setTitle(str);
- str = RandomString.randomstring(10,20);
+ str = RandomString.randomstring(10, 20);
course.setRoom(str);
joe.addCourse(course);
}
More information about the jboss-cvs-commits
mailing list