为什么Apache Event MPM表现不佳?

时间:2022-01-12 08:07:28

The Event MPM is not exactly the same design as Nginx, but was clearly designed to make keepalives more tenable and sending static files faster. My understanding is that the Event MPM is a bit of a misnomer because:

事件MPM与Nginx的设计并不完全相同,但显然旨在使Keepalive更加稳定并更快地发送静态文件。我的理解是事件MPM有点用词不当,因为:

  1. Although the connection is passed to kqueue/epoll,
  2. 虽然连接传递给kqueue / epoll,

  3. certain very important modules such as mod_gzip and mod_ssl will block/consume a thread until the response is done,
  4. 某些非常重要的模块,如mod_gzip和mod_ssl,将阻塞/使用一个线程,直到响应完成,

  5. and that is an issue for large files, but probably not for PHP-generated HTML documents, etc.
  6. 这对于大文件来说是一个问题,但可能不适用于PHP生成的HTML文档等。

Unfortunately, Apache keeps losing marketshare, and most benchmarks are damning for the event MPM. Are the benchmarks flawed, or does the event MPM really do so poorly against Nginx? Even with these limitations, under normal traffic (non-malicious) and smaller files, it should be somewhat competitive with Nginx. For example, it should be competitive serving PHP-generated documents via php-fpm on slow connections because the document will be buffered (even if being ssl'd and gzip'd) and sent asynchronously. Both SSL and non-SSL connections using compression or not should not work meaningfully differently than they would in Nginx on such a workload.

