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 Tue, 20 Dec 2005 00:34:15 GMT
arminw      2005/12/19 16:34:15

  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:
  add "get by Identity" test method, add "repeat query by collection"
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.1.2.4   +77 -1     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.3
  retrieving revision 1.1.2.4
  diff -u -r1.1.2.3 -r1.1.2.4
  --- OJBPerfTest.java	15 Dec 2005 02:10:57 -0000	1.1.2.3
  +++ OJBPerfTest.java	20 Dec 2005 00:34:14 -0000	1.1.2.4
  @@ -7,6 +7,7 @@
   import java.util.ArrayList;
   import java.util.Collection;
   import java.util.List;
  +import java.util.Iterator;
   
   import org.apache.ojb.broker.Identity;
   import org.apache.ojb.broker.PersistenceBroker;
  @@ -202,6 +203,30 @@
               return list;
           }
   
  +        public PerfArticle getArticleByIdentity(Long articleId) throws Exception
  +        {
  +            String sql = "SELECT * FROM " + TABLE_NAME + " WHERE ARTICLE_ID=" + articleId.longValue()
+ "";
  +            Connection con = getConnection();
  +            Statement stmt = con.createStatement();
  +            ResultSet rs = stmt.executeQuery(sql);
  +            PerfArticle result = null;
  +            while (rs.next())
  +            {
  +                result = new PerfArticleImpl();
  +                result.setArticleId(new Long(rs.getLong("ARTICLE_ID")));
  +                result.setArticleName(rs.getString("ARTICLE_NAME"));
  +                result.setMinimumStock(rs.getInt("MINIMUM_STOCK"));
  +                result.setPrice(rs.getDouble("PRICE"));
  +                result.setUnit(rs.getString("UNIT"));
  +                result.setStock(rs.getInt("STOCK"));
  +                result.setSupplierId(rs.getInt("SUPPLIER_ID"));
  +            }
  +            rs.close();
  +            stmt.close();
  +            releaseConnection();
  +            return result;
  +        }
  +
           public void updateArticles(PerfArticle[] arr) throws Exception
           {
               // we don't know which field is to update, thus do do all
  @@ -398,6 +423,20 @@
               return col;
           }
   
  +        public PerfArticle getArticleByIdentity(Long articleId) throws Exception
  +        {
  +            PersistenceBroker broker = null;
  +            try
  +            {
  +                broker = PersistenceBrokerFactory.defaultPersistenceBroker();
  +                return (PerfArticle) broker.getObjectByIdentity(broker.serviceIdentity().buildIdentity(PerfArticleImpl.class,
articleId));
  +            }
  +            finally
  +            {
  +                if (broker != null) broker.close();
  +            }
  +        }
  +
           public void updateArticles(PerfArticle[] arr) throws Exception
           {
               PersistenceBroker broker = null;
  @@ -601,6 +640,28 @@
               return allProducts;
           }
   
  +        public PerfArticle getArticleByIdentity(Long articleId) throws Exception
  +        {
  +//            m_tx.setImplicitLocking(false);
  +//            m_tx.begin();
  +//            OQLQuery query = odmg.newOQLQuery();
  +//            String sql = "select allArticles from " + PerfArticleImpl.class.getName()
+
  +//                    " where articleId=$";
  +//            query.create(sql);
  +//            query.bind(articleId);
  +//            List result = (List) query.execute();
  +//            m_tx.commit();
  +//            return (PerfArticle) result.get(0);
  +// use OJB's extension for faster Identity lookup
  +            PerfArticle result;
  +            m_tx.setImplicitLocking(false);
  +            m_tx.begin();
  +            PersistenceBroker pb = m_tx.getBroker();
  +            result = (PerfArticle) pb.getObjectByIdentity(pb.serviceIdentity().buildIdentity(PerfArticleImpl.class,
articleId));
  +            m_tx.commit();
  +            return result;
  +        }
  +
           public void updateArticles(PerfArticle[] arr) throws Exception
           {
               m_tx.begin();
  @@ -768,6 +829,21 @@
               return col;
           }
   
  +        public PerfArticle getArticleByIdentity(Long articleId) throws Exception
  +        {
  +            Criteria c = new Criteria();
  +            c.addEqualTo("articleId", articleId);
  +            Query q = new QueryByCriteria(PerfArticleImpl.class, c);
  +
  +            _tx = _kit.getTransaction(_conn);
  +            _tx.begin();
  +            // the getByIdeneityMethod() needs Identity and this is currently not supported
  +            Collection col = _conn.getCollectionByQuery(q, LockType.NO_LOCK);
  +            _tx.commit();
  +            Iterator it = col.iterator();
  +            return it.hasNext() ? (PerfArticle) it.next() : null;
  +        }
  +
           public void updateArticles(PerfArticle[] arr) throws Exception
           {
               _tx = _kit.getTransaction(_conn);
  
  
  
  No                   revision
  No                   revision
  1.11.2.4  +45 -1     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.3
  retrieving revision 1.11.2.4
  diff -u -r1.11.2.3 -r1.11.2.4
  --- PerfHandle.java	15 Dec 2005 02:10:57 -0000	1.11.2.3
  +++ PerfHandle.java	20 Dec 2005 00:34:15 -0000	1.11.2.4
  @@ -67,6 +67,15 @@
       public abstract Collection readArticlesByCursor(String articleName) throws Exception;
   
       /**
  +     * Read all stored articles from the database and return the
  +     * result as collection of <code>PerfArticles</code>.
  +     * Do optimize performance.
  +     * @param articleId the primary key of a {@link PerfArticle} instance
  +     * @return The matching {@link PerfArticle} instance or <em>null</em> if
not found.
  +     */
  +    public abstract PerfArticle getArticleByIdentity(Long articleId) throws Exception;
  +
  +    /**
        * Delete all given article from the database.
        * Do optimize performance.
        */
  @@ -188,6 +197,41 @@
               }
               test.addTime(PerfTest.FETCH, period);
   
  +            // read objects
  +            period = System.currentTimeMillis();
  +            col = readArticlesByCursor(objectName);
  +            period = System.currentTimeMillis() - period;
  +            try
  +            {
  +                checkQueryResult(col, m_arr);
  +            }
  +            catch (Exception e)
  +            {
  +                test.registerException(PREFIX_LOG
  +                        + "(Something wrong with query result or with object insert operation)
", e);
  +            }
  +            test.addTime(PerfTest.FETCH_2, period);
  +
  +            // get by Identity
  +            period = System.currentTimeMillis();
  +            PerfArticle result;
  +            for(int i = 0; i < m_arr.length; i++)
  +            {
  +                if(i%4==0)
  +                {
  +                    PerfArticle perfArticle = m_arr[i];
  +                    result = getArticleByIdentity(perfArticle.getArticleId());
  +                    if(result == null)
  +                    {
  +                        test.registerException("Unexpected result: Get by Identity is 'null'
for "
  +                                + PerfArticle.class.getName() + " with primary key "
  +                                + perfArticle.getArticleId(), null);
  +                    }
  +                }
  +            }
  +            period = System.currentTimeMillis() - period;
  +            test.addTime(PerfTest.BY_IDENTITY, period);
  +
               // update objects
               modifyPerfArticle(m_arr);
               if (PerfMain.isUseStressMode())
  
  
  
  1.9.2.5   +78 -40    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.4
  retrieving revision 1.9.2.5
  diff -u -r1.9.2.4 -r1.9.2.5
  --- PerfMain.java	15 Dec 2005 02:10:57 -0000	1.9.2.4
  +++ PerfMain.java	20 Dec 2005 00:34:15 -0000	1.9.2.5
  @@ -28,6 +28,8 @@
   import java.util.Map;
   import java.util.StringTokenizer;
   
  +import org.apache.commons.lang.exception.ExceptionUtils;
  +
   /**
    * The OJB stress/performance test - a simple performance test framework for
    * testing multi-threaded environments.
  @@ -77,6 +79,11 @@
    */
   public class PerfMain
   {
  +    /**
  +     * The factor for get by Identity calls, e.g. 4 means handling 100 objects
  +     * result in 100/4 getByIdentity calls.
  +     */
  +    protected static final int BY_IDENTITY_FACTOR = 4;
       protected static final String EOL = System.getProperty("line.separator");
   
       /** iterations per thread */
  @@ -228,25 +235,6 @@
                   }
               }
           }
  -
  -//        Iterator it = testList.iterator();
  -//        while (it.hasNext())
  -//        {
  -//            String perfTest = (String) it.next();
  -//            PerfTest test = (PerfTest) Class.forName(perfTest).newInstance();
  -//            test.registerPerfMain(this);
  -//            Runtime rt = Runtime.getRuntime();
  -//            long freeMem = 0;
  -//            for (int i = 0; i < testLoops; i++)
  -//            {
  -//                System.out.println("perform test loop " + (i + 1));
  -//                freeMem = rt.freeMemory();
  -//                test.performTest();
  -//                freeMem = (freeMem - rt.freeMemory()) / 1024;
  -//                System.out.println("allocated memory after test: " + freeMem + " kb");
  -//                rt.gc();
  -//            }
  -//        }
       }
   
       public void printResult(OutputStream out)
  @@ -258,14 +246,18 @@
           {
               StringBuffer buf = new StringBuffer();
               buf.append(EOL).append("Failures occured, test not valid:").append(EOL);
  -            Iterator it = getExceptionMap().keySet().iterator();
  +            Iterator it = getExceptionMap().entrySet().iterator();
               while (it.hasNext())
               {
  -                String causer = (String) it.next();
  -                buf.append("Failure cause by ")
  -                        .append(causer).append(", exception was ")
  -                        .append(exceptionMap.get(causer))
  -                        .append(EOL);
  +                Map.Entry entry = (Map.Entry) it.next();
  +                buf.append("Failure cause by ").append(entry.getKey());
  +                if(entry.getValue() != null)
  +                {
  +                    Throwable ex = ExceptionUtils.getRootCause((Exception) entry.getValue());
  +                    if(ex == null) ex = (Exception) entry.getValue();
  +                    buf.append(EOL).append("Exception was: ").append(EOL).append(ExceptionUtils.getStackTrace(ex));
  +                }
  +                buf.append(EOL);
               }
               print.println(buf.toString());
           }
  @@ -285,7 +277,8 @@
       private String buildTestSummary(Collection results)
       {
           int columnLength = 8;
  -        int columnNumbers = 8;
  +        int columnNumbers = 10;
  +        final String indent = "  ";
   
           StringBuffer buf = new StringBuffer();
           // table header
  @@ -298,13 +291,22 @@
           buf.append(getFilledUpToLength("", columnLength, " "));
           buf.append(getFilledUpToLength("OJB PERFORMANCE TEST SUMMARY", columnLength, "
"));
           buf.append(EOL);
  -
  -        buf.append(PerfMain.getConcurrentThreads());
  +        for (int i = 0; i < columnNumbers; i++)
  +        {
  +            buf.append(getFilledUpToLength("", columnLength, "-"));
  +        }
  +        buf.append(EOL);
  +        buf.append(indent).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(EOL).append(indent).append(iterationsPerThread).append(" INSERT operations
per thread");
  +        buf.append(EOL).append(indent + "FETCH collection of ").append(iterationsPerThread).append("
objects per thread");
  +        buf.append(EOL).append(indent + "Repeat FETCH collection of ").append(iterationsPerThread).append("
objects per thread");
  +        buf.append(EOL).append(indent).append((iterationsPerThread / PerfMain.BY_IDENTITY_FACTOR)).append("
get by Identity calls  per thread");
  +        buf.append(EOL).append(indent).append(iterationsPerThread).append(" UPDATE operations
per thread");
  +        buf.append(EOL).append(indent).append(iterationsPerThread).append(" DELETE operations
per thread");
  +        buf.append(EOL).append(indent);
           buf.append("- ").append(!(isUseStressMode()) ? "performance mode" : "stress mode");
           buf.append(" - results per thread (av)");
           buf.append(EOL);
  @@ -319,6 +321,8 @@
           buf.append(getFilledUpToLength("Total", columnLength, " "));
           buf.append(getFilledUpToLength("Insert", columnLength, " "));
           buf.append(getFilledUpToLength("Fetch", columnLength, " "));
  +        buf.append(getFilledUpToLength("Fetch 2", columnLength, " "));
  +        buf.append(getFilledUpToLength("by Id", columnLength, " "));
           buf.append(getFilledUpToLength("Update", columnLength, " "));
           buf.append(getFilledUpToLength("Delete", columnLength, " "));
           buf.append(EOL);
  @@ -330,6 +334,8 @@
           buf.append(getFilledUpToLength("[msec]", columnLength, " "));
           buf.append(getFilledUpToLength("[msec]", columnLength, " "));
           buf.append(getFilledUpToLength("[msec]", columnLength, " "));
  +        buf.append(getFilledUpToLength("[msec]", columnLength, " "));
  +        buf.append(getFilledUpToLength("[msec]", columnLength, " "));
           buf.append(EOL);
           for (int i = 0; i < columnNumbers; i++)
           {
  @@ -364,6 +370,8 @@
               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.getFetchSecondPeriod()), columnLength,
" "));
  +            buf.append(getFilledUpToLength(Long.toString(res.getByIdentityPeriod()), columnLength,
" "));
               buf.append(getFilledUpToLength(Long.toString(res.getUpdatePeriod()), columnLength,
" "));
               buf.append(getFilledUpToLength(Long.toString(res.getDeletePeriod()), columnLength,
" "));
               counter++;
  @@ -399,11 +407,13 @@
       }
   
       /**
  -     * resultArr[0] startTime/test length
  -     * resultArr[1] inserting times
  -     * resultArr[2] fetching times
  -     * resultArr[3] updating times
  -     * resultArr[4] deleting times
  +     * testTimes[0] startTime/test length
  +     * testTimes[1] inserting times
  +     * testTimes[2] fetching times
  +     * testTimes[3] fetching repeat times
  +     * testTimes[4] get by Identity times
  +     * testTimes[5] updating times
  +     * testTimes[6] deleting times
        */
       public synchronized void addPeriodResult(String testName, long[] resultArr)
       {
  @@ -422,16 +432,20 @@
           result.addTestPeriod(resultArr[0]);
           result.addInsertPeriod(resultArr[1]);
           result.addFetchPeriod(resultArr[2]);
  -        result.addUpdatePeriod(resultArr[3]);
  -        result.addDeletePeriod(resultArr[4]);
  +        result.addFetchSecondPeriod(resultArr[3]);
  +        result.addByIdentityPeriod(resultArr[4]);
  +        result.addUpdatePeriod(resultArr[5]);
  +        result.addDeletePeriod(resultArr[6]);
   
           StringBuffer buf = new StringBuffer();
           buf.append("Test '").append(result.getTestName()).append("' [ms]")
                   .append(": testPeriod=").append(resultArr[0])
                   .append(" insert=").append(resultArr[1]/getConcurrentThreads())
                   .append(" read=").append(resultArr[2]/getConcurrentThreads())
  -                .append(" update=").append(resultArr[3]/getConcurrentThreads())
  -                .append(" delete=").append(resultArr[4]/getConcurrentThreads());
  +                .append(" read2=").append(resultArr[3]/getConcurrentThreads())
  +                .append(" byIdentity=").append(resultArr[4]/getConcurrentThreads())
  +                .append(" update=").append(resultArr[5]/getConcurrentThreads())
  +                .append(" delete=").append(resultArr[6]/getConcurrentThreads());
           System.out.println(buf.toString());
       }
   
  @@ -503,6 +517,8 @@
   
           private long insertPeriod;
           private long fetchPeriod;
  +        private long fetchSecondPeriod;
  +        private long byIdentityPeriod;
           private long updatePeriod;
           private long deletePeriod;
   
  @@ -528,6 +544,8 @@
               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("fetchSecondPeriod=").append(getFetchSecondPeriod());
  +            buf.append(EOL).append("byIdentity=").append(getByIdentityPeriod());
               buf.append(EOL).append("deletePeriod=").append(getDeletePeriod());
               buf.append(EOL).append("consistentList: ").append(consistentList);
               buf.append("]");
  @@ -635,6 +653,26 @@
               this.fetchPeriod += aFetchPeriod;
           }
   
  +        public long getFetchSecondPeriod()
  +        {
  +            return (fetchSecondPeriod / getTestLoops()) / getNumberOfThreads();
  +        }
  +
  +        public synchronized void addFetchSecondPeriod(long secondPeriod)
  +        {
  +            this.fetchSecondPeriod += secondPeriod;
  +        }
  +
  +        public long getByIdentityPeriod()
  +        {
  +            return (byIdentityPeriod / getTestLoops()) / getNumberOfThreads();
  +        }
  +
  +        public synchronized void addByIdentityPeriod(long byIdentityPeriod)
  +        {
  +            this.byIdentityPeriod += byIdentityPeriod;
  +        }
  +
           public long getUpdatePeriod()
           {
               return (updatePeriod / getTestLoops()) / getNumberOfThreads();
  
  
  
  1.9.2.3   +10 -6     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.2
  retrieving revision 1.9.2.3
  diff -u -r1.9.2.2 -r1.9.2.3
  --- PerfTest.java	15 Dec 2005 02:10:57 -0000	1.9.2.2
  +++ PerfTest.java	20 Dec 2005 00:34:15 -0000	1.9.2.3
  @@ -25,8 +25,10 @@
   {
       protected static final int INSERT = 1;
       protected static final int FETCH = 2;
  -    protected static final int UPDATE = 3;
  -    protected static final int DELETE = 4;
  +    protected static final int FETCH_2 = 3;
  +    protected static final int BY_IDENTITY = 4;
  +    protected static final int UPDATE = 5;
  +    protected static final int DELETE = 6;
   
       private final String PREFIX_LOG = "[" + this.getClass().getName() + "] ";
   
  @@ -34,8 +36,10 @@
        * testTimes[0] startTime/test length
        * testTimes[1] inserting times
        * testTimes[2] fetching times
  -     * testTimes[3] updating times
  -     * testTimes[4] deleting times
  +     * testTimes[3] fetching repeat times
  +     * testTimes[4] get by Identity times
  +     * testTimes[5] updating times
  +     * testTimes[6] deleting times
        */
       private long[] testTimes;
       private ThreadGroup threadGroup;
  @@ -157,7 +161,7 @@
               int objectCount;
               int objectCountAfter;
   
  -            testTimes = new long[5];
  +            testTimes = new long[7];
   
               objectCount = articleCount();
   
  
  
  

---------------------------------------------------------------------
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