提交 fb16ec9a authored 作者: Thomas Mueller's avatar Thomas Mueller

integrate benchmark

上级 dce45113
...@@ -10,6 +10,7 @@ import java.sql.SQLException; ...@@ -10,6 +10,7 @@ import java.sql.SQLException;
import java.util.Properties; import java.util.Properties;
import org.h2.store.fs.FileSystemDisk; import org.h2.store.fs.FileSystemDisk;
import org.h2.test.bench.TestPerformance;
import org.h2.test.db.TestAutoRecompile; import org.h2.test.db.TestAutoRecompile;
import org.h2.test.db.TestBackup; import org.h2.test.db.TestBackup;
import org.h2.test.db.TestBigDb; import org.h2.test.db.TestBigDb;
...@@ -376,6 +377,7 @@ Roadmap: ...@@ -376,6 +377,7 @@ Roadmap:
} else { } else {
test.runTests(); test.runTests();
} }
TestPerformance.main(new String[]{ "-init", "-db", "1"});
System.out.println("done (" + (System.currentTimeMillis() - time) + " ms)"); System.out.println("done (" + (System.currentTimeMillis() - time) + " ms)");
} }
......
...@@ -47,7 +47,7 @@ public class BenchB implements Bench, Runnable { ...@@ -47,7 +47,7 @@ public class BenchB implements Bench, Runnable {
private BenchB(BenchB master, int seed) throws Exception { private BenchB(BenchB master, int seed) throws Exception {
this.master = master; this.master = master;
random = new Random(seed); random = new Random(seed);
conn = master.db.getConnection(); conn = master.db.openNewConnection();
conn.setAutoCommit(false); conn.setAutoCommit(false);
updateAccount = conn.prepareStatement( updateAccount = conn.prepareStatement(
"UPDATE ACCOUNTS SET ABALANCE=ABALANCE+? WHERE AID=?"); "UPDATE ACCOUNTS SET ABALANCE=ABALANCE+? WHERE AID=?");
......
...@@ -140,7 +140,7 @@ public class BenchC implements Bench { ...@@ -140,7 +140,7 @@ public class BenchC implements Bench {
loadCustomer(); loadCustomer();
loadOrder(); loadOrder();
db.commit(); db.commit();
trace("load done"); trace("Load done");
} }
private void trace(String s) { private void trace(String s) {
...@@ -152,7 +152,7 @@ public class BenchC implements Bench { ...@@ -152,7 +152,7 @@ public class BenchC implements Bench {
} }
private void loadItem() throws Exception { private void loadItem() throws Exception {
trace("load item"); trace("Loading item table");
boolean[] original = random.getBoolean(items, items / 10); boolean[] original = random.getBoolean(items, items / 10);
PreparedStatement prep = db.prepare("INSERT INTO ITEM(I_ID, I_IM_ID, I_NAME, I_PRICE, I_DATA) " PreparedStatement prep = db.prepare("INSERT INTO ITEM(I_ID, I_IM_ID, I_NAME, I_PRICE, I_DATA) "
+ "VALUES(?, ?, ?, ?, ?)"); + "VALUES(?, ?, ?, ?, ?)");
...@@ -177,7 +177,7 @@ public class BenchC implements Bench { ...@@ -177,7 +177,7 @@ public class BenchC implements Bench {
} }
private void loadWarehouse() throws Exception { private void loadWarehouse() throws Exception {
trace("loading warehouses"); trace("Loading warehouse table");
PreparedStatement prep = db.prepare("INSERT INTO WAREHOUSE(W_ID, W_NAME, W_STREET_1, " PreparedStatement prep = db.prepare("INSERT INTO WAREHOUSE(W_ID, W_NAME, W_STREET_1, "
+ "W_STREET_2, W_CITY, W_STATE, W_ZIP, W_TAX, W_YTD) " + "VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?)"); + "W_STREET_2, W_CITY, W_STATE, W_ZIP, W_TAX, W_YTD) " + "VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?)");
for (int id = 1; id <= warehouses; id++) { for (int id = 1; id <= warehouses; id++) {
...@@ -209,7 +209,7 @@ public class BenchC implements Bench { ...@@ -209,7 +209,7 @@ public class BenchC implements Bench {
} }
private void loadCustomer() throws Exception { private void loadCustomer() throws Exception {
trace("load customers"); trace("Load customer table");
int max = warehouses * districtsPerWarehouse; int max = warehouses * districtsPerWarehouse;
int i = 0; int i = 0;
for (int id = 1; id <= warehouses; id++) { for (int id = 1; id <= warehouses; id++) {
...@@ -298,7 +298,7 @@ public class BenchC implements Bench { ...@@ -298,7 +298,7 @@ public class BenchC implements Bench {
} }
private void loadOrder() throws Exception { private void loadOrder() throws Exception {
trace("load orders"); trace("Loading order table");
int max = warehouses * districtsPerWarehouse; int max = warehouses * districtsPerWarehouse;
int i = 0; int i = 0;
for (int wId = 1; wId <= warehouses; wId++) { for (int wId = 1; wId <= warehouses; wId++) {
...@@ -369,7 +369,7 @@ public class BenchC implements Bench { ...@@ -369,7 +369,7 @@ public class BenchC implements Bench {
} }
private void loadStock(int wId) throws Exception { private void loadStock(int wId) throws Exception {
trace("load stock (warehouse " + wId + ")"); trace("Loading stock table (warehouse " + wId + ")");
boolean[] original = random.getBoolean(items, items / 10); boolean[] original = random.getBoolean(items, items / 10);
PreparedStatement prep = db.prepare("INSERT INTO STOCK(S_I_ID, S_W_ID, S_QUANTITY, " PreparedStatement prep = db.prepare("INSERT INTO STOCK(S_I_ID, S_W_ID, S_QUANTITY, "
+ "S_DIST_01, S_DIST_02, S_DIST_03, S_DIST_04, S_DIST_05, " + "S_DIST_01, S_DIST_02, S_DIST_03, S_DIST_04, S_DIST_05, "
......
...@@ -160,7 +160,6 @@ class Database { ...@@ -160,7 +160,6 @@ class Database {
if (tokenizer.hasMoreTokens()) { if (tokenizer.hasMoreTokens()) {
db.password = tokenizer.nextToken().trim(); db.password = tokenizer.nextToken().trim();
} }
System.out.println("Loaded successfully: " + db.name);
return db; return db;
} catch (Exception e) { } catch (Exception e) {
System.out.println("Cannot load database " + dbString + " :" + e.toString()); System.out.println("Cannot load database " + dbString + " :" + e.toString());
...@@ -176,12 +175,15 @@ class Database { ...@@ -176,12 +175,15 @@ class Database {
Connection getConnection() { Connection getConnection() {
return conn; return conn;
} }
/** /**
* Open a database connection. * Open a new database connection. This connection must be closed
* by calling conn.close().
*
* @return the opened connection
*/ */
void openConnection() throws SQLException { Connection openNewConnection() throws SQLException {
conn = DriverManager.getConnection(url, user, password); Connection conn = DriverManager.getConnection(url, user, password);
if (url.startsWith("jdbc:derby:")) { if (url.startsWith("jdbc:derby:")) {
// Derby: use higher cache size // Derby: use higher cache size
Statement stat = null; Statement stat = null;
...@@ -206,6 +208,14 @@ class Database { ...@@ -206,6 +208,14 @@ class Database {
JdbcUtils.closeSilently(stat); JdbcUtils.closeSilently(stat);
} }
} }
return conn;
}
/**
* Open the database connection.
*/
void openConnection() throws SQLException {
conn = openNewConnection();
stat = conn.createStatement(); stat = conn.createStatement();
} }
......
...@@ -205,8 +205,7 @@ public class TestPerformance { ...@@ -205,8 +205,7 @@ public class TestPerformance {
// } // }
// writer.println("</table>"); // writer.println("</table>");
System.out.println("Test finished"); // System.exit(0);
System.exit(0);
} }
private void testAll(ArrayList dbs, ArrayList tests, int size) throws Exception { private void testAll(ArrayList dbs, ArrayList tests, int size) throws Exception {
...@@ -217,17 +216,19 @@ public class TestPerformance { ...@@ -217,17 +216,19 @@ public class TestPerformance {
// calls garbage collection // calls garbage collection
TestBase.getMemoryUsed(); TestBase.getMemoryUsed();
Database db = (Database) dbs.get(i); Database db = (Database) dbs.get(i);
System.out.println("testing " + db.getName()); System.out.println("Testing performance of " + db.getName());
db.startServer(); db.startServer();
Connection conn = db.getConnection(); Connection conn = db.openNewConnection();
runDatabase(db, tests, 1); runDatabase(db, tests, 1);
runDatabase(db, tests, 1); runDatabase(db, tests, 1);
collect = true; collect = true;
runDatabase(db, tests, size); runDatabase(db, tests, size);
conn.close(); conn.close();
db.log("Executed Statements", "#", db.getExecutedStatements()); db.log("Executed statements", "#", db.getExecutedStatements());
db.log("Total Time", "ms", db.getTotalTime()); db.log("Total time", "ms", db.getTotalTime());
db.log("Statement per Second", "#", db.getExecutedStatements() * 1000 / db.getTotalTime()); int statPerSec = db.getExecutedStatements() * 1000 / db.getTotalTime();
db.log("Statements per second", "#", statPerSec);
System.out.println("Statements per second: " + statPerSec);
collect = false; collect = false;
db.stopServer(); db.stopServer();
} }
......
...@@ -55,7 +55,7 @@ public class Build extends BuildBase { ...@@ -55,7 +55,7 @@ public class Build extends BuildBase {
download("ext/mysql-connector-java-5.1.6.jar", download("ext/mysql-connector-java-5.1.6.jar",
"http://repo1.maven.org/maven2/mysql/mysql-connector-java/5.1.6/mysql-connector-java-5.1.6.jar", "http://repo1.maven.org/maven2/mysql/mysql-connector-java/5.1.6/mysql-connector-java-5.1.6.jar",
"380ef5226de2c85ff3b38cbfefeea881c5fce09d"); "380ef5226de2c85ff3b38cbfefeea881c5fce09d");
String cp = "bin" + File.pathSeparator + "bin/h2.jar" + File.pathSeparator + String cp = "temp" + File.pathSeparator + "bin/h2.jar" + File.pathSeparator +
"ext/hsqldb-1.8.0.7.jar" + File.pathSeparator + "ext/hsqldb-1.8.0.7.jar" + File.pathSeparator +
"ext/derby-10.4.1.3.jar" + File.pathSeparator + "ext/derby-10.4.1.3.jar" + File.pathSeparator +
"ext/derbyclient-10.4.1.3.jar" + File.pathSeparator + "ext/derbyclient-10.4.1.3.jar" + File.pathSeparator +
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论