mysql callablestatement_mysql jdbc性能优化之mybatis/callablestatement调用存储过程mysql jdbc产生不必要的元数据查询(已解决,cpu负...

INFO | jvm 1 | 2016/08/25 15:17:01 | 16-08-25 15:17:01 DEBUG pool-1-thread-371dao.ITaskDao.callProcedure: ==> Preparing: call sp_one( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? );

INFO | jvm 1 | 2016/08/25 15:17:01 | 16-08-25 15:17:01 DEBUG pool-1-thread-371 dao.ITaskDao.callProcedure: ==> Parameters: 9999(Integer), 9901(Integer),=(String), task(String), T(String), 1000(Integer), sysL.1.19(String), 13(Integer), 469047(Integer), 20160825(Integer), 151700(Integer)

INFO | jvm 1 | 2016/08/25 15:17:01 | 16-08-25 15:17:01 DEBUG pool-1-thread-371.dao.ITaskDao.callProcedure: <== Total: 1

INFO | jvm 1 | 2016/08/25 15:17:01 | 16-08-25 15:17:01 DEBUG pool-1-thread-371dao.ITaskDao.callProcedure: <== Updates: 0

mysql general_log中可以发现如下元数据查询语句:

SELECT name, type, comment FROM mysql.proc WHERE name like...

SHOW FUNCTION STATUS LIKE 'sp_one'

SHOW PROCEDURE STATUS LIKE 'sp_one'

SHOW CREATE PROCEDURE `db-name`.`sp_one`

CALL sp_one()

因为我们使用了大量的存储过程,而且很多过程执行非常快,因此导致查询这些元数据本身成了响应时间中很大的一部分,如下所示:

179b83699983254c74625595720682a8.png

根据https://www.percona.com/blog/2006/08/02/mysql-prepared-statements/所述,mysql的Prepare Statements目前好像只能如此,原生mysql jdbc驱动也没支持改进。MariaDB Connector/J倒是进行了优化。

需要使用最古老的

stmt = conn.createStatement();

rs = stmt.executeQuery("call sp_one('a','b')");才能解决该问题。

mybatis的实现中,CALLABLE直接调用了callablestatement,没法直接运行,如下:

CallableStatement cs = (CallableStatement)statement;

cs.execute();

int rows = cs.getUpdateCount();

看来目前只能使用mariadb connector了,就怕这不稳定要么有特定bug存在。。。

我们使用的mysql connector版本是5.1.34。希望后续版本能够优化掉问题。

=============

170222更新

这个最近我们已经解决了,在jdbc.url连接串中增加选项如下:

cachePrepStmts=true

cacheCallableStmts=true

cacheServerConfiguration=true

useLocalSessionState=true

elideSetAutoCommits=false

alwaysSendSetIsolation=false

enableQueryTimeouts=false

useConfigs=maxPerformance有bug https://bugs.mysql.com/bug.php?id=70785等待下一版本发布解决。

如下,大量日志都没有了

2017-02-22T18:47:51.004298+08:00 31744 Query SELECT * FROM `c3potest`

2017-02-22T18:47:51.004677+08:0031753 QuerySELECT * FROM `c3potest`

2017-02-22T18:47:51.840092+08:0030929 QuerySELECT * FROM `c3potest`

2017-02-22T18:47:51.840828+08:0030929 Querycall prl_QueryUniteQuitiesPosition(

7777,77770002,'YWQzYzM3ZTlkOTNjYzFlNzJjNWEzNzUzNDc2OGUyYTI=','101.69.255.190:41723>=ld-web','7',806003,'actL.2.7',7777,0,' ',0,'',0,'',0,0,@com_mysql_jdbc_outparam_p_error_code,@com_mysql_jdbc_outparam_p_error_info

)

2017-02-22T18:47:51.846647+08:0030929 QuerySELECT @com_mysql_jdbc_outparam_p_error_code,@com_mysql_jdbc_outparam_p_error_info

2017-02-22T18:47:51.847462+08:0030929 QuerySELECT * FROM `c3potest`

2017-02-22T18:47:52.001402+08:0031753 Queryselect * from tb_sys_task

2017-02-22T18:47:52.003294+08:0031744 Queryselect unix_timestamp()

最新版本的5.1.41已经发布,意味着可以使用useConfigs=maxPerformance了,同时,elideSetAutoCommits因为bug被弃用。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值