简体   繁体   English

应用程序池和工作进程线程之间的关系是什么?

[英]What is the relationship between Application Pools and worker process threads?

I'm troubleshooting restarts in an ASP.NET application. 我正在解决ASP.NET应用程序中的重新启动问题。 The application is restarting about 20 times a day. 该应用程序每天重启大约20次。 We strongly suspect one part of the application because the restarts began when this particular feature when into production. 我们强烈怀疑应用程序的一部分,因为重新启动是在此特定功能投入生产时开始的。 I've added some logging to those pages using the log4net library, but I'm having trouble interpreting the logs. 我使用log4net库为这些页面添加了一些日志记录,但是我在解释日志时遇到了问题。

When an ASP.NET application is running in an Application Pool, does only a single instance of that application run, or will multiple instances of that application run? 当ASP.NET应用程序在应用程序池中运行时,是仅运行该应用程序的单个实例,还是运行该应用程序的多个实例? I know several worker process threads will be spawned. 我知道会产生几个工作进程线程。 What is the relationship of the worker process threads to the application(s) running in the App Pool? 工作进程线程与应用程序池中运行的应用程序的关系是什么?

I am thinking that I may not be interpreting the results correctly if there are multiple applications logging to the same log. 我想如果有多个应用程序记录到同一个日志,我可能无法正确解释结果。 If one is restarted but the other is not, the logs aren't really telling me much about what was happening when the restart occurred. 如果一个重新启动但另一个没有重启,那么日志并没有真正告诉我很多关于重启发生时发生的事情。

UPDATE 1 更新1

Looking at this page , I find the following information: 查看此页面 ,我找到以下信息:

An application pool defines a group of one or more worker processes, configured with common settings that serve requests to one or more applications that are assigned to that application pool. 应用程序池定义一组一个或多个工作进程,这些进程配置有通用设置,这些设置为分配给该应用程序池的一个或多个应用程序提供请求。 Because application pools allow a set of Web applications to share one or more similarly configured worker processes, they provide a convenient way to isolate a set of Web applications from other Web applications on the server computer. 由于应用程序池允许一组Web应用程序共享一个或多个类似配置的工作进程,因此它们提供了一种将一组Web应用程序与服务器计算机上的其他Web应用程序隔离的便捷方法。 Process boundaries separate each worker process; 流程边界将每个工作流程分开; therefore, application problems in one application pool do not affect Web sites or applications in other application pools. 因此,一个应用程序池中的应用程序问题不会影响其他应用程序池中的Web站点或应用程序。

But I am still confused. 但我仍然感到困惑。 I know from experience that I can assign two entirely different applications to use the same App Pool. 我从经验中知道,我可以分配两个完全不同的应用程序来使用相同的应用程序池。 Does that mean that exactly two worker processes will be spawned? 这是否意味着将产生两个工作进程? Or can there be multiple worker processes spawned for the first app, and multiple worker processes spawned for the second app? 或者可以为第一个应用程序生成多个工作进程,并为第二个应用程序生成多个工作进程? If a problem happens in one worker process, can it take down every application running in that App Pool? 如果在一个工作进程中发生问题,是否可以删除该应用程序池中运行的每个应用程序?

UPDATE 2 更新2

From this page about using WinDbg , I found this information (emphasis mine): 这个关于使用WinDbg的页面 ,我发现了这个信息(强调我的):

In IIS 5.x, there is only one Aspnet_wp.exe worker process and one debugger thread. 在IIS 5.x中,只有一个Aspnet_wp.exe工作进程和一个调试器线程。 Consequently, only one debugger can be attached to the Aspnet_wp.exe process at a time. 因此,一次只能将一个调试器附加到Aspnet_wp.exe进程。 This can pose a problem if you're dealing with multiple Web applications on the same machine. 如果您在同一台计算机上处​​理多个Web应用程序,则可能会出现问题。 In IIS 6.0, you can coerce an AppDomain to run in a separate application pool. 在IIS 6.0中,您可以强制AppDomain在单独的应用程序池中运行。 (For more information, see "IIS 5.x Process Model" and "IIS 6.0 Process Model" in Chapter 1.) Separate application pools provide multiple W3wp.exe processes. (有关详细信息,请参阅第1章中的“IIS 5.x进程模型”和“IIS 6.0进程模型”。) 单独的应用程序池提供多个W3wp.exe进程。 Multiple debugger threads are created in these processes (one in each), allowing you to debug more efficiently. 在这些进程中创建了多个调试器线程(每个进程一个),使您可以更有效地进行调试。

This sounds to me like each App Pool gets one w3wp.exe process. 这听起来像每个应用程序池获得一个w3wp.exe进程。 Am I interpreting that right? 我能解释那个吗? And if so, does that still apply in IIS 7.5? 如果是这样,这仍然适用于IIS 7.5吗?

Yes, each application pool is typically a single process 1 , but can contain multiple threads. 是的,每个应用程序池通常是单个进程1 ,但可以包含多个线程。 You can assign multiple sites to an application pool, and those sites will all run under the same process, however they will run under different "app domains", which are security contexts that separate the code of one site from another, even if they're running on the same app pool. 您可以将多个站点分配给应用程序池,这些站点将在同一进程下运行,但是它们将在不同的“应用程序域”下运行,这些安全上下文将一个站点的代码与另一个站点的代码分开,即使它们是'重新在同一个应用程序池上运行。

Two users hitting the site at the same time can run on different threads, meaning they can run concurrently. 两个同时访问该站点的用户可以在不同的线程上运行,这意味着它们可以同时运行。 That means any logging can have values interspersed. 这意味着任何日志记录都可以散布值。 You might want to add a session value to your logging so you can sort based on session. 您可能希望为日志记录添加会话值,以便可以根据会话进行排序。

App pool restarts (recycling) are normal, 20 restarts in a day does not seem unusual. 应用程序池重启(回收)是正常的,一天20次重启似乎并不常见。 They can happen multiple times per day, and IIS controls when app pools are restarted. 它们可以每天发生多次,并且IIS控制何时重新启动应用程序池。 It does this whenever it feels it needs to clean up the pool. 只要感觉需要清理游泳池,它就会这样做。 2 Your applications should be written in such a way as to recover gracefully from this (ie, do not keep anything in session that cannot be easily recreated if the app pool restarts). 2您的应用程序应该以这样的方式编写,以便从中优雅地恢复(即,如果应用程序池重新启动,请不要在会话中保留任何无法轻松重新创建的内容)。

The app pool can also restart when an unhandled exception occurs in your app. 当您的应用中发生未处理的异常时,应用池也可以重新启动。 In that case, you want to address the cause of this. 在这种情况下,您想要解决这个原因。 Such exceptions are usually logged in the event log. 此类异常通常记录在事件日志中。


1 – While you can configure an application pool to have multiple worker processes (this is known as a Web Garden ), this is not a typical (nor generally recommended) configuration in my experience. 1 - 虽然您可以将应用程序池配置为具有多个工作进程(这称为Web Garden ),但根据我的经验,这不是典型(通常也不建议)的配置。

2 – Note that using IIS Manager you can configure an application to log recycle events to the Windows Event Log . 2 - 请注意,使用IIS管理器可以配置应用程序以将回收事件记录到Windows事件日志中 You can also use IIS Manager to set the threshold for when several of the different types of recycle events occur. 您还可以使用IIS管理器设置何时发生多种不同类型的回收事件的阈值。

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

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