3

We are trying to optimize the performance of our site. We are using glimpse for profiling and debugging. We noticed that the "connection opened" time in glimpse timeline is much higher when compared to the command execution time.

Load and number of connections in DB server seems to be normal. So we couldn't nail down the root cause.

enter image description here

As per Glimpse Timeline, the connection was opened for 381 ms. But the command got executed in 6 ms.

Total query execution time - 430 ms

Total connection open time - 19130 ms

Any idea why this happens?

Note :

Scope of DB Context is the scope of Http request

Number of records returned by these queries are < 1000 (approx)

Community
  • 1
  • 1
Dhivya DD
  • 73
  • 7
  • Is it faster on subsequent queries? If so, could be the view generation occurring. https://msdn.microsoft.com/library/cc853327(v=vs.100).aspx – Steve Greene Jan 19 '16 at 19:03
  • @AlexanderDerck Commands are just select statements, which fetches data from application related tables. Almost all the columns used in where condition are either primary keys or integers values (indexed) Query performance is good. – Dhivya DD Jan 19 '16 at 20:03
  • @SteveGreene Same pattern is repeated for almost all the queries (Its actually worse for few queries) Approximately, 50 queries are executed as part of this http request. – Dhivya DD Jan 19 '16 at 20:03

1 Answers1

0

.Net uses connection pooling and doesn't close connections. The only thing that matters is how long it took the EF method to return back to the caller. Do you have the DBContext instance in a "using" block to let .Net know to release it?

Bruce Dunwiddie
  • 2,888
  • 1
  • 15
  • 20
  • We are using shared DB Context - Single DB context across the app. DBContext will be created when http request hits the controller and it will be disposed when controller Action gets executed (By the end of http request) – Dhivya DD Jan 20 '16 at 05:51
  • why are you using a shared db context? – Bruce Dunwiddie Jan 20 '16 at 17:34