Entity Framework Timeslots in SaveChanges
We were getting intermittent timeouts when called SaveChanges
from Entity Framework, I decided to turn Database.Log
on on DbContext
to try and figure out what was going on, the output was as follows:
Opened connection at 5/9/2015 4:56:57 PM +00:00
Started transaction at 5/9/2015 4:56:57 PM +00:00
UPDATE [Search].[IndexingStatuses]
SET [DateTimeLastUpdated] = @0, [IndexStores_IndexStoreId] = @1
WHERE ([CustomerId] = @2)
-- @0: '5/9/2015 4:03:57 PM' (Type = DateTime2)
-- @1: '2' (Type = Int16)
-- @2: '1' (Type = Int32)
-- Executing at 5/9/2015 4:56:57 PM +00:00
-- Completed in 1 ms with result: 1
Failed to commit transaction at 5/9/2015 4:57:13 PM +00:00 with error: Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.
Closed connection at 5/9/2015 4:57:13 PM +00:00
This is very strange, it's a simple update and as you can see the transaction starts at 4:56:57, the update takes 1ms, but for some reason there is a timeout at 4:57:13 which is only 16 seconds later, which is less than our timeout limit anyway.
Does anyone know why we get them periodically?
source to share
I can't say for sure, but it seems like your server is running on very less free memory. One of the following things may work for you:
- Incresing timeout for greater value once. The query may not take long when it runs a second time, since it will already have an execution plan.
-
Delete transaction logs, tempDb data.
-
Use a filter condition in your query to update a smaller dataset at a time.
source to share