|

几个性能关键点:
- 一定要开事务 JDBC PreparedStatement.addBatch() 批量添加;
- JPA、JDO 要注意及时 detach 被 ORM 框架管理的对象;
- 有的库支持 L2 cache,关掉会提升性能;
- 参数绑定时的 Java bean 反射影响性能;
软件包版本:
- JDK 17, macOS 12.5.1, H2 2.1.214
- JDBI 3.34.0
- MyBatis 3.5.11
- Ebean 13.10.0
- JPA 3.1 + Hibernate 6.1.4.Final
- JDO 3.2.1 + DataNucleus 5.2.12
- jOOQ 3.17.4
没想到 jOOQ 性能这么差:
public static void runJOOQ(String engine, int count, int batch) throws SQLException {
try ( Connection conn = DriverManager.getConnection(DB_URL.formatted(engine), DB_USER, DB_PASS)) {
conn.setAutoCommit(false);
DSLContext create = DSL.using(conn, SQLDialect.H2);
List<UserJourneyRecord> records = new ArrayList<>(batch);
for (int i = 1; i <= count; ++i) {
//records.add(create.newRecord(USER_JOURNEY, newUserJourney(i)));
records.add(newUserJourneyRecord(i));
if (i % batch == 0) {
create.transaction(c -> c.dsl().batchInsert(records).execute());
//create.batchInsert(records).execute();
records.clear();
}
}
if (!records.isEmpty()) {
create.transaction(c -> c.dsl().batchInsert(records).execute());
//create.batchInsert(records).execute();
}
}
}
jOOQ 的代码规模非常大,测试用例没开源…… |
|