不幸的是,Apache一直在失去市场份额,大多数基准测试都是MPM事件的诅咒。基准测试是否存在缺陷,或者事件MPM对Nginx的影响是否真的如此糟糕?即使有这些限制,在正常流量(非恶意)和较小的文件下,它应该与Nginx有一定的竞争力。例如,它应该是有竞争力的,通过php-fpm在慢速连接上提供PHP生成的文档,因为文档将被缓冲(即使是ssl'd和gzip)并且异步发送。使用压缩或不使用压缩的SSL和非SSL连接的工作方式与Nginx在此类工作负载上的工作方式不同。

So why does it not shine in various benchmarks? What's wrong with it? Or what's wrong with the benchmarks? Is a major site using it as an appeal to authority that it can perform?

那为什么它不会在各种基准测试中闪耀?它出什么问题了?或者基准测试有什么问题?是一个主要的网站使用它作为它可以执行的权威的诉求?

2 个解决方案

#1


11  

It is slower than nginx because Apache with the event MPM is (very) roughly equivalent to an event-driven HTTP proxy (nginx, varnish, haproxy) in front of Apache with the worker MPM. Event is worker, but rather than handing each new connection to a thread for its lifetime, the event MPM's threads hand the connection to a secondary thread which pushes it onto a queue or closes it if keep-alive is off or has expired.

它比nginx慢,因为带有事件MPM的Apache(非常)大致相当于Apache与工作者MPM之前的事件驱动的HTTP代理(nginx,varnish,haproxy)。事件是工作者,但事件MPM的线程将连接交给一个辅助线程,将其推送到队列或在保持活动关闭或已过期时关闭它,而不是将每个新连接交给一个线程。

The real benefit of event over worker is the resource usage. If you need to sustain 1,000 concurrent connections, the worker MPM needs 1,000 threads, while the event MPM may get by with 100 active threads and 900 idle connections managed in the event queue. The event MPM will use a fraction of the resources of the worker MPM in that hypothetical, but the downside is still there: each of those requests is handled by a separate thread which must be scheduled by the kernel and as such will incur the cost of switching context.

事件超过工人的真正好处是资源使用。如果您需要维持1,000个并发连接,则工作程序MPM需要1,000个线程,而事件MPM可能会在事件队列中管理100个活动线程和900个空闲连接。事件MPM将在该假设中使用工作者MPM的一小部分资源,但缺点仍然存在:每个请求都由一个必须由内核调度的单独线程处理,因此会产生成本转换背景。

On the other hand we have nginx which uses the event model itself as its scheduler. Nginx simply processes as much work on each connection as it can before moving on to the next one. No extra context switching required.

另一方面,我们有nginx,它使用事件模型本身作为其调度程序。 Nginx只需处理每个连接上的尽可能多的工作,然后再继续下一个连接。无需额外的上下文切换。

The one use case where the event MPM really shines is to handle a setup where you have a heavy application running in Apache, and to conserve the resources of threads that are idle during keep-alive, you would deploy a proxy (such as nginx) in front of apache. If your front end served no other purpose (e.g. static content, proxying to other servers, etc...), the event MPM handles that use case beautifully and eliminates the need for a proxy.

事件MPM真正发挥作用的一个用例是处理在Apache中运行繁重应用程序的设置,并且为了节省在保持活动期间空闲的线程的资源,您将部署代理(例如nginx)在阿帕奇面前。如果您的前端没有其他用途(例如静态内容,代理到其他服务器等等),MPM事件可以很好地处理该用例并且无需代理。

#2


4  

To me, the dominating operative differences are that in event:

对我而言,主要的操作差异在于:

  • handlers (plugins responsible for generating the response) are synchronous -- if they are performing either computation or I/O they will tie up a thread
  • 处理程序(负责生成响应的插件)是同步的 - 如果它们执行计算或I / O,它们将占用一个线程

  • the core must use cross-thread locks to protect key data structures because it is multi-threaded to support so many of these synchronous requests
  • 核心必须使用跨线程锁来保护关键数据结构,因为它是多线程的,以支持这么多的这些同步请求

That's why at very high volumes servers like nginx (or Apache Traffic Server or any modern commercial/high performance proxy) usually comes out ahead.

这就是为什么在非常大量的服务器上,例如nginx(或Apache Traffic Server或任何现代商业/高性能代理)通常会出现。

IMO The bullets in your question are a bit off the mark, SSL and deflate are not really contributing much to the differences here as they are both filters that don't really contribute to scalability problems or even tie httpd to its traditional API guarantees about the lifecycle of a request or connection. Filters like these (vs. handlers, or the core filter responsible for the low-level I/O) are probably the least of things tied to the processing model.

IMO你问题中的子弹有点偏离标志,SSL和deflate对这里的差异没有多大贡献,因为它们都是过滤器,它们并没有真正导致可扩展性问题,甚至将httpd与其传统的API保证联系在一起请求或连接的生命周期。像这样的过滤器(与处理程序或负责低级I / O的核心过滤器)可能是与处理模型相关的最少的事情。

But I also don't think it peforms so poorly by comparison for all but the most extreme workloads or extremely constrained systems. Most of the benchmarks I've seen are of extremely poor quality, for one reason or another.

但是,除了最极端的工作负载或极端受限的系统之外,我还认为它的表现并不差。由于种种原因,我见过的大多数基准都质量极差。

I think largely people want what they call a webserver today to be a proxy to a more sophisticated application server (Java EE, PHP, etc) and a server designed to move I/O around most efficiently without API baggage is going to have the edge.

我认为很大程度上人们希望他们今天所谓的网络服务器是更复杂的应用服务器(Java EE,PHP等)的代理,并且设计用于在没有API行李的情况下最有效地移动I / O的服务器将具有优势。

#1


11  

It is slower than nginx because Apache with the event MPM is (very) roughly equivalent to an event-driven HTTP proxy (nginx, varnish, haproxy) in front of Apache with the worker MPM. Event is worker, but rather than handing each new connection to a thread for its lifetime, the event MPM's threads hand the connection to a secondary thread which pushes it onto a queue or closes it if keep-alive is off or has expired.

它比nginx慢,因为带有事件MPM的Apache(非常)大致相当于Apache与工作者MPM之前的事件驱动的HTTP代理(nginx,varnish,haproxy)。事件是工作者,但事件MPM的线程将连接交给一个辅助线程,将其推送到队列或在保持活动关闭或已过期时关闭它,而不是将每个新连接交给一个线程。

The real benefit of event over worker is the resource usage. If you need to sustain 1,000 concurrent connections, the worker MPM needs 1,000 threads, while the event MPM may get by with 100 active threads and 900 idle connections managed in the event queue. The event MPM will use a fraction of the resources of the worker MPM in that hypothetical, but the downside is still there: each of those requests is handled by a separate thread which must be scheduled by the kernel and as such will incur the cost of switching context.

事件超过工人的真正好处是资源使用。如果您需要维持1,000个并发连接,则工作程序MPM需要1,000个线程,而事件MPM可能会在事件队列中管理100个活动线程和900个空闲连接。事件MPM将在该假设中使用工作者MPM的一小部分资源,但缺点仍然存在:每个请求都由一个必须由内核调度的单独线程处理,因此会产生成本转换背景。

On the other hand we have nginx which uses the event model itself as its scheduler. Nginx simply processes as much work on each connection as it can before moving on to the next one. No extra context switching required.

另一方面,我们有nginx,它使用事件模型本身作为其调度程序。 Nginx只需处理每个连接上的尽可能多的工作,然后再继续下一个连接。无需额外的上下文切换。

The one use case where the event MPM really shines is to handle a setup where you have a heavy application running in Apache, and to conserve the resources of threads that are idle during keep-alive, you would deploy a proxy (such as nginx) in front of apache. If your front end served no other purpose (e.g. static content, proxying to other servers, etc...), the event MPM handles that use case beautifully and eliminates the need for a proxy.

事件MPM真正发挥作用的一个用例是处理在Apache中运行繁重应用程序的设置,并且为了节省在保持活动期间空闲的线程的资源,您将部署代理(例如nginx)在阿帕奇面前。如果您的前端没有其他用途(例如静态内容,代理到其他服务器等等),MPM事件可以很好地处理该用例并且无需代理。

#2


4  

To me, the dominating operative differences are that in event:

对我而言,主要的操作差异在于:

  • handlers (plugins responsible for generating the response) are synchronous -- if they are performing either computation or I/O they will tie up a thread
  • 处理程序(负责生成响应的插件)是同步的 - 如果它们执行计算或I / O,它们将占用一个线程

  • the core must use cross-thread locks to protect key data structures because it is multi-threaded to support so many of these synchronous requests
  • 核心必须使用跨线程锁来保护关键数据结构,因为它是多线程的,以支持这么多的这些同步请求

That's why at very high volumes servers like nginx (or Apache Traffic Server or any modern commercial/high performance proxy) usually comes out ahead.

这就是为什么在非常大量的服务器上,例如nginx(或Apache Traffic Server或任何现代商业/高性能代理)通常会出现。

IMO The bullets in your question are a bit off the mark, SSL and deflate are not really contributing much to the differences here as they are both filters that don't really contribute to scalability problems or even tie httpd to its traditional API guarantees about the lifecycle of a request or connection. Filters like these (vs. handlers, or the core filter responsible for the low-level I/O) are probably the least of things tied to the processing model.

IMO你问题中的子弹有点偏离标志,SSL和deflate对这里的差异没有多大贡献,因为它们都是过滤器,它们并没有真正导致可扩展性问题,甚至将httpd与其传统的API保证联系在一起请求或连接的生命周期。像这样的过滤器(与处理程序或负责低级I / O的核心过滤器)可能是与处理模型相关的最少的事情。

But I also don't think it peforms so poorly by comparison for all but the most extreme workloads or extremely constrained systems. Most of the benchmarks I've seen are of extremely poor quality, for one reason or another.

但是,除了最极端的工作负载或极端受限的系统之外,我还认为它的表现并不差。由于种种原因,我见过的大多数基准都质量极差。

I think largely people want what they call a webserver today to be a proxy to a more sophisticated application server (Java EE, PHP, etc) and a server designed to move I/O around most efficiently without API baggage is going to have the edge.

我认为很大程度上人们希望他们今天所谓的网络服务器是更复杂的应用服务器(Java EE,PHP等)的代理,并且设计用于在没有API行李的情况下最有效地移动I / O的服务器将具有优势。