第一次调用 WCF 服务是否会花费大量时间?

发布于 2024-09-25 14:06:46 字数 422 浏览 4 评论 0原文

我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

我是有多爱你 2024-10-02 14:06:46

在您的情况下,第一个调用将执行两件事:

  • JIT 编译服务
  • 在数据库服务器中缓存查询/数据

这可以解释其中的差异。在某些系统上,第一个调用可能会超时,而第二个调用只需要一两秒。

In your case the first call will do 2 things:

  • JIT compile the service
  • Cache the query / data in the database server

This can explain the difference. On some systems the first call can timeout, while the second takes only one or two seconds.

〆一缕阳光ご 2024-10-02 14:06:46

您可能想要检查的一件事是查看托管服务的 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.

情绪失控 2024-10-02 14:06:46

您是否尝试过启用 WCF 跟踪?查找活动边界中的滞后情况流程操作活动。

Have you tried enabling WCF tracing? Look for lags in the activity boundaries in the Process action activity.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文