We have an application which gives every impression of being bottlenecked on poor database response. Neither the database nor the application server are heavily loaded, but the application is spending considerable time making queries via ExecuteReader.
We are measuring two things: batch and statement duration in SQL Server Profiler, and the time between invoking ExecuteReader and disposing it. Consumption of the data is 'trivial' ie. simply reading data into a list of dictionaries.
Duration recorded by the Profiler is often considerably less than that recorded by the application. These queries return only a few rows (usually one) so the time taken to consume the resultset should be tiny. But we've seen instances of a 150ms query (as recorded by the profiler) being recorded as over 1700ms by the application.
Environment:
- It's not our infrastructure.
- It's live, so we can't attach a profiler/debugger.
- The application server at least is virtualised. The DB is a cluster.
- SQL Server 2008R2 and Windows Server 2008R2.
An obvious culprit is network latency, but ping
indicates that latency from app to DB server is consistently less than 1ms.
The connection is reused for multiple queries, so Open()-time overhead should already have been accounted for separately. I would expect this to rule out authentication delays during ExecuteReader, but perhaps I'm wrong about that?
What other things should we investigate? What other things might ExecuteReader wait upon?
SqlConnection
that is opened and then multipleSqlCommand
s are executed using that connection without closing it between each query. This is fine as it is the same thing as multiple batches viaGO
in SSMS. – Solomon Rutzky