Reputation: 1187
We have an application that has 3 contexts for connecting to 3 SQL Server databases, under the same server.
Our DBAs are arguing that these three connections are being costly for the server.
My question is: is it true? Are three connections more costly than one? How can I measure it?
What is the best practice for dealing with this sittuation on Entity Framework?
Also, we are accessing three databases and our DBAs are arguing we are doing three connections. Is it a coincidence or each context really corresponds to a different connection?
Upvotes: 1
Views: 59
Reputation: 54628
Entity Framework under the hood uses ADO.Net Connection Pooling.
Excerpt:
Connection pooling reduces the number of times that new connections must be opened. The pooler maintains ownership of the physical connection. It manages connections by keeping alive a set of active connections for each given connection configuration. Whenever a user calls Open on a connection, the pooler looks for an available connection in the pool. If a pooled connection is available, it returns it to the caller instead of opening a new connection. When the application calls Close on the connection, the pooler returns it to the pooled set of active connections instead of closing it. Once the connection is returned to the pool, it is ready to be reused on the next Open call.
Pooling connections can significantly enhance the performance and scalability of your application. By default, connection pooling is enabled in ADO.NET. Unless you explicitly disable it, the pooler optimizes the connections as they are opened and closed in your application. You can also supply several connection string modifiers to control connection pooling behavior. For more information, see "Controlling Connection Pooling with Connection String Keywords" later in this topic.
.
Our DBAs are arguing that these three connections are being costly for the server.
He needs to Define costly. If you need 3 connections, you need three connections, you can't just magically reduce the number of connections.
Are three connections more costly than one?
Yes. Everything has a Pro/Con to it. If it simpler to write, maintain and have better performance with 3, it not as simple as just saying 3 vs 1.
What is the best practice for dealing with this sittuation on Entity Framework?
I don't think based on your question (no example contexts, why there are 3 databases, if they are all in use at the same time by the same client or not) it can really be answered in your case.
Upvotes: 2