如何使 AppDomain 中的 ASP.NET 程序集保持活动状态?

发布于 2024-07-18 08:54:22 字数 396 浏览 8 评论 0原文

场景:我有一个使用 Web 部署项目部署的 n 层企业 ASP.NET 应用程序。 所有层都生成由 ASP.NET 应用程序使用的独立程序集。

问题:当我运行应用程序时。 部署后第一次需要花费大量时间将依赖程序集加载到内存中。 但一旦加载了其闪电般的快速应用程序。 如果没有用户访问该应用程序,IIS 将从内存中卸载程序集,并且当用户尝试在稍后的实例上访问该应用程序时,它会再次加载所有程序集,加载时间与加载时间相同这是第一次这样做。

我正在寻找一种解决方案,使我能够将程序集持久加载到内存中,从而覆盖程序集的易失性以实现内存驻留。

或者任何其他解决方案,让我的用户愉快地使用解决上述问题的应用程序问题。

Scenario: I've an n-Tier enterprise ASP.NET application deployed using Web Deployment Projects. All tiers produce independent assemblies that is consumed by the ASP.NET application.

Problem: When I run the app. for the first time after deployment it takes lot of time to load dependent assemblies in memory. But once loaded its lighting fast app. In case if there are no users accessing the app, IIS unloads the assemblies from the memory and when a user tried to access the app on a later instance it goes on loading all the assemblies once again taking the same amount of time to load as it takes to do so for the first time.

I'm looking for a solution that enables me to keep my assemblies loaded into memory persistently overriding the volatile nature of assemblies towards memory residency.

Or any other solution that lets my users happily use the app resolving the mentioned problem.

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

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

发布评论

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

评论(3

剪不断理还乱 2024-07-25 08:54:22

IIS 6 中,转到“应用程序池”部分,然后右键单击“应用程序池”>“应用程序池”。 托管相关 ASP.NET 应用程序的池的属性。 转到“性能”选项卡并取消选中“闲置后关闭工作进程:”

IIS 7 中,转到“连接”窗格并找到“应用程序池”,然后为托管应用程序的池选择“高级设置”。 找到“空闲超时”属性并将其设置为“0”(这会禁用它)。

默认值为 20 分钟不活动。 通过取消选中该框,一旦您的 AppDomain工作进程,它永远不会死(除非你杀死进程或当然)。 默认情况下,IIS 将

我还编写了一个小型 C# 类,它将让您的 ASP.NET 应用程序保持活动状态 (备用存档版本)在正常情况下。 由于它在应用程序内运行,显然它无法阻止 IIS 或其他任何东西显式终止该进程,但它会使应用程序保持“热”状态,例如应用程序永远不会空闲足够长的时间以使 IIS 决定将其关闭。

如果您无法直接控制 IIS 配置(例如共享主机),您最好的选择是在单独的系统上运行一个小型应用程序 - 例如,一个永远在线的工作站 - 它每 x 分钟访问您的站点以保持应用程序池免于超时。 没什么花哨的 - 一个简单的 WebRequest 和 while()控制台应用程序中的循环就可以了。

In IIS 6, go to the Application Pools section, and right-click > Properties on the pool which hosts the ASP.NET application in question. Go to the Performance tab and uncheck "Shutdown worker processes after being idle for:"

In IIS 7, go to the Connections pane and find Application Pools, and select Advanced Settings for the pool which hosts your application. Find the "Idle Timeout" property and set it to "0" (this disables it).

The default is 20 minutes of inactivity. By unchecking the box, once your AppDomain is loaded by the worker process, it will never die (unless you kill the process or something of course). By default, IIS will recycle the process when it reaches some limit, such as a memory cap, but it will also start a new one and "phase over" all incoming requests until the old one is unused, so as to minimize disruption.

I've also written a small c# class which will keep your ASP.NET application alive (alternate archived version) under normal circumstances. Since it runs within the application, obviously it can't stop IIS or anything else from explicitly killing the process, but it will keep the application "hot", e.g. the app will never go idle long enough for IIS to decide to shut it off.

If you do not have direct control over your IIS configuration (shared host, for example) your best bet is to have a small application running on a separate system - say, an always-on workstation - which hits your site every x minutes to keep the application pool from timing out. Nothing fancy - a simple WebRequest and a while() loop in a console application will do.

鹿港小镇 2024-07-25 08:54:22

ASP .net 的优点之一是可以创建对象的静态(共享)实例。

为了避免外部进程的必要性,您可以在(例如)global.asax 中创建一个静态计时器,它使用简单的 WebRequest 调用域上的页面。 通过这种方式,站点可以自行保持活动状态,直到池的手动重置完成为止。

One of the advantages of ASP .net is the posibility to create static (shared) instances of objects.

To avoid the necessity of an external process you can create an static timer in (per example) global.asax which calls for a page on the domain with a simple WebRequest. On this way the site keeps alive himself until a manual reset of the pool is done.

紫罗兰の梦幻 2024-07-25 08:54:22

我编写了一个小型 C# 控制台应用程序,通过 Windows 任务计划程序使我的 4 个站点每 10 分钟保持活动状态。 生活再次美好起来。 我们不会在凌晨 2 点到 5 点运行应用程序,这样服务器就可以清理内存(如果有必要的话)。 无论如何,对于我们的网站来说,在这些时间里很少有人上网。

I wrote a little C# console application that keeps my 4 sites alive every 10 mins via windows task scheduler. Life is once again good. We do not run the app from 2-5am just so the serves can do any cleanups of memory, if it even matters. for our sites there is rarely anyone on at those hours anyway.

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