db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From arm...@apache.org
Subject cvs commit: db-ojb/src/test/org/apache/ojb/performance PerfHandle.java PerfMain.java PerfTest.java
Date Thu, 15 Dec 2005 02:10:57 GMT
arminw      2005/12/14 18:10:57

  Modified:    src/test/org/apache/ojb/compare Tag: OJB_1_0_RELEASE
                        OJBPerfTest.java
               src/test/org/apache/ojb/performance Tag: OJB_1_0_RELEASE
                        PerfHandle.java PerfMain.java PerfTest.java
  Log:
  fix bug, make tests more fair
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.1.2.3   +22 -9     db-ojb/src/test/org/apache/ojb/compare/OJBPerfTest.java
  
  Index: OJBPerfTest.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/compare/OJBPerfTest.java,v
  retrieving revision 1.1.2.2
  retrieving revision 1.1.2.3
  diff -u -r1.1.2.2 -r1.1.2.3
  --- OJBPerfTest.java	10 Oct 2005 00:35:43 -0000	1.1.2.2
  +++ OJBPerfTest.java	15 Dec 2005 02:10:57 -0000	1.1.2.3
  @@ -110,8 +110,14 @@
       public static class JdbcPerfHandle extends PerfHandle
       {
           private static final String TABLE_NAME = "PERF_ARTICLE";
  +        // cast to int to avoid problems with DB field length
  +        public static volatile int counter = (int) System.currentTimeMillis();
           private PersistenceBroker broker;
   
  +        public synchronized static Long nextKey()
  +        {
  +            return new Long(++counter);
  +        }
   
           public JdbcPerfHandle(PerfTest test)
           {
  @@ -140,14 +146,17 @@
               buf.append("INSERT INTO ").append(TABLE_NAME);
               buf.append(" (ARTICLE_ID, ARTICLE_NAME, MINIMUM_STOCK, PRICE, UNIT, STOCK,
SUPPLIER_ID)");
               buf.append(" VALUES (?,?,?,?,?,?,?)");
  +            // lookup the connection (using OJB's con pooling support to make the test
more fair)
               Connection con = getConnection();
               con.setAutoCommit(false);
  -            PreparedStatement stmt = con.prepareStatement(buf.toString());
               for (int i = 0; i < arr.length; i++)
               {
  +                // OJB doesn't use a PS-pool (normally the JDBC driver supports statement
pooling)
  +                // thus to make this test more fair lookup a new PS for each object
  +                PreparedStatement stmt = con.prepareStatement(buf.toString());
                   PerfArticle article = arr[i];
  -                // use Identity to set pk field value
  -                Identity oid = broker.serviceIdentity().buildIdentity(article);
  +                // generate PK value
  +                article.setArticleId(nextKey());
                   stmt.setLong(1, article.getArticleId().longValue());
                   stmt.setString(2, article.getArticleName());
                   stmt.setInt(3, article.getMinimumStock());
  @@ -156,10 +165,10 @@
                   stmt.setInt(6, article.getStock());
                   stmt.setInt(7, article.getSupplierId());
                   stmt.executeUpdate();
  +                stmt.close();
               }
               con.commit();
               con.setAutoCommit(true);
  -            stmt.close();
               releaseConnection();
           }
   
  @@ -202,9 +211,11 @@
               buf.append(" WHERE ARTICLE_ID = ?");
               Connection con = getConnection();
               con.setAutoCommit(false);
  -            PreparedStatement stmt = con.prepareStatement(buf.toString());
               for (int i = 0; i < arr.length; i++)
               {
  +                // OJB doesn't use a PS-pool (normally the JDBC driver supports statement
pooling)
  +                // thus to make this test more fair lookup a new PS for each object
  +                PreparedStatement stmt = con.prepareStatement(buf.toString());
                   PerfArticle article = arr[i];
                   stmt.setString(1, article.getArticleName());
                   stmt.setInt(2, article.getMinimumStock());
  @@ -214,10 +225,10 @@
                   stmt.setInt(6, article.getSupplierId());
                   stmt.setLong(7, article.getArticleId().longValue());
                   stmt.executeUpdate();
  +                stmt.close();
               }
               con.commit();
               con.setAutoCommit(true);
  -            stmt.close();
               releaseConnection();
           }
   
  @@ -231,16 +242,18 @@
               String sql = "DELETE FROM " + TABLE_NAME + " WHERE ARTICLE_ID = ?";
               Connection con = getConnection();
               con.setAutoCommit(false);
  -            PreparedStatement stmt = con.prepareStatement(sql);
               for (int i = 0; i < arr.length; i++)
               {
  +                // OJB doesn't use a PS-pool (normally the JDBC driver supports statement
pooling)
  +                // thus to make this test more fair lookup a new PS for each object
  +                PreparedStatement stmt = con.prepareStatement(sql);
                   PerfArticle article = arr[i];
                   stmt.setLong(1, article.getArticleId().longValue());
                   stmt.execute();
  +                stmt.close();
               }
               con.commit();
               con.setAutoCommit(true);
  -            stmt.close();
               releaseConnection();
           }
   
  
  
  
  No                   revision
  No                   revision
  1.11.2.3  +8 -8      db-ojb/src/test/org/apache/ojb/performance/PerfHandle.java
  
  Index: PerfHandle.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/performance/PerfHandle.java,v
  retrieving revision 1.11.2.2
  retrieving revision 1.11.2.3
  diff -u -r1.11.2.2 -r1.11.2.3
  --- PerfHandle.java	2 Sep 2005 13:27:03 -0000	1.11.2.2
  +++ PerfHandle.java	15 Dec 2005 02:10:57 -0000	1.11.2.3
  @@ -163,14 +163,14 @@
                   period = System.currentTimeMillis();
                   insertNewArticlesStress(m_arr);
                   period = System.currentTimeMillis() - period;
  -                test.addTime(1, period);
  +                test.addTime(PerfTest.INSERT, period);
               }
               else
               {
                   period = System.currentTimeMillis();
                   insertNewArticles(m_arr);
                   period = System.currentTimeMillis() - period;
  -                test.addTime(1, period);
  +                test.addTime(PerfTest.INSERT, period);
               }
   
               // read objects
  @@ -186,7 +186,7 @@
                   test.registerException(PREFIX_LOG
                           + "(Something wrong with query result or with object insert operation)
", e);
               }
  -            test.addTime(2, period);
  +            test.addTime(PerfTest.FETCH, period);
   
               // update objects
               modifyPerfArticle(m_arr);
  @@ -195,14 +195,14 @@
                   period = System.currentTimeMillis();
                   updateArticlesStress(m_arr);
                   period = System.currentTimeMillis() - period;
  -                test.addTime(3, period);
  +                test.addTime(PerfTest.UPDATE, period);
               }
               else
               {
                   period = System.currentTimeMillis();
                   updateArticles(m_arr);
                   period = System.currentTimeMillis() - period;
  -                test.addTime(3, period);
  +                test.addTime(PerfTest.UPDATE, period);
               }
   
               // delete objects
  @@ -211,14 +211,14 @@
                   period = System.currentTimeMillis();
                   deleteArticlesStress(m_arr);
                   period = System.currentTimeMillis() - period;
  -                test.addTime(4, period);
  +                test.addTime(PerfTest.DELETE, period);
               }
               else
               {
                   period = System.currentTimeMillis();
                   deleteArticles(m_arr);
                   period = System.currentTimeMillis() - period;
  -                test.addTime(4, period);
  +                test.addTime(PerfTest.DELETE, period);
               }
   
               tearDown();
  
  
  
  1.9.2.4   +64 -58    db-ojb/src/test/org/apache/ojb/performance/PerfMain.java
  
  Index: PerfMain.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/performance/PerfMain.java,v
  retrieving revision 1.9.2.3
  retrieving revision 1.9.2.4
  diff -u -r1.9.2.3 -r1.9.2.4
  --- PerfMain.java	16 Aug 2005 15:11:33 -0000	1.9.2.3
  +++ PerfMain.java	15 Dec 2005 02:10:57 -0000	1.9.2.4
  @@ -79,21 +79,13 @@
   {
       protected static final String EOL = System.getProperty("line.separator");
   
  -    /**
  -     * iterations per thread
  -     */
  +    /** iterations per thread */
       private static int iterationsPerThread = 500;
  -    /**
  -     * number of concurrent threads
  -     */
  +    /** number of concurrent threads */
       private static int concurrentThreads = 10;
  -    /**
  -     * if false we use performance optimized delete/insert method
  -     */
  +    /** if false we use performance optimized delete/insert method */
       private static boolean useStressMode = false;
  -    /**
  -     * number of test loops
  -     */
  +    /** number of test loops */
       private static int testLoops = 1;
   
       private HashMap resultMap;
  @@ -127,9 +119,7 @@
           this.exceptionMap = new Hashtable();
       }
   
  -    /**
  -     * Call this to begin the performance test.
  -     */
  +    /** Call this to begin the performance test. */
       public void startPerfTest(String[] args) throws Exception
       {
           ArrayList testList = null;
  @@ -190,11 +180,11 @@
                   EOL + "# Start OJB performance-test framework - do " + testLoops + " loop
#" +
                   EOL + "####################################################" + EOL);
   
  -        PerfTest test = null;
  +        PerfTest test;
           for (int i = 0; i < testLoops; i++)
           {
               Runtime rt = Runtime.getRuntime();
  -            long freeMem = 0;
  +            long freeMem;
               System.out.println("==> perform test loop " + (i + 1));
   
               if(i%2 == 0)
  @@ -267,12 +257,15 @@
           if (!getExceptionMap().isEmpty())
           {
               StringBuffer buf = new StringBuffer();
  -            buf.append(EOL + "Failures occured, test not valid:" + EOL);
  +            buf.append(EOL).append("Failures occured, test not valid:").append(EOL);
               Iterator it = getExceptionMap().keySet().iterator();
               while (it.hasNext())
               {
                   String causer = (String) it.next();
  -                buf.append("Failure cause by " + causer + ", exception was " + exceptionMap.get(causer)
+ EOL);
  +                buf.append("Failure cause by ")
  +                        .append(causer).append(", exception was ")
  +                        .append(exceptionMap.get(causer))
  +                        .append(EOL);
               }
               print.println(buf.toString());
           }
  @@ -306,12 +299,14 @@
           buf.append(getFilledUpToLength("OJB PERFORMANCE TEST SUMMARY", columnLength, "
"));
           buf.append(EOL);
   
  -        buf.append(PerfMain.getConcurrentThreads() + " concurrent threads, handle " +
  -                PerfMain.getIterationsPerThread() + " objects per thread");
  +        buf.append(PerfMain.getConcurrentThreads());
  +        buf.append(" concurrent threads, handle ");
  +        buf.append(PerfMain.getIterationsPerThread());
  +        buf.append(" objects per thread");
           buf.append(EOL);
           buf.append(getFilledUpToLength("", columnLength, " "));
  -        buf.append("- " + (isUseStressMode() == false ? "performance mode" : "stress mode"));
  -        buf.append(" - results per thread");
  +        buf.append("- ").append(!(isUseStressMode()) ? "performance mode" : "stress mode");
  +        buf.append(" - results per thread (av)");
           buf.append(EOL);
           for (int i = 0; i < columnNumbers; i++)
           {
  @@ -341,7 +336,7 @@
               buf.append(getFilledUpToLength("", columnLength, "-"));
           }
   
  -        List failures = new ArrayList();
  +//        List failures = new ArrayList();
           // fill table
           Iterator it = results.iterator();
           int counter = 0;
  @@ -356,17 +351,21 @@
   //            }
               if(counter == 0)
               {
  -                calibrationMark = (((double) res.getTotalTime()) / 1000);
  +                // the first one is the fastest
  +                calibrationMark = res.getTotalTime();
               }
  +            double period = (double) res.getTestPeriod() / 1000;
  +            double total = (double) Math.round((double) res.getTotalTime()) / 1000;
  +            long percent = Math.round((res.getTotalTime() / calibrationMark) * 100);
  +
               buf.append(getFilledUpToLength(res.getTestName(), columnLength, " "));
  -            buf.append(getFilledUpToLength(new Double((((double) res.getTestPeriod()) /
1000)).toString(), columnLength, " "));
  -            Double totalTime = new Double((((double) res.getTotalTime()) / 1000));
  -            buf.append(getFilledUpToLength(totalTime.toString(), columnLength, " "));
  -            buf.append(getFilledUpToLength(new Long(Math.round((totalTime.doubleValue()
/ calibrationMark) * 100)).toString(), columnLength, " "));
  -            buf.append(getFilledUpToLength(new Long(res.getInsertPeriod()).toString(),
columnLength, " "));
  -            buf.append(getFilledUpToLength(new Long(res.getFetchPeriod()).toString(), columnLength,
" "));
  -            buf.append(getFilledUpToLength(new Long(res.getUpdatePeriod()).toString(),
columnLength, " "));
  -            buf.append(getFilledUpToLength(new Long(res.getDeletePeriod()).toString(),
columnLength, " "));
  +            buf.append(getFilledUpToLength(""+period, columnLength, " "));
  +            buf.append(getFilledUpToLength(""+total, columnLength, " "));
  +            buf.append(getFilledUpToLength(""+percent, columnLength, " "));
  +            buf.append(getFilledUpToLength(Long.toString(res.getInsertPeriod()), columnLength,
" "));
  +            buf.append(getFilledUpToLength(Long.toString(res.getFetchPeriod()), columnLength,
" "));
  +            buf.append(getFilledUpToLength(Long.toString(res.getUpdatePeriod()), columnLength,
" "));
  +            buf.append(getFilledUpToLength(Long.toString(res.getDeletePeriod()), columnLength,
" "));
               counter++;
           }
           buf.append(EOL);
  @@ -406,7 +405,7 @@
        * resultArr[3] updating times
        * resultArr[4] deleting times
        */
  -    public void addPeriodResult(String testName, long[] resultArr)
  +    public synchronized void addPeriodResult(String testName, long[] resultArr)
       {
           PerfResult result = (PerfResult) resultMap.get(testName);
           if (result == null)
  @@ -436,13 +435,17 @@
           System.out.println(buf.toString());
       }
   
  -    public void addConsistentResult(String testName, int objectsBefore, int objectsAfter)
  +    public synchronized void addConsistentResult(String testName, int objectsBefore, int
objectsAfter)
       {
           ConsistentEntry ce = new ConsistentEntry(objectsBefore, objectsAfter);
           PerfResult result = (PerfResult) resultMap.get(testName);
           if(objectsBefore != objectsAfter)
           {
  -            try{throw new Exception("Wrong object count, before=" + objectsBefore + ",
after=" + objectsAfter);}catch(Exception e)
  +            try
  +            {
  +                throw new Exception("Wrong object count, before=" + objectsBefore + ",
after=" + objectsAfter);
  +            }
  +            catch(Exception e)
               {
                   registerException(testName, e);
               }
  @@ -516,17 +519,17 @@
           public String toString()
           {
               StringBuffer buf = new StringBuffer();
  -            buf.append(EOL + "[" + this.getClass().getName());
  -            buf.append(EOL + "testName=" + testName);
  -            buf.append(EOL + "testPeriod=" + testPeriod);
  -            buf.append(EOL + "testLoops=" + testLoops);
  -            buf.append(EOL + "numberOfThreads=" + numberOfThreads);
  -            buf.append(EOL + "iterationsPerThread=" + iterationsPerThread);
  -            buf.append(EOL + "isValid=" + isValid());
  -            buf.append(EOL + "insertPeriod=" + getInsertPeriod());
  -            buf.append(EOL + "fetchPeriod=" + getFetchPeriod());
  -            buf.append(EOL + "deletePeriod=" + getDeletePeriod());
  -            buf.append(EOL + "consistentList: " + consistentList);
  +            buf.append(EOL).append("[").append(this.getClass().getName());
  +            buf.append(EOL).append("testName=").append(testName);
  +            buf.append(EOL).append("testPeriod=").append(testPeriod);
  +            buf.append(EOL).append("testLoops=").append(testLoops);
  +            buf.append(EOL).append("numberOfThreads=").append(numberOfThreads);
  +            buf.append(EOL).append("iterationsPerThread=").append(iterationsPerThread);
  +            buf.append(EOL).append("isValid=").append(isValid());
  +            buf.append(EOL).append("insertPeriod=").append(getInsertPeriod());
  +            buf.append(EOL).append("fetchPeriod=").append(getFetchPeriod());
  +            buf.append(EOL).append("deletePeriod=").append(getDeletePeriod());
  +            buf.append(EOL).append("consistentList: ").append(consistentList);
               buf.append("]");
               return buf.toString();
           }
  @@ -569,10 +572,10 @@
   
           public long getTestPeriod()
           {
  -            return testPeriod / getTestLoops();
  +            return testPeriod;
           }
   
  -        public void addTestPeriod(long aTestPeriod)
  +        public synchronized void addTestPeriod(long aTestPeriod)
           {
               this.testPeriod += aTestPeriod;
           }
  @@ -617,7 +620,7 @@
               return (insertPeriod / getTestLoops()) / getNumberOfThreads();
           }
   
  -        public void addInsertPeriod(long anInsertPeriod)
  +        public synchronized void addInsertPeriod(long anInsertPeriod)
           {
               this.insertPeriod += anInsertPeriod;
           }
  @@ -627,7 +630,7 @@
               return (fetchPeriod / getTestLoops()) / getNumberOfThreads();
           }
   
  -        public void addFetchPeriod(long aFetchPeriod)
  +        public synchronized void addFetchPeriod(long aFetchPeriod)
           {
               this.fetchPeriod += aFetchPeriod;
           }
  @@ -637,7 +640,7 @@
               return (updatePeriod / getTestLoops()) / getNumberOfThreads();
           }
   
  -        public void addUpdatePeriod(long aUpdatePeriod)
  +        public synchronized void addUpdatePeriod(long aUpdatePeriod)
           {
               this.updatePeriod += aUpdatePeriod;
           }
  @@ -647,7 +650,7 @@
               return (deletePeriod / getTestLoops()) / getNumberOfThreads();
           }
   
  -        public void addDeletePeriod(long aDeletePeriod)
  +        public synchronized void addDeletePeriod(long aDeletePeriod)
           {
               this.deletePeriod += aDeletePeriod;
           }
  @@ -685,10 +688,13 @@
           public String toString()
           {
               StringBuffer buf = new StringBuffer();
  -            buf.append("[" + this.getClass().getName()).
  -                    append(": objectsBefore=" + getObjectsBefore()).
  -                    append(" objectsAfter=" + objectsAfter).
  -                    append(" isPassed=" + isPassed());
  +            buf.append("[").append(this.getClass().getName())
  +                    .append(": objectsBefore=")
  +                    .append(getObjectsBefore())
  +                    .append(" objectsAfter=")
  +                    .append(objectsAfter)
  +                    .append(" isPassed=")
  +                    .append(isPassed());
               return buf.toString();
           }
       }
  
  
  
  1.9.2.2   +19 -7     db-ojb/src/test/org/apache/ojb/performance/PerfTest.java
  
  Index: PerfTest.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/performance/PerfTest.java,v
  retrieving revision 1.9.2.1
  retrieving revision 1.9.2.2
  diff -u -r1.9.2.1 -r1.9.2.2
  --- PerfTest.java	22 Apr 2005 16:42:22 -0000	1.9.2.1
  +++ PerfTest.java	15 Dec 2005 02:10:57 -0000	1.9.2.2
  @@ -23,6 +23,11 @@
    */
   public abstract class PerfTest
   {
  +    protected static final int INSERT = 1;
  +    protected static final int FETCH = 2;
  +    protected static final int UPDATE = 3;
  +    protected static final int DELETE = 4;
  +
       private final String PREFIX_LOG = "[" + this.getClass().getName() + "] ";
   
       /**
  @@ -112,7 +117,7 @@
           threads = new Thread[runnables.length];
           for (int i = 0; i < threads.length; i++)
           {
  -            threads[i] = new Thread(runnables[i]);
  +            threads[i] = new Thread(threadGroup, runnables[i]);
           }
           for (int i = 0; i < threads.length; i++)
           {
  @@ -129,6 +134,13 @@
           {
               System.out.println(PREFIX_LOG + "Thread join interrupted.");
           }
  +
  +        // should always be skipped, because we use 'thread.join'
  +        while(threadGroup.activeCount() > 0)
  +        {
  +            System.out.println("## active threads: " + threadGroup.activeCount());
  +        }
  +
           threads = null;
       }
   
  @@ -142,8 +154,8 @@
                   System.out.println("# Start PerfTest: " + testName() + " #");
               }
   
  -            int objectCount = 0;
  -            int objectCountAfter = 0;
  +            int objectCount;
  +            int objectCountAfter;
   
               testTimes = new long[5];
   
  @@ -153,8 +165,7 @@
               PerfHandle[] perfHandles = new PerfHandle[PerfMain.getConcurrentThreads()];
               for (int i = 0; i < PerfMain.getConcurrentThreads(); i++)
               {
  -                PerfHandle ph = newPerfHandle(this);
  -                perfHandles[i] = ph;
  +                perfHandles[i] = newPerfHandle(this);
               }
               testTimes[0] = System.currentTimeMillis();
               runTestHandles(perfHandles);
  @@ -179,7 +190,8 @@
   
       public synchronized void addTime(int position, long time)
       {
  -        testTimes[position] = testTimes[position] + time;
  +        if(position < 1) throw new RuntimeException("Illegal position set");
  +        testTimes[position] += time;
       }
   
       public void registerPerfMain(PerfMain aPerfMain)
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org


Mime
View raw message