简体   繁体   English

如何在IIS 7.5上预热ASP.NET MVC应用程序?

[英]How to warm up an ASP.NET MVC application on IIS 7.5?

We would like to warm up an ASP.NET MVC application hosted on IIS 7.5 server. 我们想热身IIS 7.5服务器上托管的ASP.NET MVC应用程序。 The warm up module that used to be available at http://forums.iis.net/t/1176740.aspx has been removed since sometime. 以前在http://forums.iis.net/t/1176740.aspx上提供的预热模块已被删除。

The application should be warmed up everytime IIS or ASP.NET worker-process restarts for any reason. 每当IIS或ASP.NET工作进程因任何原因重新启动时,应该预热应用程序。 During the warm up period, IIS should return some HTTP status code signifying its warm up state or its inability to serve any clients. 在预热期间,IIS应返回一些HTTP状态代码,表示其预热状态或无法为任何客户端提供服务。

Would creating a executable that navigates through necessary pages in the site via HttpRequests be a good idea? 创建一个可执行文件,通过HttpRequests浏览网站中的必要页面是一个好主意吗? The executable can be triggered from IProcessHostPreloadClient implementation. 可执行文件可以从IProcessHostPreloadClient实现中触发。 Is it possible to configure IIS so that it would only accept requests from localhost and once the executable is done, it can switch over to all clients - but that switch should not trigger an IIS restart (obviously). 是否可以配置IIS以便它只接受来自localhost的请求,一旦可执行文件完成,它就可以切换到所有客户端 - 但是该交换机不应该触发IIS重启(显然)。

Is it possible to use an Visual Studio 2010 - Web Performance Test to warm-up an application instead of creating an manual executable? 是否可以使用Visual Studio 2010 - Web性能测试来预热应用程序而不是创建手动可执行文件? Any other alternatives? 还有其他选择吗?

PS: The application uses Forms Authentication and uses sessions - so maintaining state cookie and other cookies is important. PS:应用程序使用表单身份验证并使用会话 - 因此维护状态cookie和其他cookie非常重要。

UPDATE 1 - We are using .NET Framework 4.0 and Entity Framework (database first) in our application. 更新1 - 我们在我们的应用程序中使用.NET Framework 4.0和Entity Framework(数据库优先)。 The first time hits to EF queries are slow. 首次点击EF查询的速度很慢。 The reason behind the warm up is to get these first time hits out of the way. 热身背后的原因是让这些第一次击中。 We are already using compiled queries at most places and we have implemented pre-compiled views for EF. 我们已经在大多数地方使用了编译查询,并且已经为EF实现了预编译视图。 The size of the model and application is very large and complex. 模型和应用程序的大小非常大且复杂。 Warm up needs to walk through many pages to ensure that compiled and non-compiled EF queries get executed at-least once before any end user gets access to the application. 预热需要遍历许多页面,以确保在任何最终用户访问应用程序之前至少执行一次编译和非编译的EF查询。

Microsoft has released a module that does exactly what you ask for. 微软发布了一个完全符合您要求的模块。 The Application Initialization Module for IIS 7.5 improves the responsiveness of Web sites by loading the Web applications before the first request arrives. IIS 7.5应用程序初始化模块通过在第一个请求到达之前加载Web应用程序来提高Web站点的响应能力。

You can specify a series of Urls that IIS will preload before accepting requests from real users. 您可以在接受来自真实用户的请求之前指定IIS将预加载的一系列Url。 I don't think you can get a true user login expereince, but maybe you can set up simulated pages that does not require login that fulfills the same warmup you ask for? 我不认为您可以获得真正的用户登录,但也许您可以设置不需要登录的模拟页面,以满足您要求的相同热身效果?

The feature I think is most compelling is that this module also enables overlapped process recycling. 我认为最引人注目的功能是该模块还可以实现重叠的流程回收。 The following tutorial from IIS 8.0 include a step-by-step approach on how to enable overlapped process recycling. IIS 8.0以下教程包含有关如何启用重叠进程回收的分步方法。

