You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-commits@db.apache.org by ka...@apache.org on 2008/04/21 13:38:11 UTC
svn commit: r650112 - in
/db/derby/code/trunk/java/testing/org/apache/derbyTesting/perf/clients:
Runner.java SingleRecordFiller.java SingleRecordSelectClient.java
SingleRecordUpdateClient.java
Author: kahatlen
Date: Mon Apr 21 04:38:10 2008
New Revision: 650112
URL: http://svn.apache.org/viewvc?rev=650112&view=rev
Log:
DERBY-3619: Implement more load types for org.apache.derbyTesting.perf.clients.Runner
Added simple selects of rows with columns containing a BLOB or a CLOB.
Modified:
db/derby/code/trunk/java/testing/org/apache/derbyTesting/perf/clients/Runner.java
db/derby/code/trunk/java/testing/org/apache/derbyTesting/perf/clients/SingleRecordFiller.java
db/derby/code/trunk/java/testing/org/apache/derbyTesting/perf/clients/SingleRecordSelectClient.java
db/derby/code/trunk/java/testing/org/apache/derbyTesting/perf/clients/SingleRecordUpdateClient.java
Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/perf/clients/Runner.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/perf/clients/Runner.java?rev=650112&r1=650111&r2=650112&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/perf/clients/Runner.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/perf/clients/Runner.java Mon Apr 21 04:38:10 2008
@@ -25,6 +25,7 @@
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
+import java.sql.Types;
/**
* Class used for running a performance test from the command line. To learn
@@ -166,7 +167,8 @@
" -init: initialize database (otherwise, reuse database)\n" +
" -load: type of load, required argument, valid types:\n" +
" * sr_select - single-record (primary key) select from table with\n" +
-" 100 000 rows\n" +
+" 100 000 rows. If _blob or _clob is appended to the\n" +
+" name, BLOB/CLOB is used for the data columns.\n" +
" * sr_update - single-record (primary key) update on table with\n" +
" 100 000 rows\n" +
" * sr_select_big - single-record (primary key) select from table with\n" +
@@ -204,13 +206,17 @@
*/
private static DBFiller getDBFiller() {
if (load.equals("sr_select") || load.equals("sr_update")) {
- return new SingleRecordFiller(100000, 1);
+ return new SingleRecordFiller(100000, 1, Types.VARCHAR);
+ } else if (load.equals("sr_select_blob")) {
+ return new SingleRecordFiller(100000, 1, Types.BLOB);
+ } else if (load.equals("sr_select_clob")) {
+ return new SingleRecordFiller(100000, 1, Types.CLOB);
} else if (load.equals("sr_select_big") ||
load.equals("sr_update_big")) {
- return new SingleRecordFiller(100000000, 1);
+ return new SingleRecordFiller(100000000, 1, Types.VARCHAR);
} else if (load.equals("sr_select_multi") ||
load.equals("sr_update_multi")) {
- return new SingleRecordFiller(1, 32);
+ return new SingleRecordFiller(1, 32, Types.VARCHAR);
} else if (load.equals("index_join")) {
return new WisconsinFiller();
}
@@ -227,15 +233,19 @@
*/
private static Client newClient() {
if (load.equals("sr_select")) {
- return new SingleRecordSelectClient(100000, 1);
+ return new SingleRecordSelectClient(100000, 1, Types.VARCHAR);
+ } else if (load.equals("sr_select_blob")) {
+ return new SingleRecordSelectClient(100000, 1, Types.BLOB);
+ } else if (load.equals("sr_select_clob")) {
+ return new SingleRecordSelectClient(100000, 1, Types.CLOB);
} else if (load.equals("sr_update")) {
return new SingleRecordUpdateClient(100000, 1);
} else if (load.equals("sr_select_big")) {
- return new SingleRecordSelectClient(100000000, 1);
+ return new SingleRecordSelectClient(100000000, 1, Types.VARCHAR);
} else if (load.equals("sr_update_big")) {
return new SingleRecordUpdateClient(100000000, 1);
} else if (load.equals("sr_select_multi")) {
- return new SingleRecordSelectClient(1, 32);
+ return new SingleRecordSelectClient(1, 32, Types.VARCHAR);
} else if (load.equals("sr_update_multi")) {
return new SingleRecordUpdateClient(1, 32);
} else if (load.equals("index_join")) {
Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/perf/clients/SingleRecordFiller.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/perf/clients/SingleRecordFiller.java?rev=650112&r1=650111&r2=650112&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/perf/clients/SingleRecordFiller.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/perf/clients/SingleRecordFiller.java Mon Apr 21 04:38:10 2008
@@ -21,10 +21,13 @@
package org.apache.derbyTesting.perf.clients;
+import java.io.ByteArrayInputStream;
+import java.io.StringReader;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Statement;
+import java.sql.Types;
import java.util.Random;
/**
@@ -37,8 +40,10 @@
private final int numberOfTables;
private final int tableSize;
+ private final int dataType;
+ private final String dataTypeString;
- private static final int TEXT_SIZE = 100;
+ static final int TEXT_SIZE = 100;
/**
* Generate a filler that creates the specified number of tables, each of
@@ -46,21 +51,38 @@
*
* @param records the number of records in each table
* @param tables the number of tables to create
+ * @param type which SQL type to store the text as (one of
+ * {@code java.sql.Types.VARCHAR}, {@code java.sql.Types.BLOB} and
+ * {@code java.sql.Types.CLOB}.
*/
- public SingleRecordFiller(int records, int tables) {
+ public SingleRecordFiller(int records, int tables, int type) {
tableSize = records;
numberOfTables = tables;
+ dataType = type;
+ switch (type) {
+ case Types.VARCHAR:
+ dataTypeString = "VARCHAR";
+ break;
+ case Types.BLOB:
+ dataTypeString = "BLOB";
+ break;
+ case Types.CLOB:
+ dataTypeString = "CLOB";
+ break;
+ default:
+ throw new IllegalArgumentException("type = " + type);
+ }
}
public void fill(Connection c) throws SQLException {
c.setAutoCommit(false);
Statement s = c.createStatement();
for (int table = 0; table < numberOfTables; table++) {
- String tableName = getTableName(tableSize, table);
+ String tableName = getTableName(tableSize, table, dataType);
WisconsinFiller.dropTable(c, tableName);
s.executeUpdate(
"CREATE TABLE " + tableName + "(ID INT PRIMARY KEY, " +
- "TEXT VARCHAR(" + TEXT_SIZE + "))");
+ "TEXT " + dataTypeString + "(" + TEXT_SIZE + "))");
PreparedStatement ps =
c.prepareStatement("INSERT INTO " + tableName +
@@ -68,7 +90,16 @@
for (int i = 0; i < tableSize; i++) {
ps.setInt(1, i);
- ps.setString(2, randomString(i));
+ if (dataType == Types.VARCHAR) {
+ ps.setString(2, randomString(i));
+ } else if (dataType == Types.CLOB) {
+ StringReader reader = new StringReader(randomString(i));
+ ps.setCharacterStream(2, reader, TEXT_SIZE);
+ } else if (dataType == Types.BLOB) {
+ ByteArrayInputStream stream =
+ new ByteArrayInputStream(randomBytes(i));
+ ps.setBinaryStream(2, stream, TEXT_SIZE);
+ }
ps.executeUpdate();
if ((i % 1000) == 0) {
c.commit();
@@ -83,6 +114,7 @@
}
private static final String[] RANDOM_STRINGS = new String[16];
+ private static final byte[][] RANDOM_BYTES = new byte[16][TEXT_SIZE];
static {
final String alphabet = "abcdefghijklmnopqrstuvwxyz" +
"ABCDEFGHIJKLMNOPQRSTUVWXYZ" +
@@ -94,6 +126,9 @@
buf.append(alphabet.charAt(r.nextInt(alphabet.length())));
}
RANDOM_STRINGS[i] = buf.toString();
+ for (int j = 0; j < TEXT_SIZE; j++) {
+ RANDOM_BYTES[i][j] = (byte) RANDOM_STRINGS[i].charAt(j);
+ }
}
}
@@ -108,14 +143,36 @@
}
/**
+ * Pick a random byte string.
+ *
+ * @param seed a seed used to decide which random string to pick
+ * @return a (somewhat) random sequence of bytes
+ */
+ static byte[] randomBytes(int seed) {
+ return RANDOM_BYTES[(seed & 0x7fffffff) % RANDOM_BYTES.length];
+ }
+
+ /**
* Get the name of a table generated by this class.
*
* @param records the number of records in the table
* @param table the number of the table, between 0 (inclusive) and the
* total number of tables (exclusive)
+ * @param dataType the {@code java.sql.Types} constant specifying the
+ * data type of the text column
* @return the name of the table specified by the arguments
*/
- static String getTableName(int records, int table) {
- return "SINGLE_RECORD_" + records + "_" + table;
+ static String getTableName(int records, int table, int dataType) {
+ String suffix;
+ if (dataType == Types.VARCHAR) {
+ suffix = "";
+ } else if (dataType == Types.BLOB) {
+ suffix = "_BLOB";
+ } else if (dataType == Types.CLOB) {
+ suffix = "_CLOB";
+ } else {
+ throw new IllegalArgumentException("dataType = " + dataType);
+ }
+ return "SINGLE_RECORD_" + records + "_" + table + suffix;
}
}
Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/perf/clients/SingleRecordSelectClient.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/perf/clients/SingleRecordSelectClient.java?rev=650112&r1=650111&r2=650112&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/perf/clients/SingleRecordSelectClient.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/perf/clients/SingleRecordSelectClient.java Mon Apr 21 04:38:10 2008
@@ -25,6 +25,7 @@
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
+import java.sql.Types;
import java.util.Random;
/**
@@ -40,22 +41,28 @@
private final PreparedStatement[] pss;
private final Random r;
private final int tableSize;
+ private final int dataType;
/**
* Construct a new single-record select client.
*
* @param records the number of records in each table in the test
* @param tables the number of tables in the test
+ * @param type the data type of the text column
+ * ({@code java.sql.Types.VARCHAR}, {@code java.sql.Types.BLOB} or
+ * {@code java.sql.Types.CLOB})
*/
- public SingleRecordSelectClient(int records, int tables) {
+ public SingleRecordSelectClient(int records, int tables, int type) {
tableSize = records;
r = new Random();
pss = new PreparedStatement[tables];
+ dataType = type;
}
public void init(Connection c) throws SQLException {
for (int i = 0; i < pss.length; i++) {
- String tableName = SingleRecordFiller.getTableName(tableSize, i);
+ String tableName =
+ SingleRecordFiller.getTableName(tableSize, i, dataType);
String sql = "SELECT * FROM " + tableName + " WHERE ID = ?";
pss[i] = c.prepareStatement(sql);
}
@@ -69,8 +76,25 @@
ResultSet rs = ps.executeQuery();
rs.next();
rs.getInt(1);
- rs.getString(2);
+ fetchTextColumn(rs, 2);
rs.close();
conn.commit();
+ }
+
+ /**
+ * Make sure the text column is retrieved and read. Different methods
+ * are used for the retrieval based on whether the column is a VARCHAR,
+ * a BLOB or a CLOB.
+ */
+ private void fetchTextColumn(ResultSet rs, int column) throws SQLException {
+ if (dataType == Types.VARCHAR) {
+ rs.getString(column);
+ } else if (dataType == Types.CLOB) {
+ rs.getClob(column).getSubString(1, SingleRecordFiller.TEXT_SIZE);
+ } else if (dataType == Types.BLOB) {
+ rs.getBlob(column).getBytes(1, SingleRecordFiller.TEXT_SIZE);
+ } else {
+ throw new IllegalArgumentException();
+ }
}
}
Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/perf/clients/SingleRecordUpdateClient.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/perf/clients/SingleRecordUpdateClient.java?rev=650112&r1=650111&r2=650112&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/perf/clients/SingleRecordUpdateClient.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/perf/clients/SingleRecordUpdateClient.java Mon Apr 21 04:38:10 2008
@@ -24,6 +24,7 @@
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
+import java.sql.Types;
import java.util.Random;
/**
@@ -54,7 +55,8 @@
public void init(Connection c) throws SQLException {
for (int i = 0; i < pss.length; i++) {
- String tableName = SingleRecordFiller.getTableName(tableSize, i);
+ String tableName =
+ SingleRecordFiller.getTableName(tableSize, i, Types.VARCHAR);
String sql = "UPDATE " + tableName + " SET TEXT = ? WHERE ID = ?";
pss[i] = c.prepareStatement(sql);
}