Author: arminw
Date: Tue Oct 31 08:58:19 2006
New Revision: 469555
URL: http://svn.apache.org/viewvc?view=rev&rev=469555
Log:
improve performance tool
Modified:
db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/performance/PerfMain.java
db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/performance/PerfRunner.java
Modified: db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/performance/PerfMain.java
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/performance/PerfMain.java?view=diff&rev=469555&r1=469554&r2=469555
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/performance/PerfMain.java (original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/performance/PerfMain.java Tue Oct 31 08:58:19 2006
@@ -228,10 +228,16 @@
EOL + "---------------------------------------------------");
PerfRunner test;
- ThreadGroup threadGroup = new ThreadGroup("PerfTest_Group_id=" + Math.random());
+ Runtime rt = Runtime.getRuntime();
+ ThreadGroup threadGroup = new ThreadGroup("PerfTest_Group_id=" + StrictMath.random());
+ // warmup O/R mapper
+ prepareForTests(threadGroup, testList);
+ rt.gc();
+ Thread.sleep(200);
+ rt.gc();
+ Thread.sleep(200);
for (int i = 0; i < testLoops; i++)
{
- Runtime rt = Runtime.getRuntime();
long freeMem;
if(logAll) printer().println(" Loop " + (i + 1));
@@ -239,18 +245,18 @@
{
String perfTest = (String) testList.get(j);
Class testHandle = Class.forName(perfTest);
- test = new PerfRunner(threadGroup, testHandle);
- test.registerPerfMain(this);
+ test = new PerfRunner(this, threadGroup, testHandle);
rt.gc();
- Thread.sleep(300);
+ Thread.sleep(80);
rt.freeMemory();
rt.gc();
- Thread.sleep(100);
+ Thread.sleep(80);
freeMem = rt.freeMemory();
+ Thread.sleep(20);
test.performTest();
freeMem = (freeMem - rt.freeMemory()) / 1024;
- if(logAll) printer().println(" allocated memory=" + freeMem + "kb");
+ if(logAll) printer().println(" memory=" + freeMem + "kb");
// rt.gc();
}
ArrayList tmpList = new ArrayList(testList);
@@ -275,6 +281,22 @@
}
}
+ private void prepareForTests(ThreadGroup threadGroup, List testList) throws Exception
+ {
+ PerfMain.printer().println("## Test warmup start");
+ for(int j = 0; j < testList.size(); j++)
+ {
+ String perfTest = (String) testList.get(j);
+ Class testHandle = Class.forName(perfTest);
+ PerfRunner test = new PerfRunner(this, threadGroup, testHandle);
+ Thread.sleep(300);
+ test.performTest();
+ PerfMain.printer().println("");
+ }
+ PerfMain.printer().println("## Test warmup end");
+ resultMap.clear();
+ }
+
public void printResult()
{
printer().println();
@@ -290,12 +312,12 @@
{
PerfResult r1 = (PerfResult) o1;
PerfResult r2 = (PerfResult) o2;
- return new Long(r1.getTotalTime()).compareTo(new Long(r2.getTotalTime()));
+ return new Double(r1.getTotalTime()).compareTo(new Double(r2.getTotalTime()));
}
});
PerfResult[] results = (PerfResult[]) tmp.toArray(new PerfResult[tmp.size()]);
- long[][] calibration = new long[6][results.length];
+ double[][] calibration = new double[6][results.length];
for(int k = 0; k < 6; k++)
{
for(int i = 0; i < results.length; i++)
@@ -314,8 +336,8 @@
{
if(k==TEST_INSERT)
{
- long[] resultArray = calibration[TEST_INSERT];
- long minimum = NumberUtils.min(resultArray);
+ double[] resultArray = calibration[TEST_INSERT];
+ double minimum = NumberUtils.min(resultArray);
for(int i = 0; i < results.length; i++)
{
results[i].setInsertMinimun(minimum);
@@ -323,8 +345,8 @@
}
if(k==TEST_FETCH)
{
- long[] resultArray = calibration[TEST_FETCH];
- long minimum = NumberUtils.min(resultArray);
+ double[] resultArray = calibration[TEST_FETCH];
+ double minimum = NumberUtils.min(resultArray);
for(int i = 0; i < results.length; i++)
{
results[i].setFetchMinimun(minimum);
@@ -332,8 +354,8 @@
}
if(k==TEST_FETCH_2)
{
- long[] resultArray = calibration[TEST_FETCH_2];
- long minimum = NumberUtils.min(resultArray);
+ double[] resultArray = calibration[TEST_FETCH_2];
+ double minimum = NumberUtils.min(resultArray);
for(int i = 0; i < results.length; i++)
{
results[i].setFetchSecondMinimun(minimum);
@@ -341,8 +363,8 @@
}
if(k==TEST_BY_IDENTITY)
{
- long[] resultArray = calibration[TEST_BY_IDENTITY];
- long minimum = NumberUtils.min(resultArray);
+ double[] resultArray = calibration[TEST_BY_IDENTITY];
+ double minimum = NumberUtils.min(resultArray);
for(int i = 0; i < results.length; i++)
{
results[i].setByIdentityMinimun(minimum);
@@ -350,8 +372,8 @@
}
if(k==TEST_UPDATE)
{
- long[] resultArray = calibration[TEST_UPDATE];
- long minimum = NumberUtils.min(resultArray);
+ double[] resultArray = calibration[TEST_UPDATE];
+ double minimum = NumberUtils.min(resultArray);
for(int i = 0; i < results.length; i++)
{
results[i].setUpdateMinimun(minimum);
@@ -359,8 +381,8 @@
}
if(k==TEST_DELETE)
{
- long[] resultArray = calibration[TEST_DELETE];
- long minimum = NumberUtils.min(resultArray);
+ double[] resultArray = calibration[TEST_DELETE];
+ double minimum = NumberUtils.min(resultArray);
for(int i = 0; i < results.length; i++)
{
results[i].setDeleteMinimun(minimum);
@@ -468,9 +490,7 @@
// the first one is the fastest
calibrationMark = result.getTotalTime();
}
- //double period = (double) result.getTestPeriod() / 1000;
- //double total = (double) Math.round((double) result.getTotalTime()) / 1000;
- long percent = Math.round((result.getTotalTime() / calibrationMark) * 100);
+ long percent = smartPercent(printer(), result.getTotalTime(), calibrationMark);
buf.append(alignLeft(result.getTestName(), columnLength));
//buf.append(alignLeft(""+period, columnLength, " "));
@@ -556,7 +576,7 @@
* testTimes[5] updating times
* testTimes[6] deleting times
*/
- public synchronized void addPeriodResult(String testName, long[] resultArr, boolean isValid)
+ public synchronized void addPeriodResult(String testName, double[] resultArr, boolean isValid)
{
PerfResult result = (PerfResult) resultMap.get(testName);
if (result == null)
@@ -583,13 +603,13 @@
{
StringBuffer buf = new StringBuffer();
buf.append(" Test '").append(result.getTestName()).append("' [ms]")
- .append(": testPeriod=").append(resultArr[TIME_TOTAL]/getConcurrentThreads())
- .append(" insert=").append(resultArr[TIME_INSERT]/getConcurrentThreads())
- .append(" read=").append(resultArr[TIME_FETCH]/getConcurrentThreads())
- .append(" read2=").append(resultArr[TIME_FETCH_2]/getConcurrentThreads())
- .append(" byIdentity=").append(resultArr[TIME_BY_IDENTITY]/getConcurrentThreads())
- .append(" update=").append(resultArr[TIME_UPDATE]/getConcurrentThreads())
- .append(" delete=").append(resultArr[TIME_DELETE]/getConcurrentThreads());
+ .append(": testPeriod=").append(smartRounding(resultArr[TIME_TOTAL]/getConcurrentThreads()))
+ .append(" insert=").append(smartRounding(resultArr[TIME_INSERT]/getConcurrentThreads()))
+ .append(" read=").append(smartRounding(resultArr[TIME_FETCH]/getConcurrentThreads()))
+ .append(" read2=").append(smartRounding(resultArr[TIME_FETCH_2]/getConcurrentThreads()))
+ .append(" byIdentity=").append(smartRounding(resultArr[TIME_BY_IDENTITY]/getConcurrentThreads()))
+ .append(" update=").append(smartRounding(resultArr[TIME_UPDATE]/getConcurrentThreads()))
+ .append(" delete=").append(smartRounding(resultArr[TIME_DELETE]/getConcurrentThreads()));
printer().print(buf.toString());
}
else
@@ -669,6 +689,41 @@
}
}
+ static String smartRounding(double value)
+ {
+ String result;
+
+ if(value < 1.0d)
+ {
+ result = "" + StrictMath.round((value * 100d)) / 100d;
+ }
+ else if(value > 10.0d)
+ {
+ result = "" + StrictMath.round(value);
+ }
+ else
+ {
+ result = "" + StrictMath.round((value * 10d)) / 10d;
+ }
+ //System.out.println("before: " + value + ", after: " +result);
+ return result;
+ }
+
+ static long smartPercent(Printer printer, double value, double calibration)
+ {
+ if(value <= 0)
+ {
+ if(printer != null)
+ {
+ printer.println();
+ printer.println("## Unexact percent result generated, give value was <=0 --> use approximated value 0.5 to fix ##");
+ printer.println();
+ }
+ value = 0.5d;
+ }
+ return Math.round((value / calibration) * 100);
+ }
+
//================================================================
// inner class
@@ -676,25 +731,25 @@
static class PerfResult
{
private String testName;
- private long testPeriod;
+ private double testPeriod;
private boolean stressMode;
private int testLoops;
private int numberOfThreads;
private int iterationsPerThread;
- private long insertPeriod;
- private long insertMinimun;
- private long fetchPeriod;
- private long fetchMinimun;
- private long fetchSecondPeriod;
- private long fetchSecondMinimun;
- private long byIdentityPeriod;
- private long byIdentityMinimun;
- private long updatePeriod;
- private long updateMinimun;
- private long deletePeriod;
- private long deleteMinimun;
+ private double insertPeriod;
+ private double insertMinimun;
+ private double fetchPeriod;
+ private double fetchMinimun;
+ private double fetchSecondPeriod;
+ private double fetchSecondMinimun;
+ private double byIdentityPeriod;
+ private double byIdentityMinimun;
+ private double updatePeriod;
+ private double updateMinimun;
+ private double deletePeriod;
+ private double deleteMinimun;
private boolean valid;
@@ -762,12 +817,12 @@
this.testName = testName;
}
- public long getTestPeriod()
+ public double getTestPeriod()
{
return testPeriod;
}
- public synchronized void addTestPeriod(long aTestPeriod)
+ public synchronized void addTestPeriod(double aTestPeriod)
{
this.testPeriod += aTestPeriod;
}
@@ -802,179 +857,189 @@
this.iterationsPerThread = numberOfObjects;
}
- public long getTotalTime()
+ public double getTotalTime()
{
- long result = ((insertPeriod + fetchPeriod + fetchSecondPeriod + byIdentityPeriod + updatePeriod + deletePeriod) / getTestLoops()) / getNumberOfThreads();
+ double result = ((insertPeriod + fetchPeriod + fetchSecondPeriod + byIdentityPeriod + updatePeriod + deletePeriod) / getTestLoops()) / getNumberOfThreads();
return result > 0 ? result : 1;
}
- public long getInsertPeriod()
+ public double getInsertPeriod()
{
return (insertPeriod / getTestLoops()) / getNumberOfThreads();
}
- public synchronized void addInsertPeriod(long anInsertPeriod)
+ public synchronized void addInsertPeriod(double anInsertPeriod)
{
this.insertPeriod += anInsertPeriod;
}
- public long getFetchPeriod()
+ public double getFetchPeriod()
{
return (fetchPeriod / getTestLoops()) / getNumberOfThreads();
}
- public synchronized void addFetchPeriod(long aFetchPeriod)
+ public synchronized void addFetchPeriod(double aFetchPeriod)
{
this.fetchPeriod += aFetchPeriod;
}
- public long getFetchSecondPeriod()
+ public double getFetchSecondPeriod()
{
return (fetchSecondPeriod / getTestLoops()) / getNumberOfThreads();
}
- public synchronized void addFetchSecondPeriod(long secondPeriod)
+ public synchronized void addFetchSecondPeriod(double secondPeriod)
{
this.fetchSecondPeriod += secondPeriod;
}
- public long getByIdentityPeriod()
+ public double getByIdentityPeriod()
{
return (byIdentityPeriod / getTestLoops()) / getNumberOfThreads();
}
- public synchronized void addByIdentityPeriod(long byIdentityPeriod)
+ public synchronized void addByIdentityPeriod(double byIdentityPeriod)
{
this.byIdentityPeriod += byIdentityPeriod;
}
- public long getUpdatePeriod()
+ public double getUpdatePeriod()
{
return (updatePeriod / getTestLoops()) / getNumberOfThreads();
}
- public synchronized void addUpdatePeriod(long aUpdatePeriod)
+ public synchronized void addUpdatePeriod(double aUpdatePeriod)
{
this.updatePeriod += aUpdatePeriod;
}
- public long getDeletePeriod()
+ public double getDeletePeriod()
{
return (deletePeriod / getTestLoops()) / getNumberOfThreads();
}
- public synchronized void addDeletePeriod(long aDeletePeriod)
+ public synchronized void addDeletePeriod(double aDeletePeriod)
{
this.deletePeriod += aDeletePeriod;
}
- public void setInsertMinimun(long insertMinimun)
+ public void setInsertMinimun(double insertMinimun)
{
- this.insertMinimun = insertMinimun > 1 ? insertMinimun : 1;
+ if(insertMinimun <= 0)
+ {
+ throw new RuntimeException("Can't handle test run duration <0, value=" + insertMinimun);
+ }
+ this.insertMinimun = insertMinimun;
}
- public void setFetchMinimun(long fetchMinimun)
+ public void setFetchMinimun(double fetchMinimun)
{
- this.fetchMinimun = fetchMinimun > 1 ? fetchMinimun : 1;
+ if(fetchMinimun <= 0)
+ {
+ throw new RuntimeException("Can't handle test run duration <0, value=" + fetchMinimun);
+ }
+ this.fetchMinimun = fetchMinimun;
}
- public void setFetchSecondMinimun(long fetchSecondMinimun)
+ public void setFetchSecondMinimun(double fetchSecondMinimun)
{
- this.fetchSecondMinimun = fetchSecondMinimun > 1 ? fetchSecondMinimun : 1;
+ if(fetchSecondMinimun <= 0)
+ {
+ throw new RuntimeException("Can't handle test run duration <0, value=" + fetchSecondMinimun);
+ }
+ this.fetchSecondMinimun = fetchSecondMinimun;
}
- public void setByIdentityMinimun(long byIdentityMinimun)
+ public void setByIdentityMinimun(double byIdentityMinimun)
{
- this.byIdentityMinimun = byIdentityMinimun > 1 ? byIdentityMinimun : 1;
+ if(byIdentityMinimun <= 0)
+ {
+ throw new RuntimeException("Can't handle test run duration <0, value=" + byIdentityMinimun);
+ }
+ this.byIdentityMinimun = byIdentityMinimun;
}
- public void setUpdateMinimun(long updateMinimun)
+ public void setUpdateMinimun(double updateMinimun)
{
- this.updateMinimun = updateMinimun > 1 ? updateMinimun : 1;
+ if(updateMinimun <= 0)
+ {
+ throw new RuntimeException("Can't handle test run duration <0, value=" + updateMinimun);
+ }
+ this.updateMinimun = updateMinimun;
}
- public void setDeleteMinimun(long deleteMinimun)
+ public void setDeleteMinimun(double deleteMinimun)
{
- this.deleteMinimun = deleteMinimun > 1 ? deleteMinimun : 1;
+ if(deleteMinimun <= 0)
+ {
+ throw new RuntimeException("Can't handle test run duration <0, value=" + deleteMinimun);
+ }
+ this.deleteMinimun = deleteMinimun;
}
public String getInsertResult()
{
- long result = getInsertPeriod();
- return "" + result;
+ return "" + smartRounding(getInsertPeriod());
}
public String getFetchResult()
{
- long result = getFetchPeriod();
- return "" + result;
+ return "" + smartRounding(getFetchPeriod());
}
public String getFetchSecondResult()
{
- long result = getFetchSecondPeriod();
- return "" + result;
+ return "" + smartRounding(getFetchSecondPeriod());
}
public String getByIdentityResult()
{
- long result = getByIdentityPeriod();
- return "" + result;
+ return "" + smartRounding(getByIdentityPeriod());
}
public String getUpdateResult()
{
- long result = getUpdatePeriod();
- return "" + result;
+ return "" + smartRounding(getUpdatePeriod());
}
public String getDeleteResult()
{
- long result = getDeletePeriod();
- return "" + result;
+ return "" + smartRounding(getDeletePeriod());
}
-
-
public String getInsertResultPercent()
{
- long result = getInsertPeriod();
- return "(" + (int) ((result * 100)/insertMinimun) + "%)";
+ return "(" + smartPercent(null, getInsertPeriod(), insertMinimun) + "%)";
}
public String getFetchResultPercent()
{
- long result = getFetchPeriod();
- return "(" + (int) ((result * 100)/fetchMinimun) + "%)";
+ return "(" + smartPercent(null, getFetchPeriod(), fetchMinimun) + "%)";
}
public String getFetchSecondResultPercent()
{
- long result = getFetchSecondPeriod();
- return "(" + (int) ((result * 100)/fetchSecondMinimun) + "%)";
+ return "(" + smartPercent(null, getFetchSecondPeriod(), fetchSecondMinimun) + "%)";
}
public String getByIdentityResultPercent()
{
- long result = getByIdentityPeriod();
- return "(" + (int) ((result * 100)/byIdentityMinimun) + "%)";
+ return "(" + smartPercent(null, getByIdentityPeriod(), byIdentityMinimun) + "%)";
}
public String getUpdateResultPercent()
{
- long result = getUpdatePeriod();
- return "(" + (int) ((result * 100)/updateMinimun) + "%)";
+ return "(" + smartPercent(null, getUpdatePeriod(), updateMinimun) + "%)";
}
public String getDeleteResultPercent()
{
- long result = getDeletePeriod();
- return "(" + (int) ((result * 100)/deleteMinimun) + "%)";
+ return "(" + smartPercent(null, getDeletePeriod(), deleteMinimun) + "%)";
}
}
Modified: db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/performance/PerfRunner.java
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/performance/PerfRunner.java?view=diff&rev=469555&r1=469554&r2=469555
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/performance/PerfRunner.java (original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/performance/PerfRunner.java Tue Oct 31 08:58:19 2006
@@ -34,7 +34,7 @@
* testTimes[5] updating times
* testTimes[6] deleting times
*/
- private long[] testTimes;
+ private double[] testTimes;
private ThreadGroup threadGroup;
private PerfMain perfMain;
private long perfTestId;
@@ -48,9 +48,9 @@
private Class testClass;
private PerfTest test;
-
- public PerfRunner(ThreadGroup group, Class perfTestClass)
+ public PerfRunner(PerfMain perfMain, ThreadGroup group, Class perfTestClass)
{
+ this.perfMain = perfMain;
this.perfTestId = System.currentTimeMillis();
this.checked = false;
this.testClass = perfTestClass;
@@ -158,7 +158,7 @@
int objectCount;
int objectCountAfter;
- testTimes = new long[7];
+ testTimes = new double[7];
objectCount = test.articleCount();
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.