When IIS detects that an active worker process is being recycled, IIS does not switch active traffic over to the new recycled worker process until the new worker process finishes running all application initialization Urls in the new process. 当IIS检测到正在回收活动工作进程时,IIS不会将活动流量切换到新的回收工作进程,直到新工作进程在新进程中完成所有应用程序初始化Urls的运行。 This ensures that customers browsing your website don't see application initialization pages once an application is live and running. 这可确保浏览您网站的客户在应用程序运行和运行后不会看到应用程序初始化页面。

This IIS Application Initialization module is built into IIS 8.0, but is available for download for IIS 7.5 . 此IIS应用程序初始化模块内置于IIS 8.0中,但可供IIS 7.5下载

您可以查看以下帖子 ,了解IIS 7.5和ASP.NET 4.0中内置的自动启动功能。

Any application that generates a server request for the hosted resources can be used to warm up an IIS process. 任何为托管资源生成服务器请求的应用程序都可用于预热IIS进程。 Exactly how many requests you need depends on what parts need warming up. 确切地说,您需要多少个请求取决于需要预热的部件。 Typically, warm-up is used for: 通常,预热用于:

  • Starting up a worker process. 启动工作进程。 For this, you only need to ask for one resource to warm up a process for the entire application. 为此,您只需要请求一个资源来为整个应用程序预热一个进程。
  • Perform any static initialization, database startup, or pre-caching. 执行任何静态初始化,数据库启动或预缓存。 Anything you do in your Global.asax file will happen when you do your first request, so if you can make all of your initialization happen then, you'll still only need to make one page request. 您在第一次请求时会在Global.asax文件中执行任何操作,因此如果您可以进行所有初始化,则仍然只需要发出一个页面请求。
  • Force pre-compilation of ASP.NET pages. 强制预编译ASP.NET页面。 For this to happen you would need to hit every page. 为此,您需要点击每一页。 Fortunately, this is typically not much of a time cost, so you likely don't need to worry about it. 幸运的是,这通常不是一个时间成本,所以你可能不需要担心它。 If you do have individual pages that load slowly, you can warm them up separately. 如果您确实有单独的页面加载缓慢,您可以单独加热它们。

The "warm-up" process here isn't anything magical. 这里的“热身”过程并不神奇。 You just need force IIS to serve the URL in question. 您只需要强制IIS来提供相关URL。 Everything you mentioned would take care of that: using a stress-test tool to query the URL, writing a custom utility to post HTTP requests, even just scripting out a tool like 'wget' or a PowerShell script to download the URLs would do it. 你提到的所有内容都会照顾到这一点:使用压力测试工具查询URL,编写自定义实用程序来发布HTTP请求,甚至只需编写“wget”或PowerShell脚本等脚本来下载URL就可以了。

As far as restricting access to localhost, as far as I know, within IIS, the only way to change that requires you to restart IIS. 至于限制访问localhost,据我所知,在IIS中,唯一的方法是更改​​它需要重新启动IIS。 You could always build a pre-request hook into your application and maintain the state there, and have your warm-up process query some specific URL that toggles that state to "open". 您总是可以在应用程序中构建预请求挂钩并在那里维护状态,并让您的预热过程查询一些特定的URL,将该状态切换为“打开”。 But I'm not sure what you would accomplish. 但我不确定你会完成什么。 If, somehow, a user did try to query your site before your warm-up finished, all that would happen is your site would take a long time to respond, then they would eventually get the page they asked for. 如果用户确实在热身结束之前尝试查询您的网站,那么所有这一切都会发生,您的网站需要很长时间才能回复,然后他们最终会获得他们要求的网页。 If you locked them out of the site during warm-up, they would instead get a browser network error that claimed the site was offline, which (to me) sounds much worse. 如果你在热身期间将他们锁定在网站之外,他们会得到一个浏览器网络错误,声称该网站处于脱机状态,这对我来说听起来更糟糕。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM