最近两天在作服务的性能测试,为了测试服务的承载能力,须要造不少数据。起初想用存储过程造数据,可是因为涉及到不少关联表,写存储过程比较蛋碎。因而使用Spring + MyBatis + Gradle 以程序的方式来造数据。java
顺便表扬一下springboot,实在太方便了。spring
最开始为了图省事,开个for 循环,而后挨条插入数据,1万条数据,关联插入了3张表,耗时超过35分钟。springboot
以为这样太慢,因而将单条屡次插入,改为了批量插入,2万条数据,1分钟不到,就插入完毕。性能
这个真是泪流满面啊。测试
送上MyBatis SQL 吧ui
单条插入code
@Insert("INSERT into TABLE_XX(ID, UUID, X1, X2, X3) " + "VALUES" + "(#{id}, #{uuid}, #{x1}, #{x2}, #{x3})" ) void insertTableXX(TableXXPo po);
批量插入:ip
@Insert({ "<script>", "INSERT into TABLEXX(ID, UUID, X1, X2, X3) ", "VALUES", "<foreach collection='list' item='po' open='(' separator='),(' close=')' >", "#{po.id}, #{po.uuid}, #{po.x1}, #{po.x2}, #{po.x3}", "</foreach>", "</script>" }) void insertTableXXList(List<TableXXPo> poList);
MyBatis 的 这种注解式写法,注意检查,容易报错误。
it