I have an asp.net core application deployed inside the docker container, using MySQL as database backend;
For this application, I use some simple SQL query to get retrieve business data, target to the table with about half a million records.
In most of time, these queries work fine with fast response speed and good query plan However, if the application is “inactive” (no user is using this application) for a long period of time, when these queries is re-run, the application get stuck. The application log shows that there is a timeout exception:
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)
The sql query as follow:
SELECT * FROM orders WHERE order_period=201806 AND order_type=1 AND sales_type=1
order by id desc
LIMIT 20 OFFSET 0
The query plan as follow:
+----+-------------+--------------------------------------+------------+-------+---------------------------------+---------+---------+------+------+----------+-------------+
| 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 |
+----+-------------+--------------------------------------+------------+-------+---------------------------------+---------+---------+------+-----
All the suggestions and offers for the question are appreciated
User contributions licensed under CC BY-SA 3.0