开发者

Overhead of opening connection

When a connection to DB is opened using C# OPEN statement, does that impact the web server performance or onl开发者_开发知识库y the Database? So, how does the repeated opening and closing of the database connection impact the web server and the database. Can somebody please give me some insight on this. Thanks.


Opening a database connection is a relatively expensive operation. Opening database connections can be so expensive that ADO.NET by default enables connection pooling. If you are not using connection pooling then your application is probably going to run slower (decreased response time) and could even hit problems with scalability.

If you are using connection pooling then repeated opening and closing of a SqlConnection does not incur the large overhead of creating a network connection, authenticating with SQL Server, setting any connection specific data (etc.) that occurs without pooling (except on the initial physical connection creation). When Open is called, an existing connection is retrieved from the pool (if available) and when Close is called then connection is returned to the pool.

With connection pooling enabled, I would expect to see a memory increase on both the web and database servers in maintaining the open connections. If you aren't using connection pooling, then you could do some tests to measure what the performance impact is to both servers.

Usually this isn't something you need to worry about — use connection pooling and tune the pool parameters if necessary.


It impacts end-to-end response time, because of stuff going on in both the database and the web server. In short, your web pages will all load more slowly, even under light load.

Throughput-wise, it probably hurts the database more, since it's doing all the authentication work, but that's just a wild guess.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