IIS 应用程序池/重新启动和 ASP.NET [英] IIS App Pool/Restart and ASP.NET

查看:39
本文介绍了IIS 应用程序池/重新启动和 ASP.NET的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在使用 IIS7 来托管一个基于 web 的 asp.net 应用程序.在这种环境中,管理员和开发人员可以定期将代码部署到应用程序中.

新代码或应用程序作为 DLL 进入 ASP.NET bin 文件夹.部署新 DLL 后,IIS 重新启动进程,影响(减慢)所有在线用户.

有没有办法将 IIS 配置为在后台运行进程,一旦准备好从旧状态切换到新状态而不影响用户?!

提前感谢您的反馈!

解决方案

IIS 已经这样做了,这就是回收的全部意义所在.IT 正在加载 DLL,而旧版本的应用程序仍在运行.只有在完成此操作后,才能完成回收.

但是加载 DLL 只是准备好 Web 应用程序的一部分,也可能会有初始加载,例如加载/缓存用户数据库等.
这些操作不是回收过程的一部分,它们发生在所有 DLL 重新加载并且回收已经完成之后.

不久前,由于启动期间的大量数据库活动/缓存,我遇到了一个应用程序启动时间很长的问题.所以我很感兴趣是否有一些功能允许我们在回收标记为完成之前执行代码,以便在一切准备好运行时首先考虑应用程序回收.基本上我想要的是某种暂存功能.
我就这个问题与 IIS 团队联系过,遗憾的是他们告诉我不存在这样的功能,也没有计划.

要解决此问题,您可以尝试执行以下操作:

  • 使用交替部署:
    您设置了 2 个具有单独应用程序池的网站.其中一个是 LIVE 网站,另一个是 STAGED 网站.如果您想部署更改,您只需部署到 STAGED 网站.在所有内容都加载/缓存等之后,您切换 Web 应用程序的 URL 设置以将传入请求从 LIVE 重新路由到 STAGED 请求.所以现场直播变成了新的舞台表演,反之亦然.然后下一次部署将再次转到新的 STAGED,依此类推.

更新
显然他们现在已经创建了一个 IIS 模块来提供这个功能:

<块引用>

IIS 7.5 的 IIS 应用程序预热模块

IIS 团队发布了第一个 beta 测试版IIS 7.5 的应用程序预热模块.这让你热身应用程序甚至比以前描述的更容易.而不是写自定义代码,您指定要在之前执行的资源的 URLWeb 应用程序接受来自网络的请求.发生这种热身在 IIS 服务启动期间(如果您配置了 IIS应用程序池作为 AlwaysRunning)和 IIS 工作进程时回收.在回收期间,旧的 IIS 工作进程继续执行请求,直到新生成的工作进程完全运行热身,使应用程序不会遇到中断或其他由于未准备好的缓存导致的问题.请注意,此模块适用于任何ASP.NET 版本,从 2.0 版开始.

有关详细信息,请参阅 IIS.net 网站上的应用程序预热.有关说明如何使用预热功能的演练,请参阅IIS 7.5 应用程序预热模块入门IIS.net 网站.

见:

<块引用>

http://www.asp.net/whitepapers/aspnet4

如果您使用 ASP.NET 4 自动启动功能:

<块引用>

您仍然可以选择不时自动回收工作进程时间.但是,当您这样做时,应用程序将立即重新启动并您的热身代码将执行(与今天不同 - 您必须等待为下一个请求执行此操作).

预热和自动启动功能的主要区别在于预热模块是回收过程的一部分.而不是在运行初始化代码时阻止应用程序的请求.
使用自动启动功能唯一的好处是您不必等待用户点击页面,这对您的情况没有帮助.

见顾的博文:

<块引用>

http://weblogs.asp.net/scottgu/archive/2009/09/15/auto-start-asp-net-applications-vs-2010-and-net-4-0-series.aspx

更新 2:

遗憾的是,IIS 7/7.5 的预热模块已经停止:

<块引用>

http://forums.iis.net/t/1176740.aspx

不过它将成为 IIS8 的一部分(现在称为应用程序初始化模块):

<块引用>

