SQL Server 2005 和 .NET 之间的延迟
这个问题是上一个问题的后续问题提出问题。
我写了一个简单的程序,如下所示。
string s;
do
{
using (SqlConnection conn = new SqlConnection("POOLEDCONN"))
{
using (SqlCommand cmd = new SqlCommand("", conn))
{
s = (string) cmd.ExecuteScalar();
Code2IncrementPerfomanceCounter
}
}
} while (!string.IsNullOrEmpty(s))
查询返回一个字符串(nvarchar(max),当前最大大小9k),SQL Server和.NET之间存在很大的延迟。 SQL Profiler 说查询的持续时间为 0 毫秒,所以我认为这不是数据库的问题。网络在不到 1 毫秒的时间内做出响应,因此不应是网络问题。
如果我在我们的测试服务器(VMWare,SQL 未虚拟化)上运行此代码,每秒最多将有 600 个循环。该应用程序不会消耗超过 5% 的 cpu。为什么不进展 快点?我必须使用流式传输从 SQL 或其他方式获取数据吗?
提前感谢
This question is an follow-up of an previous asked question.
I've written an simple program who looks like this.
string s;
do
{
using (SqlConnection conn = new SqlConnection("POOLEDCONN"))
{
using (SqlCommand cmd = new SqlCommand("", conn))
{
s = (string) cmd.ExecuteScalar();
Code2IncrementPerfomanceCounter
}
}
} while (!string.IsNullOrEmpty(s))
The query returns an string(nvarchar(max), current maximum size 9k), there is a lot of latency between SQL Server and .NET. The SQL Profiler says that the query has an duration of 0 ms, so I think it isn't the database. The network is responding in less than 1 ms so it shouldn't be the network.
If I run this code on our testserver(VMWare, SQL isn't virtualized) there will be a max of 600 loops per second. The application doesn't consume more than 5 % cpu. Why isn't it going
faster? Must I use streaming to get the data from SQL or something else?
Thanx in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
每秒 600 次调用是每 1.7 毫秒一次调用。如果您的延迟是 1 毫秒,并且 Sql Server 增加了一点,这似乎是一个合理的结果?
600 calls per second is one call per 1.7 ms. If your latency is 1 ms, and Sql Server adds a little to that, that seems like a plausible result?
您需要查看三件不同的事情:
I have three different things you need to look at:
打开和关闭 SQL 连接的成本很高。你能只做一次吗?
Opening and closing the SQL connection is expensive. Can you just do that once instead?