第一个Web API会话请求非常慢 [英] First Web API session request is very slow

查看:232
本文介绍了第一个Web API会话请求非常慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个在IIS7上托管的ASP.NET Web API应用程序(无特殊配置).

I'm writing an ASP.NET Web API application hosted on IIS7 (no special configuration).

我的问题是,对于每个第一个请求(在新的计算机/新的浏览器上/一段时间后...),都会有很长的延迟-即使在返回常量的请求上!

My problem is that for each first request (on a new machine/new browser/after a while...) there is a long delay - even on requests that return constants!

我已经读过有关热身"脚本的信息,但这不是这里的问题.似乎Web服务器正在尝试创建会话,这需要很长时间.有什么建议吗?

I've read about "warming up" scripts but it's not the issue here. It seems like the web server is trying to create a session and it takes very long time. Any suggestions?

编辑

我认为延迟是由每个新会话的工作进程创建引起的.现在的问题是为什么它这么慢,为什么Web服务器不重用活动的工作进程来处理请求?

I think the delay is caused by worker-process creation for each new session. Now the question is why is it so slow, and why doesn't the web server reuse living worker-processes to serve requests?

我已将应用程序池配置为将工作进程限制为5个,且没有超时(设置为0).这导致前五个会话在遇到第一个请求时很慢(我可以接受),而现在工作进程仍处于活动状态.但令人惊讶的是,请求有时又很慢!

I have configured the application pool to limit worker processes to 5 with no timeout (set to 0). This caused the first five sessions to be slow on first requests (which I can live with) and now the worker processes are alive. But surprisingly, from time to time, the request is slow again!

推荐答案

如果您使用的是Windows Server 2008 R2,则可以

If you are using Windows Server 2008 R2 you could configure the Auto-Start feature on the Application Pool. Also in the properties of the application pool you should disable it from being recycled at regular intervals. Bear in mind though that while this will limit the slowness, the application pool could still be recycled by IIS. With the Auto-Start feature it will be loaded again automatically in memory, but the code in your Application_Start will be executed on the next request. So you could still observe some slowness.

这篇关于第一个Web API会话请求非常慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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