http://weblogs.asp.net/owscott/archive/2012/03/01/what-s-new-in-iis-8.aspx

更新 3:

正如评论中指出的,在 IIS 8 发布后,IIS 7.5 的预热模块重新出现为 IIS 7.5 的应用程序初始化模块:

http://www.iis.net/downloads/microsoft/application-initializationp>

We are using IIS7 to host an asp.net web-based application. In this environment administrators and developers can deploy code to the application on a regular basis.

The new code or app goes as a DLL to the ASP.NET bin folder. Upon deployment of the new DLL, IIS restarts the process, impacting (slowing down) all online users.

Is there a way to configure IIS to run the process in the background and once ready make the switch from old state into new without impacting the users?!

Thanks in advance for your feedback!

解决方案

IIS already does this, that's what recycling is all about. IT's loading the DLL's while the old version of the application is still running. only after this is completed the recycling is complete.

However loading the DLL's is only part of getting web applications ready, there might also be initial loads like loading/caching the user db etc.
These actions are not part of the recycle process, they happen after all DLL's reloaded and the recycling is already completed.

A while back I ran into this issue with an application that had a huge startup time due to heavy db activity/caching during startup. So I was interested if there is some functionality that allows us to execute code before the recycle is marked as completed, so that the application is first considered recycled when everything is ready to run. Basically what I wanted is some kind of staging functionality.
I was in contact with the IIS team regarding this issue, sadly they told me that no such functionality exists, nor is it planned.

To solve this you could try do the following:

  • Use alternating deploys:
    You setup 2 Websites with separate application pools. One of them is the LIVE website the other one is the STAGED website. If you want to deploy changed you simply deploy to the STAGED website. After everything is loaded/cached etc. you switch the URL settings of the web applications to reroute incoming requests from the LIVE to the STAGED one. So the LIVE one becomes the new STAGED and the other way around. The next deploy would then go to the new STAGED again and so on.

UPDATE
Apparently they have created a IIS Module that provides this functionality by now:

IIS Application Warm-Up Module for IIS 7.5

The IIS team has released the first beta test version of the Application Warm-Up Module for IIS 7.5. This makes warming up your applications even easier than previously described. Instead of writing custom code, you specify the URLs of resources to execute before the Web application accepts requests from the network. This warm-up occurs during startup of the IIS service (if you configured the IIS application pool as AlwaysRunning) and when an IIS worker process recycles. During recycle, the old IIS worker process continues to execute requests until the newly spawned worker process is fully warmed up, so that applications experience no interruptions or other issues due to unprimed caches. Note that this module works with any version of ASP.NET, starting with version 2.0.

For more information, see Application Warm-Up on the IIS.net Web site. For a walkthrough that illustrates how to use the warm-up feature, see Getting Started with the IIS 7.5 Application Warm-Up Module on the IIS.net Web site.

See:

http://www.asp.net/whitepapers/aspnet4

If you use ASP.NET 4 Auto Start feature:

You can still choose to auto-recycle the worker processes from time to time. When you do that, though, the app will immediately restart and your warm up code will execute (unlike today - where you have to wait for the next request to-do that).

The main difference between Warm Up and Auto Start feature is that the Warm Up Module is part of the recycling process. Rather than blocking the application for requests, while running the init code.
Only thing you get by using the Auto Start feature is that you don't have to wait for a user to hit the page, which does not help your case.

See the Gu's blog post:

http://weblogs.asp.net/scottgu/archive/2009/09/15/auto-start-asp-net-applications-vs-2010-and-net-4-0-series.aspx

UPDATE 2:

Sadly the Warmup Module has been discontinued for IIS 7/7.5:

http://forums.iis.net/t/1176740.aspx

It will be part of IIS8 though (It's now called Application Initialization Module):

http://weblogs.asp.net/owscott/archive/2012/03/01/what-s-new-in-iis-8.aspx

UPDATE 3:

As pointed out in the comments the Warmup Module resurfaced for IIS 7.5 as Application Initialization Module for IIS 7.5 after IIS 8 was released:

http://www.iis.net/downloads/microsoft/application-initialization

这篇关于IIS 应用程序池/重新启动和 ASP.NET的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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