最近开发的应用开始做性能测试。在小于80用户并发的时候一切OK,并发量到100用户时,持续压5分钟。应用开始报错,并且只有1次错误,持续时间长,比如10分钟,会报3次。

日志如下:

Caused by: com.ibatis.common.jdbc.exception.NestedSQLException:

--- The error occurred in DomainSQL.xml.

--- The error occurred while applying a parameter map.

--- Check the contact.addContact-InlineParameterMap.

--- Check the statement (update failed).

--- Cause: java.sql.SQLException: Lock wait timeout exceeded; try restarting transaction

at com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.executeUpdate(GeneralStatement.java:91)

at com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.insert(SqlMapExecutorDelegate.java:447)

at com.ibatis.sqlmap.engine.impl.SqlMapSessionImpl.insert(SqlMapSessionImpl.java:82)

at org.springframework.orm.ibatis.SqlMapClientTemplate$8.doInSqlMapClient(SqlMapClientTemplate.java:366)

at org.springframework.orm.ibatis.SqlMapClientTemplate.execute(SqlMapClientTemplate.java:200)

... 82 more

Caused by: java.sql.SQLException: Lock wait timeout exceeded; try restarting transaction

at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1073)

at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3597)

at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3529)

at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1990)

at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2151)

at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2625)

at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2119)

at com.mysql.jdbc.PreparedStatement.execute(PreparedStatement.java:1362)

at org.apache.commons.dbcp.DelegatingPreparedStatement.execute(DelegatingPreparedStatement.java:168)

at com.ibatis.sqlmap.engine.execution.SqlExecutor.executeUpdate(SqlExecutor.java:81)

at com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.sqlExecuteUpdate(GeneralStatement.java:200)

at com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.executeUpdate(GeneralStatement.java:78)

... 86 more

MySQl数据库是InnoDB模式。

报错的方法:addContact,执行的是Insert语句, 查了一下,据怀疑是操作的表被其他线程锁定,引起插入超时。

检查代码该表的操作有select,insert,update操作,update是根据主键进行的。 select有关联其他表做查询,但确认没有 “for update ”。 郁闷中,不知道什么原因了?希望能得到点线索。谢谢

有两个疑问:

1.Lock wait timeout exceeded; try restarting transaction 是什么原因造成的?

2.MySQl数据库是INNODB模式,默认是行级锁,什么情况下会出现锁表呢?

2011年11月29日 19:22

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