WebAPI的第一个服务呼叫速度慢 [英] WebAPI Slow first call to service

查看:36
本文介绍了WebAPI的第一个服务呼叫速度慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了WCF和启动时间慢的问题,因此我将所有代码都切换为使用WebAPI.虽然启动时间已大大减少(从约8-15秒减少到了约2),但启动时的延迟仍然很奇怪.当前大约需要2秒钟,但随后的通话持续不到0.5秒钟,直到发生超时.

I was having issues with WCF and slow startup times, so i switched all of my code to use WebAPI. While the startup time has reduced massively (~8-15 seconds down to ~2) I still have an odd latency on startup. Currently its about ~2 seconds but subsequent calls are under 0.5 seconds consistently, until a timeout occurs.

我检查了所有ApplicationPool设置,以确保没有任何启动延迟或空闲超时设置.

I reviewed all of my ApplicationPool settings to ensure there wasn't any startup delays or idle timeout settings.

我找到了此链接第一次访问网络服务非常慢这并没有帮助我-在冷启动时我仍然遇到相同的速度问题.还发现了这一个每天对Web服务的首次呼叫都很慢似乎不适用于我.

I found this 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 again doesn't seem to apply to me.

我启用了对WebAPI服务的跟踪,发现第一次调用和第二次调用之间的唯一区别是两行显示了 WebHostHttpControllerTypeResolver.GetControllerTypes .我似乎对此找不到太多,但这是我唯一能看到的区别.

I enabled tracing on my WebAPI service and found that the only difference between my first and second call are two lines showing WebHostHttpControllerTypeResolver.GetControllerTypes. I can't seem to find too much about this but it is the only difference i can see.

还有其他日志记录可用来确定实际情况吗?

Is there any other sort of logging that i could use to determine what is actually going on?

推荐答案


这是我在问题下方进行对话的摘要


This is a summary of my conversation beneath the question

超时永远不会相同,但是要保持一致……为了扩展,我发布了服务器-第一次调用是〜2秒-后续调用是〜0.5秒.大约20分钟后(很难确定实际时间),同样的情况发生-大约2到大约0.5.

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 分钟后再次点击它时,它将再次加载全部"(不确定是否重新编译),因此产生了滞后.您可以将其设置为 0 以禁用超时(请注意后果),或者只是将其设置为更大的值.

20 minutes - that's the default AppPool Idle Time-out (minutes). So it sounds like IIS unloads your app pool so that the next time you hit it after 20 mins it "loads it all up again" (not sure if it recompiles) hence the lag. You could make it 0 to disable timeout (beware repercussions) or just make it a larger value.

如果您禁用超时,则可能要考虑添加一个计划任务以在使用率较低的时间(例如,凌晨1:00或适合您的时间)回收应用程序池.

If you disable timeout, you might want to consider adding a scheduled task to recycle your app-pool at times of low usage, perhaps 1:00 am or a time suitable for your needs.

我遇到了WCF和启动时间慢的问题

I was having issues with WCF and slow startup times

这也是我的经验(使用IIS托管的WCF),就像我上面提到的,只是禁用了我的WCF服务在应用程序池上的超时.这使他们保持温暖.另外,当我知道我的系统将不会被用来允许IIS做一些内务处理时,我每天都会发生一次回收事件.

This is my experience too (with IIS-hosted WCF) and like I mention above, just disabled the timeout on the app-pools for my WCF services. This keeps them nice and warm. In addition, I have a daily recycle event at a time when I know my system won't be used to allow IIS to do some housekeeping.

由IIS托管的WCF,只是另一个IIS应用程序.:)

WCF hosted in IIS is as far as IIS is concerned, just another IIS app. :)

这篇关于WebAPI的第一个服务呼叫速度慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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