Jdbc socketRead0 Locked 记一个Mysql的不明bug
在开发人人网海量存储系统Nuclear的过程中,使用到mysql引擎,用了spring+dbcp+jdbc,在压力测试的过程中出现了问题。
在追踪java stack的过程中发现如下的问题:
java.lang.Thread.State: RUNNABLE
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.read(SocketInputStream.java:129)
at com.mysql.jdbc.util.ReadAheadInputStream.fill(ReadAheadInputStream.java:113)
at com.mysql.jdbc.util.ReadAheadInputStream.readFromUnderlyingStreamIfNecessary(ReadAheadInputStream.java:160)
at com.mysql.jdbc.util.ReadAheadInputStream.read(ReadAheadInputStream.java:188)
- locked <0x00002aaab9b2b0d8> (a com.mysql.jdbc.util.ReadAheadInputStream)
at com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:2494)
at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:3005)
at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:2938)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3481)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:919)
at com.mysql.jdbc.MysqlIO.nextRow(MysqlIO.java:1416)
at com.mysql.jdbc.MysqlIO.readSingleRowSet(MysqlIO.java:2883)
at com.mysql.jdbc.MysqlIO.getResultSet(MysqlIO.java:476)
at com.mysql.jdbc.MysqlIO.readResultsForQueryOrUpdate(MysqlIO.java:2576)
at com.mysql.jdbc.MysqlIO.readAllResults(MysqlIO.java:1757)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2167)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2648)
- locked <0x00002aaab9d98790> (a java.lang.Object)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2077)
at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:2228)
- locked <0x00002aaab9d98790> (a java.lang.Object)
at org.apache.commons.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:93)
at org.apache.commons.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:93)
at org.springframework.jdbc.core.JdbcTemplate$1.doInPreparedStatement(JdbcTemplate.java:648)
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:591)
at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:641)
at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:670)
at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:702)
at com.renren.nuclear.storage.MySqlDumpEngine.getListByLeftRight(MySqlDumpEngine.java:198)
其中锁住了tcp的socket,在研究无果的情况下,试着搜了一下,发现已经有人在mysql bugs里提到:
http://bugs.mysql.com/bug.php?id=9515
分析产生bug的原因:
mysql建表的时候使用innoDB,表中有过千万的数据,每次取过多的数据,就会重现。
可能的原因:jdbc在做网络层的时候tcp的buffer不够所致io锁。
最简单的解决办法:
把原来的limit 1000改小,变成了limit 100。
原创文章如转载,请注明:转载自五四陈科学院[http://www.54chen.com]
Posted by 54chen java