连接池是不是保持一个连接开放慢 [英] Connection pooling is slower than keeping one connection open

查看:190
本文介绍了连接池是不是保持一个连接开放慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我观察连接池在我们创建了一个客户端应用程序性能的一个有趣的现象。以往用户点击的对象上时,更特定于对象的数据从数据库加载。这需要每点击根据不同的对象介于10和30的查询。

I have observed an interesting behavior of the performance of connection pooling in an client application we created. When ever the user clicks on an object, more object specific data is loaded from the database. This takes somewhere between 10 and 30 queries per click depending on the object.

这是通过使用连接池进行,每个查询被派遣从池中新的连接,查询运行后连接被关闭。

This was done by using connection pooling and each query was dispatched on a new connection from the pool and the connection was closed after the query ran.

我已经分析的分析器进行性能优化的查询,发现那里有很多审核登录/注销项。此外表现得不是最佳eventhough在那里运行良好(仅索引查找/扫描操作)查询themselfs。

I have analyzed the queries in the profiler for performance optimization and saw that there where a lot of audit login/logout entries. Additionally the performance was not optimal eventhough the queries themselfs where running well (only index seek/scan operators).

只是为了试图出来我禁用了汇集和修改了代码让每个客户端应用程序,并重新使用一个连接。这使得整个应用程序的更多的反应,所有的审核登录/注销项从探查消失了。

Just for trying it out I disabled the pooling and modified the code to keep one connection per client application and reusing it. This made the entire application a lot more responsive, and all the audit login/logout entries disappeared from the profiler.

这怎么可能?不应连接保持打开或者如果他们真的留在至少开不这样慢?难道我们使用SqlConnection类错误导致禁用池?

How is this possible? Shouldn't the connections stay open or if they actually stay open at least not be this slow? Is it possible that we are using the SqlConnection class wrong resulting in disabled pooling?

我已经阅读了有关池的其他职位,但没有发现任何有关之间的感知速度差。池连接和重用相同的连接

I have read the other posts regarding pooling but have not found anything about a perceivable speed difference between pooling connections and reusing the same connection.

SqlConnection con = new SqlConnection(_connectionString);



的连接被移交到包装类会话,它提供事务性功能。

The connection is handed off to a wrapping class Session which provides transactional functionality.

class Session{
    Session(connection);
    Abort();
    Commit();
}



连接将中止关闭()和commit()。 。其中之一是始终名为

The connection is closed in Abort() and Commit(). One of these is always called.

推荐答案

如果我理解正确 - 连接每个会话是新。如果你希望所有实例共享的连接你应该让静态

If I understand you correctly - the connection is being "new" per session. if you want all instances to share the connection you should make it static.

把它在Global.asax中:

put it in global.asax:

public static SqlConnection con;

protected void Application_Start(object sender, EventArgs e)
{
    con = new SqlConnection(_connectionString);
}

在这样你会分享你的会话之间的连接相同。

in that way you will be sharing the same connection between your sessions.

这篇关于连接池是不是保持一个连接开放慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