第一次调用 WCF 服务是否会花费大量时间?
我有一个 WCF 服务操作,它只对 SQL 数据库执行 LINQ 查询,查找具有匹配 Guid 的 35 条记录中的 1 条(这真的很简单)。当我从一个简单的沙箱应用程序调用此方法时,它会立即返回。但是,当我让它在 Windows 服务中运行时,对该方法的第一次调用大约需要 25 秒(我在调用之前和之后获取时间戳),而第二次调用(在各方面与第一次调用相同,在调用之后立即进行)第一个,仅用于测试目的)立即返回。
该调用发生在 ThreadPool.QueueUserWorkItem 委托内部,在其之前和之后执行其他操作,并且它是整个委托中唯一完全延迟的事情。
延迟是否有意义,或者这里出了什么问题?
更新: 我已经确认问题不在于方法本身。我首先调用了一个完全不同的服务方法,该方法有一定的延迟,并且在立即执行之后对原始方法的两次调用。因此,确实是对服务器的第一次调用导致了问题。
I've got a WCF service operation that just does a LINQ query on a SQL database, looking up 1 of 35 records that have a matching Guid (it's really as simple as it gets). When I call this method from a simple sandbox application, it comes back right away. However, when I have it running in a windows service, the first call to the method takes about 25 seconds (I take a timestamp before and after the call), and the second call (identical in every way to the first, made immediately after the first, just for testing purposes) comes back right away.
The call takes place inside of a ThreadPool.QueueUserWorkItem delegate, with other actions being performed before and after it, and it's the only thing in the entire delegate that is at all delayed.
Does the delay make sense, or is something going wrong here?.
Update:
I've confirmed that the problem isn't with the method itself. I called a completely different service method first, which had that delay, and the two calls to the original method just after both execute instantaneously. So it really is whatever the first call to the server is that's causing the problem.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在您的情况下,第一个调用将执行两件事:
这可以解释其中的差异。在某些系统上,第一个调用可能会超时,而第二个调用只需要一两秒。
In your case the first call will do 2 things:
This can explain the difference. On some systems the first call can timeout, while the second takes only one or two seconds.
您可能想要检查的一件事是查看托管服务的 ASP.NET 工作进程是否有“空闲超时”,在我看来,可能是 ASP.net 的初始启动导致了您的问题。
One thing you might want to check is to see if your ASP.NET Worker Process that is hosting the service has an "idle timeout", it to me seems like it is the initial startup of ASP.net that might be causing your issue.
您是否尝试过启用 WCF 跟踪?查找活动边界中的滞后情况流程操作活动。
Have you tried enabling WCF tracing? Look for lags in the activity boundaries in the Process action activity.