db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d..@apache.org
Subject svn commit: r573329 - in /db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe: client/Submitter.java load/SimpleInsert.java run/Populate.java run/ThreadPopulate.java test/OperationsTester.java util/OERandom.java
Date Thu, 06 Sep 2007 18:09:11 GMT
Author: djd
Date: Thu Sep  6 11:09:09 2007
New Revision: 573329

URL: http://svn.apache.org/viewvc?rev=573329&view=rev
Log:
Various improvements in the Order Entry setup, consistent random number handling to match
TPC-C spec. Add a option to load the database using multiple threads for the run.Populate
class

Removed:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/run/ThreadPopulate.java
Modified:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/client/Submitter.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/load/SimpleInsert.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/run/Populate.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/test/OperationsTester.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/util/OERandom.java

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/client/Submitter.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/client/Submitter.java?rev=573329&r1=573328&r2=573329&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/client/Submitter.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/client/Submitter.java
Thu Sep  6 11:09:09 2007
@@ -21,6 +21,9 @@
 
 import java.io.PrintStream;
 import java.math.BigDecimal;
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.SQLException;
 
 import org.apache.derbyTesting.system.oe.util.OERandom;
 
@@ -104,6 +107,40 @@
      * Record of how many transactions are implemented.
      */
     private final int[] transactionCount;
+    
+    /**
+     * Generate a new random number generator
+     * that follows the rules according to 2.1.6.1
+     * @param conn
+     * @return
+     * @throws SQLException
+     */
+    public static OERandom getRuntimeRandom(Connection conn)
+        throws SQLException
+    {
+        OERandom rand = new OERandom(-1);
+        
+        ResultSet rs = conn.createStatement().executeQuery(
+                "SELECT CLOAD FROM C");
+        rs.next();
+        int cload = rs.getInt(1);
+        rs.close();
+        
+        for (;;)
+        {
+            int c = rand.randomInt(0, 255);
+            int delta = Math.abs(cload - c);
+            if (delta == 96 || delta == 112)
+                continue;
+            if (delta < 65 || delta > 119)
+                continue;
+            
+            rand = new OERandom(c);
+            break;
+        }
+        
+        return rand;
+    }
 
     public Submitter(Display display, Operations ops, OERandom rand,
             short maxW)
@@ -118,12 +155,31 @@
     }
     
     /**
+     * Run a fixed number of transactions returning the
+     * time in milli-seconds required to execute all of them.
+     * @param displayData Passed onto Display calls
+     * @param count Number of transactions to run
+     * @return Elapsed time in ms to run count transactions
+     * @throws Exception
+     */
+    public long runTransactions(final Object displayData, final int count)
+    throws Exception
+    {
+        long startms = System.currentTimeMillis();
+        for (int i = 0; i < count; i++)
+            runTransaction(displayData);
+        long endms = System.currentTimeMillis();
+        
+        return endms - startms;
+    }
+    
+    /**
      * Run an order entry transaction picking the specific
      * transaction at random with a hard-coded mix.
      * @param displayData Passed onto Display calls
      * @throws Exception Error executing the transaction
      */
