Open connection overhead

Discussion of open issues, suggestions and bugs regarding Entity Framework support in ADO.NET Data providers
Post Reply
damon.cognito
Posts: 50
Joined: Wed 22 Jul 2009 09:30

Open connection overhead

Post by damon.cognito » Fri 20 Jul 2012 12:19

I have been examining timings in dbmonitor due to slowness in the app. Each time a query is run the following items appear:

Code: Select all

Open Connection (47 - 63ms)
Exeute: SET Search_Path TO public (47 - 62ms)
Close Connection (0 - 15ms)
Not much of an overhead but if you run 10 queries against an instance of the Entity (for example inside a using) it repeats these for each query. So, in this example, if the queries take 125ms to prepare and execute, we get:

query time: 1250ms
connection overhead: 940 - 1400ms
total: 2190 - 2650ms

Is this to do with Linq, Postgresql or the Entity? Is there any way to persist the connection so the open, execute and close are only carried out once?

Using Postgresql 8.4, dotconnect V5.80, C# visual studio 10.

Shalex
Site Admin
Posts: 8245
Joined: Thu 14 Aug 2008 12:44

Re: Open connection overhead

Post by Shalex » Tue 24 Jul 2012 08:46

damon.cognito wrote:Is there any way to persist the connection so the open, execute and close are only carried out once?
Entity Framework opens/closes a connection for each interoperation with a database. But if you open the connection manually, it stays in the opened state until it is closed explicitly.

Example of opening connection for ObjectContext:

Code: Select all

  using (var conext = new MyContext()) {
    conext.Connection.Open();
DbContext:

Code: Select all

  using (var conext = new MyContext()) {
     ((IObjectContextAdapter)сonext).ObjectContext.Connection.Open();

Post Reply