[jboss-cvs] CacheBenchFwk/src/org/cachebench/tests ...
Manik Surtani
manik at jboss.org
Wed Apr 18 15:09:29 EDT 2007
User: msurtani
Date: 07/04/18 15:09:28
Modified: src/org/cachebench/tests StringTest.java
CacheTest.java SimpleTest.java TransientTest.java
AssociationsTest.java SubclassTest.java
PrimitiveTest.java StaticsTest.java
CustomClassTest.java
Log:
Updated loads of stuff
Revision Changes Path
1.4 +2 -2 CacheBenchFwk/src/org/cachebench/tests/StringTest.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: StringTest.java
===================================================================
RCS file: /cvsroot/jboss/CacheBenchFwk/src/org/cachebench/tests/StringTest.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- StringTest.java 13 Mar 2007 14:50:20 -0000 1.3
+++ StringTest.java 18 Apr 2007 19:09:28 -0000 1.4
@@ -14,9 +14,9 @@
/* (non-Javadoc)
* @see org.cachebench.tests.CacheTest#doTest(org.cachebench.config.TestConfig)
*/
- public TestResult doTest(String testName, CacheWrapper cache, String testCaseName, int sampleSize) throws Exception
+ public TestResult doTest(String testName, CacheWrapper cache, String testCaseName, int sampleSize, int numThreads) throws Exception
{
- return performTestWithObjectType(testName, cache, String.class, testCaseName, sampleSize);
+ return performTestWithObjectType(testName, cache, String.class, testCaseName, sampleSize, numThreads);
}
1.4 +2 -1 CacheBenchFwk/src/org/cachebench/tests/CacheTest.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: CacheTest.java
===================================================================
RCS file: /cvsroot/jboss/CacheBenchFwk/src/org/cachebench/tests/CacheTest.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- CacheTest.java 13 Mar 2007 14:50:46 -0000 1.3
+++ CacheTest.java 18 Apr 2007 19:09:28 -0000 1.4
@@ -17,8 +17,9 @@
* @param cache The Cache wrapper for the product under bench-mark.
* @param testCaseName The name of the test case.
* @param sampleSize The sample size of the cache to be tested.
+ * @param numThreads The number of concurrent threads to use to achieve the sample number of invocations
* @return The result of the test.
* @throws Exception When the cache opertations blow up an error.
*/
- public TestResult doTest(String testName, CacheWrapper cache, String testCaseName, int sampleSize) throws Exception;
+ public TestResult doTest(String testName, CacheWrapper cache, String testCaseName, int sampleSize, int numThreads) throws Exception;
}
1.6 +178 -69 CacheBenchFwk/src/org/cachebench/tests/SimpleTest.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: SimpleTest.java
===================================================================
RCS file: /cvsroot/jboss/CacheBenchFwk/src/org/cachebench/tests/SimpleTest.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -b -r1.5 -r1.6
--- SimpleTest.java 13 Mar 2007 14:50:46 -0000 1.5
+++ SimpleTest.java 18 Apr 2007 19:09:28 -0000 1.6
@@ -8,7 +8,13 @@
import org.cachebench.TestResult;
import java.io.Serializable;
+import java.io.ByteArrayOutputStream;
+import java.io.ObjectOutputStream;
import java.util.Date;
+import java.util.concurrent.Executors;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.atomic.AtomicLong;
/**
@@ -17,24 +23,47 @@
*/
public abstract class SimpleTest implements CacheTest
{
- protected Log logger = LogFactory.getLog(this.getClass());
+ protected Log log = LogFactory.getLog(this.getClass());
+ protected AtomicLong numberOfBytesPut = new AtomicLong(0);
+ protected long elapsedSecondsForAllPuts = 0;
+ protected ExecutorService executor;
+ private static final int EXECUTOR_SHUTDOWN_TIMEOUT_SECS = 120;
- protected TestResult performTestWithObjectType(String testCaseName, CacheWrapper cache, Class valueClass, String testName, int sampleSize) throws Exception
+ protected TestResult performTestWithObjectType(String testCaseName, CacheWrapper cache, Class valueClass, String testName, int sampleSize, int numThreads) throws Exception
{
+ log.info("Number of threads " + numThreads);
+ executor = Executors.newFixedThreadPool(numThreads);
+
TestResult result = new TestResult();
result.setTestName(testCaseName);
result.setTestTime(new Date());
result.setTestType(testName);
- logger.info("Performing PUTs");
+ log.info("Performing PUTs");
DescriptiveStatistics putStats = doPuts(cache, valueClass, sampleSize);
- logger.info("Performing GETs");
+ executor = Executors.newFixedThreadPool(numThreads);
+ log.info("Performing GETs");
DescriptiveStatistics getStats = doGets(cache, sampleSize);
result.setGetData(getStats);
result.setPutData(putStats);
result.setTestPassed(true); // The test is passed. The report would make use of this attribute.
+ // calculate throughput, in transactions per second.
+ // we only measure put operations for throughput.
+
+ // calc tps.
+
+ System.out.println("*** sum of time: " + elapsedSecondsForAllPuts);
+ System.out.println("*** num puts occured: " + putStats.getN());
+
+ result.setThroughputTransactionsPerSecond((int) (sampleSize / elapsedSecondsForAllPuts));
+ result.setThroughputBytesPerSecond((int) (numberOfBytesPut.longValue() / elapsedSecondsForAllPuts));
+
+ // set the number of members in the cluster
+ result.setNumMembers(cache.getNumMembers());
+ result.setNumThreads(numThreads);
+
return result;
}
@@ -43,38 +72,58 @@
* @param sampleSize The size of the cache.
* @return The Descriptive statistics of the cache benchmarking.
*/
- private DescriptiveStatistics doGets(CacheWrapper cache, int sampleSize) throws Exception
+ private DescriptiveStatistics doGets(final CacheWrapper cache, int sampleSize) throws Exception
{
- logger.debug("Inside doGets for : " + cache);
- String key = "baseKey";
- Object value = null;
- DescriptiveStatistics stats = DescriptiveStatistics.newInstance();
- boolean useSerializable = cache instanceof SerializableCacheWrapper;
+ log.debug("Inside doGets for : " + cache);
+ final String key = "baseKey";
+ final DescriptiveStatistics stats = DescriptiveStatistics.newInstance();
+ final boolean useSerializable = cache instanceof SerializableCacheWrapper;
for (int i = 0; i < sampleSize; i++)
{
+ final int cycleNumber = i;
+ Runnable r = new Runnable()
+ {
+ public void run()
+ {
+ try
+ {
if (!useSerializable)
{
// start your timer...
long startTime = System.currentTimeMillis();
- cache.get(key + i);
+ cache.get(key + cycleNumber);
long statValue = (System.currentTimeMillis() - startTime);
stats.addValue(statValue);
- logger.debug("The Get stat : " + statValue);
+ log.debug("The Get stat : " + statValue);
}
else
{
SerializableCacheWrapper sCache = (SerializableCacheWrapper) cache;
long startTime = System.currentTimeMillis();
- sCache.getSerializable(key + i);
+ sCache.getSerializable(key + cycleNumber);
long statValue = (System.currentTimeMillis() - startTime);
stats.addValue(statValue);
- logger.debug("The Get stat : " + statValue);
+ log.debug("The Get stat : " + statValue);
}
}
+ catch (Exception e)
+ {
+ // how should we handle this? Log for now...
+ log.error("Operation failed!", e);
+ }
+ }
+ };
+
+ // submit task to be executed
+ executor.execute(r);
+ }
+
+ // only leave once the task queue is empty!!
+ blockTillTasksComplete();
// return the raw data
- logger.debug("Leaving doGets for : " + cache);
+ log.debug("Leaving doGets for : " + cache);
return stats;
}
@@ -84,57 +133,117 @@
* @param sampleSize The size of the cache.
* @return The Descriptive statistics of the cache benchmarking.
*/
- private DescriptiveStatistics doPuts(CacheWrapper cache, Class valueClass, int sampleSize) throws Exception
+ private DescriptiveStatistics doPuts(final CacheWrapper cache, final Class valueClass, int sampleSize) throws Exception
{
- logger.debug("Inside doPuts for " + cache);
- String key = "baseKey";
- Object value = null;
- DescriptiveStatistics stats = DescriptiveStatistics.newInstance();
- boolean useSerializable = cache instanceof SerializableCacheWrapper;
+ log.debug("Inside doPuts for " + cache);
+ final String key = "baseKey";
+ final DescriptiveStatistics stats = DescriptiveStatistics.newInstance();
+ final boolean useSerializable = cache instanceof SerializableCacheWrapper;
+ numberOfBytesPut.set(0);
+ elapsedSecondsForAllPuts = 0;
+ long startElapsedTime = System.currentTimeMillis();
for (int i = 0; i < sampleSize; i++)
{
- // generate some value
- try
+ final int cycleNumber = i;
+ Runnable r = new Runnable()
{
- if (valueClass == null)
- value = null;
- else if (valueClass.getName().equals("java.lang.String"))
- value = "value" + i;
- else if (valueClass.getName().equals("java.lang.Integer"))
- value = new Integer(i);
- else
- value = valueClass.newInstance();
- }
- catch (Exception e)
+ public void run()
{
- logger.error("Problems populating map", e);
- }
+ try
+ {
+ // generate some value
+ Object value;
+ if (valueClass == null) value = null;
+ else if (valueClass.getName().equals("java.lang.String")) value = "value" + cycleNumber;
+ else if (valueClass.getName().equals("java.lang.Integer")) value = cycleNumber;
+ else value = valueClass.newInstance();
+
+ // even though some impls may use special marshalling to reduce the amount of data transmitted (such as JBoss Cache's
+ // CacheMarshaller) we still want to measure the serialized size of objects for this metric.
+
+ numberOfBytesPut.getAndAdd(calculateSerializedSize(value));
if (!useSerializable)
{
// start your timer...
long startTime = System.currentTimeMillis();
- cache.put(key + i, value);
+ cache.put(key + cycleNumber, value);
long statValue = (System.currentTimeMillis() - startTime);
stats.addValue(statValue);
- logger.debug("The Put stat : " + statValue);
+ log.debug("The Put stat : " + statValue);
}
else
{
SerializableCacheWrapper sCache = (SerializableCacheWrapper) cache;
Serializable sValue = (Serializable) value;
long startTime = System.currentTimeMillis();
- sCache.putSerializable(key + i, sValue);
+ sCache.putSerializable(key + cycleNumber, sValue);
long statValue = (System.currentTimeMillis() - startTime);
stats.addValue(statValue);
- logger.debug("The Put stat : " + statValue);
+ log.debug("The Put stat : " + statValue);
}
-
}
+ catch (Exception e)
+ {
+ // how should we handle this? Log for now...
+ log.error("Operation failed!", e);
+ }
+ }
+ };
+ // submit task to be executed
+ executor.execute(r);
+ }
+
+ // only leave once the task queue is empty!!
+ blockTillTasksComplete();
+ elapsedSecondsForAllPuts = (System.currentTimeMillis() - startElapsedTime) / 1000;
// return the raw data
- logger.debug("Leaving doPuts for " + cache);
+ log.debug("Leaving doPuts for " + cache);
return stats;
}
+
+ private void blockTillTasksComplete()
+ {
+ // now that just told us that all the tasks have been submitted. Lets check that the executor has finished everything.
+ executor.shutdown();
+ try
+ {
+ executor.awaitTermination(EXECUTOR_SHUTDOWN_TIMEOUT_SECS, TimeUnit.SECONDS);
+ }
+ catch (InterruptedException e)
+ {
+ // do nothing?
+ }
+ }
+
+ private long calculateSerializedSize(Object value)
+ {
+ ByteArrayOutputStream baos = null;
+ ObjectOutputStream oos = null;
+ try
+ {
+ baos = new ByteArrayOutputStream();
+ oos = new ObjectOutputStream(baos);
+ oos.writeObject(value);
+ oos.close();
+ baos.close();
+ return baos.size();
+ }
+ catch (Exception e)
+ {
+ log.warn("Unable to calculate serialized size of object " + value, e);
+ try
+ {
+ if (oos != null) oos.close();
+ if (baos != null) baos.close();
+ }
+ catch (Exception e2)
+ {
+ log.warn("Unable to close streams", e2);
+ }
+ }
+ return 0;
+ }
}
1.4 +2 -2 CacheBenchFwk/src/org/cachebench/tests/TransientTest.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: TransientTest.java
===================================================================
RCS file: /cvsroot/jboss/CacheBenchFwk/src/org/cachebench/tests/TransientTest.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- TransientTest.java 13 Mar 2007 14:50:46 -0000 1.3
+++ TransientTest.java 18 Apr 2007 19:09:28 -0000 1.4
@@ -17,9 +17,9 @@
/* (non-Javadoc)
* @see org.cachebench.tests.CacheTest#doTest(org.cachebench.config.TestConfig)
*/
- public TestResult doTest(String testName, CacheWrapper cache, String testCaseName, int sampleSize) throws Exception
+ public TestResult doTest(String testName, CacheWrapper cache, String testCaseName, int sampleSize, int numThreads) throws Exception
{
- return performTestWithObjectType(testName, cache, cache instanceof SerializableCacheWrapper ? SerializableCustomTypeWithTransient.class : CustomTypeWithTransient.class, testCaseName, sampleSize);
+ return performTestWithObjectType(testName, cache, cache instanceof SerializableCacheWrapper ? SerializableCustomTypeWithTransient.class : CustomTypeWithTransient.class, testCaseName, sampleSize, numThreads);
}
1.4 +2 -2 CacheBenchFwk/src/org/cachebench/tests/AssociationsTest.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: AssociationsTest.java
===================================================================
RCS file: /cvsroot/jboss/CacheBenchFwk/src/org/cachebench/tests/AssociationsTest.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- AssociationsTest.java 13 Mar 2007 14:50:46 -0000 1.3
+++ AssociationsTest.java 18 Apr 2007 19:09:28 -0000 1.4
@@ -17,9 +17,9 @@
/* (non-Javadoc)
* @see org.cachebench.tests.CacheTest#doTest(org.cachebench.config.TestConfig)
*/
- public TestResult doTest(String testName, CacheWrapper cache, String testCaseName, int sampleSize) throws Exception
+ public TestResult doTest(String testName, CacheWrapper cache, String testCaseName, int sampleSize, int numThreads) throws Exception
{
- return performTestWithObjectType(testName, cache, cache instanceof SerializableCacheWrapper ? SerializableCustomTypeWithAssocs.class : CustomTypeWithAssocs.class, testCaseName, sampleSize);
+ return performTestWithObjectType(testName, cache, cache instanceof SerializableCacheWrapper ? SerializableCustomTypeWithAssocs.class : CustomTypeWithAssocs.class, testCaseName, sampleSize, numThreads);
}
1.4 +2 -2 CacheBenchFwk/src/org/cachebench/tests/SubclassTest.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: SubclassTest.java
===================================================================
RCS file: /cvsroot/jboss/CacheBenchFwk/src/org/cachebench/tests/SubclassTest.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- SubclassTest.java 13 Mar 2007 14:50:46 -0000 1.3
+++ SubclassTest.java 18 Apr 2007 19:09:28 -0000 1.4
@@ -17,9 +17,9 @@
/* (non-Javadoc)
* @see org.cachebench.tests.CacheTest#doTest(org.cachebench.config.TestConfig)
*/
- public TestResult doTest(String testName, CacheWrapper cache, String testCaseName, int sampleSize) throws Exception
+ public TestResult doTest(String testName, CacheWrapper cache, String testCaseName, int sampleSize, int numThreads) throws Exception
{
- return performTestWithObjectType(testName, cache, cache instanceof SerializableCacheWrapper ? SerializableCustomTypeSubclassOfAbstract.class : CustomTypeSubclassOfAbstract.class, testCaseName, sampleSize);
+ return performTestWithObjectType(testName, cache, cache instanceof SerializableCacheWrapper ? SerializableCustomTypeSubclassOfAbstract.class : CustomTypeSubclassOfAbstract.class, testCaseName, sampleSize, numThreads);
}
1.4 +2 -2 CacheBenchFwk/src/org/cachebench/tests/PrimitiveTest.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: PrimitiveTest.java
===================================================================
RCS file: /cvsroot/jboss/CacheBenchFwk/src/org/cachebench/tests/PrimitiveTest.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- PrimitiveTest.java 13 Mar 2007 14:50:46 -0000 1.3
+++ PrimitiveTest.java 18 Apr 2007 19:09:28 -0000 1.4
@@ -14,9 +14,9 @@
/* (non-Javadoc)
* @see org.cachebench.tests.CacheTest#doTest(org.cachebench.config.TestConfig)
*/
- public TestResult doTest(String testName, CacheWrapper cache, String testCaseName, int sampleSize) throws Exception
+ public TestResult doTest(String testName, CacheWrapper cache, String testCaseName, int sampleSize, int numThreads) throws Exception
{
- return performTestWithObjectType(testName, cache, Integer.class, testCaseName, sampleSize);
+ return performTestWithObjectType(testName, cache, Integer.class, testCaseName, sampleSize, numThreads);
}
1.4 +2 -2 CacheBenchFwk/src/org/cachebench/tests/StaticsTest.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: StaticsTest.java
===================================================================
RCS file: /cvsroot/jboss/CacheBenchFwk/src/org/cachebench/tests/StaticsTest.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- StaticsTest.java 13 Mar 2007 14:50:46 -0000 1.3
+++ StaticsTest.java 18 Apr 2007 19:09:28 -0000 1.4
@@ -17,9 +17,9 @@
/* (non-Javadoc)
* @see org.cachebench.tests.CacheTest#doTest(org.cachebench.config.TestConfig)
*/
- public TestResult doTest(String testName, CacheWrapper cache, String testCaseName, int sampleSize) throws Exception
+ public TestResult doTest(String testName, CacheWrapper cache, String testCaseName, int sampleSize, int numThreads) throws Exception
{
- return performTestWithObjectType(testName, cache, cache instanceof SerializableCacheWrapper ? SerializableCustomTypeWithStatics.class : CustomTypeWithStatics.class, testCaseName, sampleSize);
+ return performTestWithObjectType(testName, cache, cache instanceof SerializableCacheWrapper ? SerializableCustomTypeWithStatics.class : CustomTypeWithStatics.class, testCaseName, sampleSize, numThreads);
}
}
1.4 +2 -2 CacheBenchFwk/src/org/cachebench/tests/CustomClassTest.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: CustomClassTest.java
===================================================================
RCS file: /cvsroot/jboss/CacheBenchFwk/src/org/cachebench/tests/CustomClassTest.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- CustomClassTest.java 13 Mar 2007 14:50:46 -0000 1.3
+++ CustomClassTest.java 18 Apr 2007 19:09:28 -0000 1.4
@@ -17,9 +17,9 @@
/* (non-Javadoc)
* @see org.cachebench.tests.CacheTest#doTest(org.cachebench.config.TestConfig)
*/
- public TestResult doTest(String testName, CacheWrapper cache, String testCaseName, int sampleSize) throws Exception
+ public TestResult doTest(String testName, CacheWrapper cache, String testCaseName, int sampleSize, int numThreads) throws Exception
{
- return performTestWithObjectType(testName, cache, cache instanceof SerializableCacheWrapper ? SerializableCustomType.class : CustomType.class, testCaseName, sampleSize);
+ return performTestWithObjectType(testName, cache, cache instanceof SerializableCacheWrapper ? SerializableCustomType.class : CustomType.class, testCaseName, sampleSize, numThreads);
}
More information about the jboss-cvs-commits
mailing list