WebAPI 第一次调用服务慢
WebAPI Slow first call to service
我遇到了 WCF 问题和启动时间慢的问题,所以我将所有代码切换为使用 WebAPI。虽然启动时间已大幅减少(约 8-15 秒减少到约 2 秒),但我在启动时仍有奇怪的延迟。目前它大约 2 秒,但后续调用始终低于 0.5 秒,直到发生超时。
我检查了所有 ApplicationPool 设置以确保没有任何启动延迟或空闲超时设置。
我发现这个 link Very slow first call to web service which didn't help me - i still get the same speed issue on a cold start. Also found this one First call to web service each day is slow 似乎再次不适用于我。
我在我的 WebAPI 服务上启用了跟踪,发现我的第一次和第二次调用之间的唯一区别是显示 WebHostHttpControllerTypeResolver.GetControllerTypes
的两行。我似乎找不到太多关于此的信息,但这是我能看到的唯一区别。
我可以使用任何其他类型的日志记录来确定实际发生了什么吗?
这是我在问题下方的对话摘要
Well the timeouts are never the same, but the same ballpark...to expand, i publish the server - first call is ~2 seconds - subsequent calls are ~0.5 seconds. After maybe 20 minutes (hard to determine the actual time) the same occurs - ~2 then ~0.5.
20
分钟 - 这是默认的 AppPool 空闲超时(分钟)。所以听起来 IIS 卸载了您的应用程序池,以便下次您在 20
分钟后点击它 "loads it all up again"(不确定它是否重新编译)因此延迟。您可以 0
禁用超时(注意反响)或只是将其设为更大的值。
如果您禁用超时,您可能需要考虑添加一个计划任务以在使用率较低时回收您的应用程序池,也许 1:00 上午或适合您需要的时间。
WCF 笔记
I was having issues with WCF and slow startup times
这也是我的经验(使用 IIS 托管的 WCF),就像我上面提到的,只是为我的 WCF 服务禁用了应用程序池的超时。这让他们保持美好和温暖。此外,当我知道我的系统不会用于允许 IIS 执行一些内务处理时,我每天都有一次 recycle 事件。
托管在 IIS 中的 WCF 就 IIS 而言,只是另一个 IIS 应用程序。 :)
我遇到了 WCF 问题和启动时间慢的问题,所以我将所有代码切换为使用 WebAPI。虽然启动时间已大幅减少(约 8-15 秒减少到约 2 秒),但我在启动时仍有奇怪的延迟。目前它大约 2 秒,但后续调用始终低于 0.5 秒,直到发生超时。
我检查了所有 ApplicationPool 设置以确保没有任何启动延迟或空闲超时设置。
我发现这个 link Very slow first call to web service which didn't help me - i still get the same speed issue on a cold start. Also found this one First call to web service each day is slow 似乎再次不适用于我。
我在我的 WebAPI 服务上启用了跟踪,发现我的第一次和第二次调用之间的唯一区别是显示 WebHostHttpControllerTypeResolver.GetControllerTypes
的两行。我似乎找不到太多关于此的信息,但这是我能看到的唯一区别。
我可以使用任何其他类型的日志记录来确定实际发生了什么吗?
这是我在问题下方的对话摘要
Well the timeouts are never the same, but the same ballpark...to expand, i publish the server - first call is ~2 seconds - subsequent calls are ~0.5 seconds. After maybe 20 minutes (hard to determine the actual time) the same occurs - ~2 then ~0.5.
20
分钟 - 这是默认的 AppPool 空闲超时(分钟)。所以听起来 IIS 卸载了您的应用程序池,以便下次您在 20
分钟后点击它 "loads it all up again"(不确定它是否重新编译)因此延迟。您可以 0
禁用超时(注意反响)或只是将其设为更大的值。
如果您禁用超时,您可能需要考虑添加一个计划任务以在使用率较低时回收您的应用程序池,也许 1:00 上午或适合您需要的时间。
WCF 笔记
I was having issues with WCF and slow startup times
这也是我的经验(使用 IIS 托管的 WCF),就像我上面提到的,只是为我的 WCF 服务禁用了应用程序池的超时。这让他们保持美好和温暖。此外,当我知道我的系统不会用于允许 IIS 执行一些内务处理时,我每天都有一次 recycle 事件。
托管在 IIS 中的 WCF 就 IIS 而言,只是另一个 IIS 应用程序。 :)