-    public void runTransaction(Object displayData) throws Exception
+    public void runTransaction(final Object displayData) throws Exception
     {       
         int chooseType = rand.randomInt(1, 100);
         
@@ -172,7 +228,7 @@
      * @param chooseType Random number between 1 and 100 inclusive.
      * @return A transaction constant from this class.
      */
-    protected int mixType(int chooseType)
+    protected int mixType(final int chooseType)
     {
         if (chooseType <= 43)
         {

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/load/SimpleInsert.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/load/SimpleInsert.java?rev=573329&r1=573328&r2=573329&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/load/SimpleInsert.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/load/SimpleInsert.java
Thu Sep  6 11:09:09 2007
@@ -71,14 +71,14 @@
             // ignore
         }
         conn.commit();
-        s.execute("CREATE TABLE C(CLOAD INT, CLAST INT, CID INT, CITEM INT)");
+        s.execute("CREATE TABLE C(CLOAD INT)");
         conn.commit();
 
-        random = new OERandom(-1, -1, -1, seed);
+        random = new OERandom(-1, seed);
 
         // Section 2.1.6.1 of TPC-C spec
         int loadRandomFactor = random.randomInt(0, 255);
-        s.execute("INSERT INTO C VALUES(" + loadRandomFactor + ", -1, -1, -1)");
+        s.execute("INSERT INTO C VALUES(" + loadRandomFactor + ")");
         s.close();
         conn.commit();  
         
@@ -108,7 +108,7 @@
         rs.next();
         int loadRandomFactor = rs.getInt(1);
         rs.close();
-        random = new OERandom(loadRandomFactor, -1, -1, seed);
+        random = new OERandom(loadRandomFactor, seed);
         s.close();
         conn.commit();
     }

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/run/Populate.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/run/Populate.java?rev=573329&r1=573328&r2=573329&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/run/Populate.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/run/Populate.java Thu
Sep  6 11:09:09 2007
@@ -19,19 +19,17 @@
  */
 package org.apache.derbyTesting.system.oe.run;
 
-import java.io.IOException;
-import java.io.UnsupportedEncodingException;
-import java.security.PrivilegedActionException;
 import java.sql.SQLException;
 
+import javax.sql.DataSource;
+
 import junit.framework.Test;
 import junit.framework.TestSuite;
 
+import org.apache.derbyTesting.junit.JDBCDataSource;
 import org.apache.derbyTesting.junit.JDBCPerfTestCase;
 import org.apache.derbyTesting.system.oe.client.Load;
-import org.apache.derbyTesting.system.oe.load.SimpleInsert;
-import org.apache.derbyTesting.system.oe.run.Checks;
-import org.apache.derbyTesting.system.oe.run.Schema;
+import org.apache.derbyTesting.system.oe.load.ThreadInsert;
 
 /**
  * Driver to do the load phase for the Order Entry benchmark.
@@ -43,6 +41,7 @@
  * <LI>-scale warehouse scaling factor. Takes a short value. If not specified defaults
to 1
  * <LI>-createConstraintsBeforeLoad create constraints before initial load of data,
takes a boolean value. If not specified, defaults to true
  * <LI>-doChecks check consistency of data, takes a boolean value. If not specified,
defaults to true
+ * <LI>-loaderThreads Number of threads to populate tables, defaults to number of cores
  * <LI>-help prints usage
  * </OL>
  * 
@@ -66,6 +65,11 @@
      * Warehouse scale factor
      */
     static short scale = 1;
+    
+    /**
+     * Number of threads to load the data.
+     */
+    static int loaderThreads;
 
     /**
      * flag to indicate if we should create constraints before loading data
@@ -77,11 +81,6 @@
      * after the load
      */
     private static boolean doChecks = true;
-    
-    /**
-     * Load implementation used to populate the database
-     */
-    Load loader;
 
     /**
      * Create a test case with the given name.
@@ -95,20 +94,6 @@
 
 
     /**
-     * Do the initial setup required Initialize the appropriate implementation
-     * for the Load phase.
-     */
-    protected void setUp() throws Exception {
-        // Use simple insert statements to insert data.
-        // currently only this form of load is present, once we have 
-        // different implementations, the loading mechanism will need
-        // to be configurable taking an option from the command line
-        // arguments.
-       loader = new SimpleInsert();
-       loader.setupLoad(getConnection(), scale);
-    }
-
-    /**
      * Run OE load
      * @param args supply arguments for benchmark.
      * @throws Exception
@@ -135,6 +120,8 @@
                 createConstraintsBeforeLoad = (args[++i].equals("false")? false:true);
             } else if (arg.equals("-doChecks")) {
                 doChecks = (args[++i].equals("false")? false:true);
+            } else if (arg.equals("-loaderThreads")) {
+                loaderThreads = Integer.parseInt(args[++i]);
             } else if (arg.equals("-help")) {
                 printUsage();
                 System.exit(0);
@@ -153,6 +140,7 @@
         System.out.println("  -scale warehouse scaling factor. Takes a short value. If not
specified defaults to 1");
         System.out.println("  -createConstraintsBeforeLoad create constraints before initial
load of data, takes a boolean value. If not specified, defaults to true)");
         System.out.println("  -doChecks check consistency of data, takes a boolean value.
If not specified, defaults to true)");
+        System.out.println("  -loaderThreads number of threads used to populate database,
defaults to number of cpu cores)");
         System.out.println("  -help prints usage");
         System.out.println();
     }
@@ -163,11 +151,10 @@
      * @return the tests to run
      */
     public static Test suite() {
-        return loaderSuite(Populate.class);
-    }
-    
-    static Test loaderSuite(Class loader) {
+
         TestSuite suite = new TestSuite("Order Entry");
+        
+        suite.addTest(new Populate("testCreateDB"));
 
         // Create Schema
         Schema.addBaseSchema(suite);
@@ -175,7 +162,7 @@
             Schema.addConstraints(suite);
         
         // this will populate db
-        suite.addTestSuite(loader);
+        suite.addTest(new Populate("testLoad"));
 
         if (!createConstraintsBeforeLoad)
             Schema.addConstraints(suite);
@@ -192,6 +179,16 @@
         return suite;
     }
 
+    public void testCreateDB() throws SQLException
+    {
+        DataSource ds = JDBCDataSource.getDataSource();
+        
+        JDBCDataSource.setBeanProperty(ds,
+                "createDatabase", "create");
+ 
+        ds.getConnection().close();
+
+    }
 
     /**
      * test the initial database load
@@ -199,6 +196,19 @@
      * @throws Exception
      */
     public void testLoad() throws Exception {
+        
+        // Use simple insert statements to insert data.
+        // currently only this form of load is present, once we have 
+        // different implementations, the loading mechanism will need
+        // to be configurable taking an option from the command line
+        // arguments.
+        DataSource ds = JDBCDataSource.getDataSource();
+       
+        Load loader = new ThreadInsert(ds);
+        loader.setupLoad(getConnection(), scale);
+        if (loaderThreads > 0)
+            loader.setThreadCount(loaderThreads);
+        
         loader.populateAllTables();
 
         // Way to populate data is extensible. Any other implementation

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/test/OperationsTester.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/test/OperationsTester.java?rev=573329&r1=573328&r2=573329&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/test/OperationsTester.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/test/OperationsTester.java
Thu Sep  6 11:09:09 2007
@@ -42,17 +42,18 @@
 public class OperationsTester extends BaseJDBCTestCase implements Display {
 
     private Operations ops;
-    private final OERandom rand;
+    private OERandom rand;
     private final short w = 1;
     
     public OperationsTester(String name) {
         super(name);
-        this.rand = new OERandom(-1, -1, -1);
+        
     }
     
     protected void setUp() throws Exception 
     {
         ops = new Standard(getConnection());
+        rand = Submitter.getRuntimeRandom(getConnection());
     }
     
     protected void tearDown() throws Exception
@@ -242,25 +243,32 @@
         
     }
     
+    /**
+     * Test submitting transactions through Submitter,
+     * as individual transactions and as a block.
+     * @throws Exception
+     */
     public void testSubmitter() throws Exception
     {
         Submitter submitter = new Submitter(this, this.ops, this.rand,
                 (short) 1);
         
         int tranCount = 37;
-        
         for (int i = 0; i < tranCount; i++)
         {
             submitter.runTransaction(null);
         }
         
+        int tranCount2 = 47;
+        submitter.runTransactions(null, tranCount2);
+        
         int[] executeCounts = submitter.getTransactionCount();
         int totalTran = 0;
         for (int i = 0; i < executeCounts.length; i++)
             totalTran += executeCounts[i];
         
         assertEquals("Mismatch on Submitter transaction count",
-                tranCount, totalTran);
+                tranCount + tranCount2, totalTran);
         
     }
 }

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/util/OERandom.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/util/OERandom.java?rev=573329&r1=573328&r2=573329&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/util/OERandom.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/util/OERandom.java
Thu Sep  6 11:09:09 2007
@@ -39,18 +39,32 @@
     protected final int Cid;
 
     protected final int Citem;
+    
+    /**
+     * Create a matching OERandom, for use in multi-threaded
+     * runs where all the submitters need to share the same
+     * Clast, Cid and Citem values.
+     * @param oer
+     */
+    public OERandom(OERandom oer) {
+        rand = new Random(System.currentTimeMillis());
+        Clast = oer.Clast;
+        Cid = oer.Cid;
+        Citem = oer.Citem;
+    }
 
-    public OERandom(int last, int id, int item, long seed) {
+    public OERandom(int last, long seed) {
 
-        Clast = last;
-        Cid = id;
-        Citem = item;
         rand = new Random(seed);
+        Clast = last;
+        Cid = this.randomInt(0, 255);
+        Citem = this.randomInt(0, 255);
+        
         initAStrings();
     }
 
-    public OERandom(int last, int id, int item) {
-        this(last, id, item, System.currentTimeMillis());
+    public OERandom(int last) {
+        this(last, System.currentTimeMillis());
     }
 
     private static int[] RESCALE = { 0, 10, 100, 1000, 10000, 100000, 1000000 };



Mime
View raw message