[jboss-cvs] JBossCache/tests/perf/org/jboss/cache/test/perf ...
Manik Surtani
manik at jboss.org
Wed May 23 06:28:49 EDT 2007
User: msurtani
Date: 07/05/23 06:28:48
Modified: tests/perf/org/jboss/cache/test/perf Student.java
Person.java RandomString.java Server.java
Log:
Initiated a bunch of performance fixes, including replacing CopyOnWriteArraySets with org.jboss.cache.util.concurrent.ConcurrentHashSet.
Also ran an imports optimiser on the code base - there were a lot of unused imports floating about.
Revision Changes Path
1.2 +10 -6 JBossCache/tests/perf/org/jboss/cache/test/perf/Student.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: Student.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/tests/perf/org/jboss/cache/test/perf/Student.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- Student.java 12 Apr 2007 17:25:13 -0000 1.1
+++ Student.java 23 May 2007 10:28:48 -0000 1.2
@@ -1,9 +1,13 @@
package org.jboss.cache.test.perf;
-import java.util.*;
-
import org.jboss.cache.pojo.annotation.Replicable;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+
/**
* @author Ben Wang
@@ -12,7 +16,7 @@
public class Student extends Person
{
protected String school;
-// protected Set courses = new LinkedHashSet();
+ // protected Set courses = new LinkedHashSet();
protected List courses = new ArrayList();
public void setSchool(String school)
@@ -43,12 +47,12 @@
public String toString()
{
StringBuffer buf = new StringBuffer();
- buf.append("{Name = " +name).append(", School = " +school);
+ buf.append("{Name = " + name).append(", School = " + school);
if (address != null)
buf.append(", Address = " + address.getSimpleAddress());
buf.append("}\n");
buf.append("Courses:\n");
- for (Iterator iter = getCourses().iterator(); iter.hasNext(); )
+ for (Iterator iter = getCourses().iterator(); iter.hasNext();)
buf.append(iter.next());
return buf.toString();
1.2 +3 -4 JBossCache/tests/perf/org/jboss/cache/test/perf/Person.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: Person.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/tests/perf/org/jboss/cache/test/perf/Person.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- Person.java 12 Apr 2007 17:25:13 -0000 1.1
+++ Person.java 23 May 2007 10:28:48 -0000 1.2
@@ -1,14 +1,13 @@
package org.jboss.cache.test.perf;
-import java.util.List;
-
import org.jboss.cache.pojo.annotation.Replicable;
/**
* @author Ben Wang
*/
@Replicable
-public class Person implements java.io.Serializable {
+public class Person implements java.io.Serializable
+{
protected String name;
protected Address address;
@@ -35,7 +34,7 @@
public String toString()
{
StringBuffer buf = new StringBuffer();
- buf.append("{Name = " +name);
+ buf.append("{Name = " + name);
if (address != null)
buf.append(", Address = " + address.getSimpleAddress());
buf.append("}\n");
1.2 +27 -26 JBossCache/tests/perf/org/jboss/cache/test/perf/RandomString.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: RandomString.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/tests/perf/org/jboss/cache/test/perf/RandomString.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- RandomString.java 12 Apr 2007 17:25:13 -0000 1.1
+++ RandomString.java 23 May 2007 10:28:48 -0000 1.2
@@ -1,11 +1,12 @@
package org.jboss.cache.test.perf;
-import java.util.*;
-
import org.jboss.cache.pojo.annotation.Replicable;
+import java.util.Random;
+
@Replicable
-public class RandomString {
+public class RandomString
+{
private static Random rn = new Random(12);
@@ -23,7 +24,7 @@
int n = rand(lo, hi);
byte b[] = new byte[n];
for (int i = 0; i < n; i++)
- b[i] = (byte)rand('a', 'z');
+ b[i] = (byte) rand('a', 'z');
return new String(b, 0);
}
1.2 +158 -121 JBossCache/tests/perf/org/jboss/cache/test/perf/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/test/perf/Server.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- Server.java 12 Apr 2007 17:25:13 -0000 1.1
+++ Server.java 23 May 2007 10:28:48 -0000 1.2
@@ -9,21 +9,6 @@
package org.jboss.cache.test.perf;
-import java.io.BufferedReader;
-import java.io.FileReader;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
-import java.util.Random;
-import java.util.StringTokenizer;
-import java.util.Vector;
-import java.util.concurrent.CountDownLatch;
-
-import javax.transaction.SystemException;
-import javax.transaction.Transaction;
-import javax.transaction.TransactionManager;
-
import org.jboss.aop.Advised;
import org.jboss.cache.CacheException;
import org.jboss.cache.CacheImpl;
@@ -37,10 +22,25 @@
import org.jboss.cache.transaction.DummyTransactionManager;
import org.jgroups.View;
+import javax.transaction.SystemException;
+import javax.transaction.Transaction;
+import javax.transaction.TransactionManager;
+import java.io.BufferedReader;
+import java.io.FileReader;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Random;
+import java.util.StringTokenizer;
+import java.util.Vector;
+import java.util.concurrent.CountDownLatch;
+
/**
* A standalone dummy server that accepts data from other replicated cache.
*/
-public class Server {
+public class Server
+{
static PojoCache pojoCache;
static CacheImpl<Object, Object> plainCache;
Properties props_ = new Properties();
@@ -63,10 +63,11 @@
static long endTime_ = 0;
static int operationType_ = 1;
- void initCache() throws Exception {
+ void initCache() throws Exception
+ {
- 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.");
}
@@ -74,24 +75,28 @@
Configuration config = parser.parseFile(file);
config.setTransactionManagerLookupClass("org.jboss.cache.transaction.DummyTransactionManagerLookup");
pojoCache = PojoCacheFactory.createCache(config, false);
- plainCache = (CacheImpl)pojoCache.getCache();
+ plainCache = (CacheImpl) pojoCache.getCache();
}
- void destroyCache() throws Exception {
+ void destroyCache() throws Exception
+ {
pojoCache.stop();
pojoCache = null;
}
- PojoCache getCache() {
+ PojoCache getCache()
+ {
return pojoCache;
}
- 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();
@@ -101,44 +106,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();
@@ -150,8 +156,8 @@
operationType_ = Integer.parseInt(str); */
- 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);
@@ -166,15 +172,15 @@
}
sleep_(300);
- if(runPojoCache_)
+ if (runPojoCache_)
{
// This is to pre-load the POJO class definition
Object pojo = Loader.constructObject();
- pojoCache.attach(ROOT + plainCache.getLocalAddress().toString() +"/test", pojo);
+ pojoCache.attach(ROOT + plainCache.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(pojoCache, i, plainCache.getLocalAddress().toString());
loader.start();
@@ -183,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_;
}
@@ -198,7 +205,7 @@
{
StringTokenizer tok = new StringTokenizer(addrListStr, ",");
List list = new ArrayList();
- while(tok.hasMoreTokens())
+ while (tok.hasMoreTokens())
{
list.add(tok.nextToken());
}
@@ -208,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" +
@@ -225,37 +236,43 @@
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
{
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;
}
}
- String str = (String)server.props_.get("run_pojocache");
- if(str == null)
+ String str = (String) server.props_.get("run_pojocache");
+ if (str == null)
throw new RuntimeException("Can't find run_PojoCache property");
server.runPojoCache_ = new Boolean(str).booleanValue();
- if (server.runPojoCache_ && ! Advised.class.isAssignableFrom(Address.class))
+ if (server.runPojoCache_ && !Advised.class.isAssignableFrom(Address.class))
{
System.err.println("Aop not present, either install the JVM agent or run aopc!");
System.exit(1);
@@ -263,7 +280,7 @@
server.printInfo();
- String addrListStr = (String)server.props_.get("members");
+ String addrListStr = (String) server.props_.get("members");
List addrList = server.getMembers(addrListStr);
server.initCache();
@@ -273,7 +290,8 @@
System.out.println("Cache started .. ");
System.out.println("Waiting for the other nodes to start up...");
- while (!isReady_) {
+ while (!isReady_)
+ {
sleep_(100);
}
@@ -283,7 +301,7 @@
sleep_(2000);
- if(!receiver_)
+ if (!receiver_)
{
server.startLoadTest();
System.out.println("Waiting for the test to finish...");
@@ -291,23 +309,24 @@
countdown.await();
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 ...");
- while(true)
+ while (true)
{
sleep_(1000);
}
@@ -315,24 +334,26 @@
// server.destroyCache();
}
- public static class ViewListener implements CacheListener {
+ public static class ViewListener implements CacheListener
+ {
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;
@@ -400,7 +421,8 @@
// System.out.println("Local addres is: " +localAddress.toString());
}
- public void run() {
+ public void run()
+ {
Object obj = null;
Object obj1 = constructObject();
Object obj2 = constructObject();
@@ -408,22 +430,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;
}
@@ -433,9 +456,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;
@@ -448,53 +471,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.countDown();
}
- 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);
@@ -502,54 +534,59 @@
}
}
- void doPlainCacheWork(String fqn, Object key, Object pojo) throws CacheException {
+ void doPlainCacheWork(String fqn, Object key, Object pojo) throws CacheException
+ {
Fqn<String> realFqn = Fqn.fromString(fqn);
- if(operationType_ == 1)
+ if (operationType_ == 1)
{
Object obj1 = constructObject();
plainCache.put(realFqn, key, obj1);
Object obj = plainCache.get(realFqn, key);
- if(!((Student)obj).getName().equals("Joe"))
+ if (!((Student) obj).getName().equals("Joe"))
{
throw new RuntimeException("Value returned not Joe");
}
- } else
+ }
+ else
{
plainCache.remove(realFqn, key);
plainCache.put(realFqn, key, pojo);
Object obj = plainCache.get(realFqn, 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_.attach(fqn, pojo);
Object obj = cache_.find(fqn);
- if(!((Student)obj).getName().equals("Joe"))
+ if (!((Student) obj).getName().equals("Joe"))
{
throw new RuntimeException("Value returned not Joe");
}
- } else
+ }
+ else
{
cache_.detach(fqn);
cache_.attach(fqn, pojo);
Object obj = cache_.find(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_.find(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");
}
@@ -565,14 +602,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