IIS Web-Garden 强制进程初始化可能吗?

发布于 2024-07-24 05:05:20 字数 476 浏览 6 评论 0原文

我们有一个在 IIS Web 花园中运行的 ASP.Net Web 应用程序,该应用程序配置为分配最多四个进程。 在我们的 Web 应用程序中,第一个访问该站点的用户会导致加载所有缓存的项目。 由于我们在 IIS Web-Garden 中运行,因此最终需要最多四个首次用户为四个 Web-Garden 进程中的每一个进程建立缓存。 这个缓存构建需要 30-40 秒,我们试图让它更快,但不太可能再改进了。

这是不可接受的,我们的任务是始终让每个人都能快速访问网站(无需等待缓存初始化)。 我想采用一种抓取网站来预热缓存的解决方案。 问题是 Web-Garden 功能似乎是一个黑匣子——您无法控制 IIS 是否/何时决定在遇到下一个 HTTP 请求时加载第二个、第三个或第四个进程。

对我来说,这似乎是一个常见问题,但寻找解决方案却收效甚微。 我的问题是,有没有办法通过 HTTP 标头或其他一些构造来给 IIS 一个提示,表明您希望它加载或至少路由到进程 2、3、4 等?

We have an ASP.Net Web Application that is running in an IIS Web-Garden--which is configured to allocate up to four processes. In our Web Application the first user that hits the site causes the loading of all of the cached items. Since we are running in a IIS Web-Garden it ultimately takes up to four first time users to build up the cache for each of the four Web-Garden processes. This cache building takes 30-40 seconds, we've tried to make it faster, but it's unlikely that that can be improved any more.

This is unacceptable, we have been tasked with making the site fast for everyone all the time (no waiting for cache initialization). I would like to employ a solution that crawls the site to pre-heat the cache. The problem is that the Web-Garden feature appears to be a black box--you have no way of controlling if/when IIS will decide to load that 2nd, 3rd or 4th process when hit with the next HTTP request.

To me this seems like a common problem, but searching for a solution has yielded little results. My question is, is there a way through HTTP headers or some other construct to give IIS a hint, that you would like it to load or at least route to process 2,3,4 etc?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

雪落纷纷 2024-07-31 05:05:20

根据 Microsoft 工程师的说法,这在 IIS 6 中是不可能的。但是他们在 IIS 7.5 和 ASP.Net 4.0 中添加了一个新功能,该功能很好地满足了我在这里所寻找的功能。 它称为“preloadProvider”。 下面是一个示例片段(非常酷!)。

http://forums.iis.net/p/1158476/1907392.aspx

由于单个应用程序池可以包含多个应用程序,因此您可以通过在 applicationHost.config 文件中使用以下配置来指定要自动启动的各个应用程序:

<sites>

  <site name="MySite" id="1">

    <application path="/"

         preloadEnabled="true"

         preloadProvider="PrewarmMyCache" >

        <!--  Additional content -->

    </application>

  </site>

</sites>



<!-- Additional content -->



<preloadProviders>

     <add name="PrewarmMyCache"

         type="MyNamespace.CustomInitialization, MyLibrary" />

</preloadProviders>

当 IIS 7.5 服务器冷启动或回收各个应用程序池时,IIS 7.5 使用applicationHost.config 文件中的信息来确定哪些 Web 应用程序需要自动启动。 对于每个标记为自动启动的应用程序,IIS7.5 都会向 ASP.NET 4.0 发送请求,以在应用程序暂时不接受 HTTP 请求的状态下启动该应用程序。 当处于这种状态时,ASP.NET 实例化由 preloadProvider 属性定义的类型(如前面的示例所示)并调用其公共入口点。
您可以通过实现 IProcessHostPreloadClient 接口来创建具有必要入口点的托管自动启动类型,如以下示例所示:

public class CustomInitialization :  System.Web.Hosting.IProcessHostPreloadClient

{

    public void Preload(string[]  parameters)

    {

        // Perform initialization.

    }

}

在 Preload 方法中运行初始化代码并且该方法返回后,ASP.NET 应用程序就准备好处理请求。
通过在 IIS 7.5 和 ASP.NET 4.0 中添加自动启动功能,您现在拥有一种定义明确的方法,可以在处理第一个 HTTP 请求之前执行昂贵的应用程序初始化。 例如,您可以使用新的自动启动功能来初始化应用程序,然后向负载均衡器发出信号,表明该应用程序已初始化并准备好接受 HTTP 流量。

According to the Microsoft engineers this is not possible with IIS 6. However they have added a new feature in IIS 7.5 and ASP.Net 4.0 that has a nice provision for exactly what i'm looking for here. It's called the "preloadProvider". Here is an example snippet below (very cool!).

