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

integrate benchmark

上级 dce45113
......@@ -10,6 +10,7 @@ import java.sql.SQLException;
import java.util.Properties;
import org.h2.store.fs.FileSystemDisk;
import org.h2.test.bench.TestPerformance;
import org.h2.test.db.TestAutoRecompile;
import org.h2.test.db.TestBackup;
import org.h2.test.db.TestBigDb;
......@@ -376,6 +377,7 @@ Roadmap:
} else {
test.runTests();
}
TestPerformance.main(new String[]{ "-init", "-db", "1"});
System.out.println("done (" + (System.currentTimeMillis() - time) + " ms)");
}
......
......@@ -47,7 +47,7 @@ public class BenchB implements Bench, Runnable {
private BenchB(BenchB master, int seed) throws Exception {
this.master = master;
random = new Random(seed);
conn = master.db.getConnection();
conn = master.db.openNewConnection();
conn.setAutoCommit(false);
updateAccount = conn.prepareStatement(
"UPDATE ACCOUNTS SET ABALANCE=ABALANCE+? WHERE AID=?");
......
......@@ -140,7 +140,7 @@ public class BenchC implements Bench {
loadCustomer();
loadOrder();
db.commit();
trace("load done");
trace("Load done");
}
private void trace(String s) {
......@@ -152,7 +152,7 @@ public class BenchC implements Bench {
}
private void loadItem() throws Exception {
trace("load item");
trace("Loading item table");
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) "
+ "VALUES(?, ?, ?, ?, ?)");
......@@ -177,7 +177,7 @@ public class BenchC implements Bench {
}
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, "
+ "W_STREET_2, W_CITY, W_STATE, W_ZIP, W_TAX, W_YTD) " + "VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?)");
for (int id = 1; id <= warehouses; id++) {
......@@ -209,7 +209,7 @@ public class BenchC implements Bench {
}
private void loadCustomer() throws Exception {
trace("load customers");
trace("Load customer table");
int max = warehouses * districtsPerWarehouse;
int i = 0;
for (int id = 1; id <= warehouses; id++) {
......@@ -298,7 +298,7 @@ public class BenchC implements Bench {
}
private void loadOrder() throws Exception {
trace("load orders");
trace("Loading order table");
int max = warehouses * districtsPerWarehouse;
int i = 0;
for (int wId = 1; wId <= warehouses; wId++) {
......@@ -369,7 +369,7 @@ public class BenchC implements Bench {
}
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);
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, "
......
......@@ -160,7 +160,6 @@ class Database {
if (tokenizer.hasMoreTokens()) {
db.password = tokenizer.nextToken().trim();
}
System.out.println("Loaded successfully: " + db.name);
return db;
} catch (Exception e) {
System.out.println("Cannot load database " + dbString + " :" + e.toString());
......@@ -178,10 +177,13 @@ class Database {
}
/**
* 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 {
conn = DriverManager.getConnection(url, user, password);
Connection openNewConnection() throws SQLException {
Connection conn = DriverManager.getConnection(url, user, password);
if (url.startsWith("jdbc:derby:")) {
// Derby: use higher cache size
Statement stat = null;
......@@ -206,6 +208,14 @@ class Database {
JdbcUtils.closeSilently(stat);
}
}
return conn;
}
/**
* Open the database connection.
*/
void openConnection() throws SQLException {
conn = openNewConnection();
stat = conn.createStatement();
}
......
......@@ -205,8 +205,7 @@ public class TestPerformance {
// }
// 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 {
......@@ -217,17 +216,19 @@ public class TestPerformance {
// calls garbage collection
TestBase.getMemoryUsed();
Database db = (Database) dbs.get(i);
System.out.println("testing " + db.getName());
System.out.println("Testing performance of " + db.getName());
db.startServer();
Connection conn = db.getConnection();
Connection conn = db.openNewConnection();
runDatabase(db, tests, 1);
runDatabase(db, tests, 1);
collect = true;
runDatabase(db, tests, size);
conn.close();
db.log("Executed Statements", "#", db.getExecutedStatements());
db.log("Total Time", "ms", db.getTotalTime());
db.log("Statement per Second", "#", db.getExecutedStatements() * 1000 / db.getTotalTime());
db.log("Executed statements", "#", db.getExecutedStatements());
db.log("Total time", "ms", db.getTotalTime());
int statPerSec = db.getExecutedStatements() * 1000 / db.getTotalTime();
db.log("Statements per second", "#", statPerSec);
System.out.println("Statements per second: " + statPerSec);
collect = false;
db.stopServer();
}
......
......@@ -55,7 +55,7 @@ public class Build extends BuildBase {
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",
"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/derby-10.4.1.3.jar" + File.pathSeparator +
"ext/derbyclient-10.4.1.3.jar" + File.pathSeparator +
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论