ASP.NET Web Garden - 我需要多少个工作进程?
决定 ASP.NET Web 应用程序允许多少个工作进程的最佳实践是什么?
在我管理的一台服务器上,创建新的 AppPool 默认为 10 个(最多)工作进程。其他人建议正常设置是之一。
多个工作进程解决什么问题以及决定多少个工作进程的技术是什么?
What is the best practice for deciding how many worker processes to allow for an ASP.NET web application?
On one server I manage, creating a new AppPool defaults to 10 (maximum) worker processes. Other people suggest that the normal setting is one.
What problem does multiple worker processes solve and what are the techniques for deciding on how many?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
工作进程是一种将网站的执行分段到多个 exe 中的方法。这样做有几个原因,其中之一是如果其中一个工作人员因运行时问题而崩溃,则不会影响其他工作人员。例如,如果传入的 html 请求导致进程无果而终,那么只有该工作处理器正在处理的其他请求才会被终止。另一个例子是,一个请求可能会导致同一工作线程处理的其他线程阻塞。
至于你需要多少,做一些负载测试。大力使用该应用程序,看看仅使用一个应用程序会发生什么。然后再添加一些,然后再次点击。在某个时刻,您将达到机器网络、磁盘、CPU 和 RAM 真正饱和的程度。那时您就知道自己达到了适当的平衡。
顺便说一句,您可以通过 machine.config 文件控制每个工作进程使用的线程数。我相信关键是 maxWorkerThreads。
现在,请注意,如果您使用会话,则会话状态不会在工作进程之间共享。我通常建议无论如何都要避免会议,但这是需要考虑的事情。
出于所有意图和目的,您可以将每个工作进程视为它自己的独立 Web 服务器。只不过它们在同一个盒子上运行。
Worker processes are a way of segmenting the execution of your website across multiple exe's. You do this for a couple of reasons, one if one of the workers gets clobbered by run time issues it doesn't take the others down. For example, if a html request comes in that causes the process to run off into nothing then only the other requests that are being handled by that one worker processor get killed. Another example is that one request could cause blocking against the other threads handled by the same worker.
As far as how many you need, do some load testing. Hit the app hard and see what happens with only one. Then add some more to it and hit it again. At some point you'll reach a point of truly saturating the machines network, disk, cpu, and ram. That's when you know you have the right balance.
Incidentally, you can control the number of threads used per worker process via the machine.config file. I believe the key is maxWorkerThreads.
Now, beware, if you use session, Session state is not shared between worker processes. I generally recommend avoiding session anyway but it is something to consider.
For all intents and purposes you might consider each worker process as it's own separate web server. Except they are running on the same box.
内存泄漏
另一个最大的优点是处理内存泄漏。有时,您多么努力地优化代码,但框架本身和其他第三方库都存在内存泄漏。我们注意到,最终我们的应用程序达到了非常高的内存,并且开始没有出现内存异常。
因此,我们必须将工作进程的最大虚拟内存限制设置为 1GB 之类,并允许多个进程运行。即使对于单个工作进程,您也可以设置最大虚拟限制,但这会导致速度急剧下降,因为当工作进程被回收时,所有请求都会变慢,直到工作进程获得良好的速度。由于我们的应用程序具有内部缓存(实体框架查询缓存、一些对象池),因此这些都会减慢应用程序的启动速度。这是单个工作进程最受伤害的地方。
如果有多个工作进程,只有其中一个处于回收模式的进程速度较慢,但其他进程仍保持良好的速度。
Memory Leaks
The other biggest advantage is handling memory leaks. Sometimes how much ever you try to optimize your code, but there are memory leaks in the framework itself and other third party libraries. We noticed that eventually our application reaches very high memory and starts giving no memory exceptions.
So we had to set a max virtual memory limit on worker process to like 1GB and allow multiple processes to run. You could set max virtual limit even for single worker process, but this leads to a spikes of slow down, as when worker process is recycled, all requests are slow till the time worker process gains good speed. As our application has internal caching (Entity Framework Query Cache, some object pools), each of these things slows down starting of application. This is where single worker process hurts the most.
If there are multiple worker processes, only one of the process in recycle mode is slow, but others do keep good speed.
拥有许多工作进程有意义的另一种情况是,如果您的应用程序包含阻止其并行化的锁。基于 GDI+ 的图像处理就是示例之一。
当我试图寻找 的解决方案时,我发现了它我的问题。
Another case when it makes sense to have many worker processes is if your application contains locks that prevent its parallelization. GDI+ based image processing is one of examples.
I found it when I tried to find solution for my problem.