多核/多处理器会提高 Web 服务器的性能吗?

发布于 2024-12-12 20:07:13 字数 115 浏览 4 评论 0原文

NGINX 或 Apache 是否受益于具有以下任一功能的服务器:

  • 多核,或

  • 多处理器?

如果是这样,为什么?

Does NGINX or Apache benefit from a server that has either:

  • Multi-cores, or

  • Multiple processors?

If so, why?

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

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

发布评论

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

评论(3

佼人 2024-12-19 20:07:13

使用多个 CPU/CPU 核心使服务器应用程序有机会并行处理多个客户端连接(和请求)(实现更高的性能)。

在多核 CPU 的世界中,这个问题一直是广泛研究的主题。

有 3 种解决并行性的方法(如多核 CPU):

  1. 使用多个进程;

  2. 在单个进程中使用多个线程;

  3. 在多个进程中使用多个线程。

Apache 已经探索了几种模型,Nginx 正在使用选项 #1。

哪种模型性能更好通常被认为是实现问题(至少在 Unix 下,进程非常轻,因此可以与线程竞争)。

现在,回到我的猜测的问题(基于阅读发布的测试 此处)是,正确的(多线程)Apache 架构应该比多核 CPU 上的 Nginx 具有更好的扩展性。

矛盾的是,这并不意味着 Apache 比 Nginx 更快:它只是意味着在 1、2、3、... 16 个核心上,Apache 的扩展性比 Nginx 更好,而 Nginx 可以处理更多客户端请求:

  • 性能是快(在单核 CPU 上每秒处理更多请求)

  • 可扩展性是指每秒处理更多请求的能力随着 CPU 核心数量的增加,每秒的请求数会增加(理想的是线性扩展:当 CPU 核心数量增加一倍时,每秒的请求数也会增加一倍)。

如果可扩展的服务器每秒的请求数低于不可扩展的服务器的速度,那么在没有性能的情况下进行扩展是毫无意义的(请注意,如果服务器确实可以很好地扩展,那么在某个点上,拥有多个核心应该可以使其执行比无法扩展的服务器更好)。

如果不进行扩展,服务器将无法利用多核 CPU。

未来肯定会由能够正确执行这两项操作的服务器应用程序组成,以便在所有条件下(仅几个核心或多核心)提供最佳性能。

Using several CPUs/CPU-Cores gives server applications the opportunity to process several client connections (and requests) in parallel (achieving higher performance).

In a world of multi-Core CPUs, the question has been subject of extensive research.

There are 3 ways of addressing parallelism (like multi-Core CPUs):

  1. using several processes;

  2. using several threads in a single process;

  3. using several threads in several processes.

Apache has explored several models, and Nginx is using option #1.

Which model performs better is generally considered as being a matter of implementation (at least under Unix where processes are very light so they can compete with threads).

Now, back to the question my guess (based on reading tests published here) would be that the proper (multi-thread) Apache architecture should scale better than Nginx on multi-Core CPUs.

Paradoxally, it does not mean that Apache is faster than Nginx: it just means that on 1, 2, 3, ... 16 Cores, Apache would scale better than Nginx WHILE Nginx would process more client requests:

  • Performance is to be fast (processing more requests per second on a single-Core CPU)

  • Scalability is the ability to process more requests per seconds as the number of CPU Cores grows (the ideal is to scale linearly: doubling the requests per second as you double the number of CPU Cores).

Scaling without performance is pointless if the number of requests per second of the server which scales is inferior to the speed of the server which does not scale (note that if the server REALLY scales well, there's a point where having MANY Cores should make it perform better than the server that does not scale).

Performing without scaling is making a server unable to take advantage of multi-Core CPUs.

The future will certainly be made of server applications which do both correctly, to provide the best performance under all conditions (just a few Cores or many-many Cores).

清醇 2024-12-19 20:07:13

是的。

我想你的问题是哪个更好?

在这种情况下,这是一个相当复杂的问题,但通常我希望多个处理器的性能会更好。

这是描述两者架构的一个很好的答案:
nginx:它是多线程的,但使用多个进程?

Nginx为每个客户端请求启动新进程,因此尽管它不是多线程的(很好......避免了线程问题),但操作系统可以利用多个线程cores/cpu 通过在不同的 cpu 上调度每个进程。

Yes.

I assume your question is whether one or the other is better?

In which case it's a fairly complicated question, but generally I'd expect that multiple processors will perform better.

Here's a good answer describing the architecture of both:
nginx : Its Multithreaded but uses multiple processes?

Nginx fires up new processess for each client request, so although it's not multithreaded (good... avoids threading issues), the operating system can take advantage of multiple cores/cpu's by scheduling each process on a different cpu.

撧情箌佬 2024-12-19 20:07:13

只有多线程系统才能从多核中受益。我知道 Apache 是多线程的,并且它的性能确实会随着多核的增加而提高。通常,如果要完成的工作被分成不需要彼此依赖的小块工作,那么多核的性能会提高。 Apache启动进程来服务Web请求,不同的请求可以在多个核心上并发运行,从而提高性能。如果 NGINX 是单线程的,那么它就不会利用多核。

在这种情况下,多核/多处理器是同一件事。

Only multi-threaded systems will benefit from multi-cores. I know Apache is multi-threaded and its performance does increase with multi-core. Typically performance goes up with multi-core if the work to be done is divided into small chunks of work which do not need to depend on each other. Apache starts processes to serve web requests and different requests can run concurrently on multiple cores, thereby improving performance. If NGINX is single-threaded, then it will not leverage multi-core.

Multi-core/multi-processor are the same thing in this context.

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