MySQL Client在处理简单查询时抛出超时异常

时间:2018-06-26 17:30:59

标签: mysql asp.net-core

我在docker容器中部署了一个asp.net核心应用程序,使用MySQL作为数据库后端;

对于此应用程序,我使用一些简单的SQL查询来获取检索业务数据,并将其定位到具有大约一百万条记录的表。

在大多数情况下,这些查询都可以正常工作,响应速度快,查询计划好 但是,如果应用程序长时间处于“非活动状态”(没有用户正在使用此应用程序),则当重新运行这些查询时,应用程序将卡住。 应用程序日志显示存在超时异常:

fail: Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware[0]
      An unhandled exception has occurred: Timeout expired.  The timeout period elapsed prior to completion of the operation or the server is not responding.
Pomelo.Data.MySql.MySqlException (0x80004005): Timeout expired.  The timeout period elapsed prior to completion of the operation or the server is not responding. ---> System.TimeoutException: Timeout in IO operation
   at Pomelo.Data.MySql.TimedStream.StopTimer()
   at Pomelo.Data.MySql.TimedStream.Read(Byte[] buffer, Int32 offset, Int32 count)
   at Pomelo.Data.Common.BufferedStream.Read(Byte[] buffer, Int32 offset, Int32 count)
   at Pomelo.Data.MySql.MySqlStream.ReadFully(Stream stream, Byte[] buffer, Int32 offset, Int32 count)
   at Pomelo.Data.MySql.MySqlStream.LoadPacket()
   at Pomelo.Data.MySql.MySqlStream.ReadPacket()
   at Pomelo.Data.MySql.NativeDriver.GetResult(Int64& affectedRow, Int64& insertedId)
   at Pomelo.Data.MySql.Driver.NextResult(Int32 statementId, Boolean force)
   at Pomelo.Data.MySql.MySqlDataReader.NextResult()
   at Pomelo.Data.MySql.MySqlCommand.ExecuteReader(CommandBehavior behavior)

sql查询如下:

SELECT  *  FROM  orders  WHERE order_period=201806 AND order_type=1 AND sales_type=1 
order by id desc
LIMIT 20 OFFSET 0

查询计划如下:

+----+-------------+--------------------------------------+------------+-------+---------------------------------+---------+---------+------+------+----------+-------------+
| id | select_type | table                                | partitions | type  | possible_keys                   | key     | key_len | ref  | rows | filtered | Extra       |
+----+-------------+--------------------------------------+------------+-------+---------------------------------+---------+---------+------+------+----------+-------------+
|  1 | SIMPLE      | orders                               | NULL       | index | idx1,idx2                       | PRIMARY | 4       | NULL |   40 |      0.5 | Using where |
+----+-------------+--------------------------------------+------------+-------+---------------------------------+---------+---------+------+-----

感谢所有有关该问题的建议和提议

0 个答案:

没有答案