http://forums.iis.net/p/1158476/1907392.aspx

Because a single application pool can contain multiple applications, you specify individual applications to be automatically started by using the following configuration in theapplicationHost.config file:

<sites>

  <site name="MySite" id="1">

    <application path="/"

         preloadEnabled="true"

         preloadProvider="PrewarmMyCache" >

        <!--  Additional content -->

    </application>

  </site>

</sites>



<!-- Additional content -->



<preloadProviders>

     <add name="PrewarmMyCache"

         type="MyNamespace.CustomInitialization, MyLibrary" />

</preloadProviders>

When an IIS 7.5 server is cold-started or when an individual application pool is recycled, IIS 7.5 uses the information in the applicationHost.config file to determine which Web applications need to be automatically started. For each application that is marked for auto-start, IIS7.5 sends a request to ASP.NET 4.0 to start the application in a state during which the application temporarily does not accept HTTP requests. When it is in this state, ASP.NET instantiates the type defined by the preloadProvider attribute (as shown in the previous example) and calls into its public entry point.
You create a managed auto-start type with the necessary entry point by implementing the IProcessHostPreloadClient interface, as shown in the following example:

public class CustomInitialization :  System.Web.Hosting.IProcessHostPreloadClient

{

    public void Preload(string[]  parameters)

    {

        // Perform initialization.

    }

}

After your initialization code runs in the Preload method and the method returns, the ASP.NET application is ready to process requests.
With the addition of auto-start to IIS 7.5 and ASP.NET 4.0, you now have a well-defined approach for performing expensive application initialization prior to processing the first HTTP request. For example, you can use the new auto-start feature to initialize an application and then signal a load-balancer that the application was initialized and ready to accept HTTP traffic.

你爱我像她 2024-07-31 05:05:20

也许使用 Web 监控工具定期访问您的 Web 应用程序。 除了能够在您的网站出现故障或其他行为不符合预期时向您发送电子邮件/寻呼外,此类工具还可以产生有益的副作用,即根据页面和位置保持您的网络应用程序“热门”该工具将被配置为访问该站点的频率。

理论上,一旦所有请求都被初始化,IIS 就会以循环方式在花园中分配传入的请求。 最有效的方法可能是在应用程序中使用各种 URL 配置监控工具,这些 URL 不等于花园中进程数量的直接倍数 - 否则相同的花园总是会受到相同子集的影响URL 的数量(假设没有其他网站活动)。 不管怎样,如果配置正确,几轮后你的花园应该会很热。

Perhaps use a web monitoring tool to periodically access your web application. In addition to being able to send you an email / page you when your site goes down or otherwise doesn't behave as expected, such tools can have the beneficial side-effect of keeping your web app "hot" based on which pages and at what frequency the tool would be configured to access the site.

In theory, IIS would be allocating the incoming requests in a round-robin fashion across gardens, once they are all initialized. What might work best would be to configure the monitoring tool with a variety of URLs in your app that doesn't amount to a straight multiple of the number of processes in your garden -- otherwise the same gardens would always get hit with the same subset of URLs, assuming no other site activity. Anyway, if configured right, after a few rounds your gardens should all be hot.

无法回应 2024-07-31 05:05:20

微软已经发布了一个模块,它完全可以满足您的要求。 IIS 7.5 的应用程序初始化模块 将通过确保以下各项来解决您的问题:您花园中的服务器将具有热缓存,并在收到真实用户的首页点击时做出响应。

我认为最引人注目的功能是该模块还支持重叠进程回收。 这意味着您可以回收、部署应用程序的新版本并重新启动各个服务器,而不会导致任何用户陷入具有冷缓存的慢速服务器上。 以下教程来自IIS 8.0 包含有关如何启用重叠进程回收的分步方法。

有关更多详细信息,您可以阅读我对类似问题的回答 如何在 IIS 7.5 上预热 ASP.NET MVC 应用程序?

Microsoft has released a module that does exactly what you ask for. The Application Initialization Module for IIS 7.5 will solve your problem by making sure each of the servers in your garden will have hot caches and be responsive when they receive their first page hit from a real user.

The feature I think is most compelling is that this module also enables overlapped process recycling. That means that you can recycle, deploy new versions of your application and restart individual servers without any user getting stuck on a slow server with a cold cache. The following tutorial from IIS 8.0 include a step-by-step approach on how to enable overlapped process recycling.

For more details, you can read my answer to a similar question at How to warm up an ASP.NET MVC application on IIS 7.5?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文