如果我使用 PHP,如何解决 c10k 问题?

发布于 2024-11-10 02:24:47 字数 314 浏览 1 评论 0原文

我正在决定一个应用程序的架构,其中“Http KeepAlive”和“长轮询”将用于更快的响应。 PHP 是否有任何东西可以解决 Tornado 为 c10k 带来的问题?

我正在考虑使用nginx + PHP-FPM。但是,对于 1000 个活动连接,不是有 1000 个 PHP-FPM 进程吗?

然后我认为我们会遇到与 Apache 相同的问题,即许多常设连接。不是吗?

编辑:我知道如果我只想要 HTTP KeepAlive,nginx 就足够了。但是如果我也想要像龙卷风一样的长轮询支持怎么办? PHP中有类似的东西吗?

I am deciding on the architecture of an application where "Http KeepAlive" and "long polling" will be used for faster response. Is there anything for PHP which solves the problem that Tornado does for c10k?

I was thinking of using nginx + PHP-FPM. But then, for 1000 active connections, won't there be 1000 PHP-FPM processes?

Then I think we'll have the same problem that Apache has with many standing connections. Isn't it?

EDIT: I understand that nginx will be enough if I just want HTTP KeepAlive. But what if I also want long polling like tornado supports? Is there anything similar in PHP?

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

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

发布评论

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

评论(3

柠檬心 2024-11-17 02:24:47

对于活动连接(例如,加载并运行定义的 PHP 脚本),是的,活动 连接的 PHP 进程数量相同。但 KeepAlive 是关于被动连接的,Nginx 非常擅长以非常低的资源使用量处理被动 KeepAlive 连接 - 即使是数千个连接。

Apache 的问题在于,在 mod_php 和 mpm_prefork 的通常配置中,每个连接都需要一个进程,即使它只是被动的 KeepAlive。这意味着大多数 Apache 服务器实际上确实需要在内存中拥有 PHP 进程,即使连接是被动的,但如果您将 PHP 作为 FastCGI 运行,则情况并非如此。如果您将 PHP 作为 FastCGI 运行并选择 mpm_worker,Apache 还可以处理大量被动连接,这将为每个连接创建一个更轻量级的线程,但它仍然不如 Nginx。

For active connections (as in, loading and running a defined PHP script), yes, there will be as many PHP processes as active connections. But KeepAlive is about passive connections, and Nginx is very good at handling passive KeepAlive connections with very low resource usage - even for thousands of them.

The problem with Apache is that it, in the usual configuration with mod_php and mpm_prefork, needs a process for each connection even if it's just a passive KeepAlive. This means that most Apache servers in fact do need to have a PHP process in memory even if the connection is passive, but this is not the case if you run PHP as FastCGI. Apache can also handle lots of passive connections if you run PHP as FastCGI and choose the mpm_worker which will create a more lightweight thread per connection, but it's still not as good as Nginx.

阳光的暖冬 2024-11-17 02:24:47

我对此的回答是看一下 node.js,您指定 Node.js 应该有 100K 活动连接只要你有正确的硬件就可以很好地处理。

建立连接时,节点不会生成新进程,套接字被放置在排队系统中,但它不是典型的排队系统,其中处理 1 个连接,然后处理下一个连接。

Node.js 因处理大量连接而臭名昭著,并且 HTTP 客户端库基于 Keep-Alive 风格的传输,并且速度非常快且功能强大。

我已经使用过它相当多了,我必须说它非常容易使用,它基于用于 Chrome 中 JavaScript 的超快速 Google V8 引擎,这意味着它非常快,你真的应该看看这个,然后你会发现它对于这类事情是可行的。

My answer to this would be to take a look at node.js, You specify a 100K Active connections which Node.js should handle fine as long as you have the correct hardware.

Node does not spawn new processes when a connection is made, the socket is placed in a queuing system but it's not a typical queuing system, where 1 connection is processed and then the next one.

Node.js is notorious at handling many many connection's and there HTTP Client Library is based on Keep-Alive style of transferring, as well as being very fast and powerful.

I've used it a fair bit and I must say it's extremely easy to use, it's based on the Super fast Google V8 Engine that's used for the JavaScript in Chrome, meaning it's extremely fast, you should really take a look at this and you will see that it's viable for this sort of thing.

内心旳酸楚 2024-11-17 02:24:47

我不明白你的意思。 c10k 与 Web 服务器(apache、nginx 等)相关,而不与 PHP 相关。

如果您使用 nginx,则不必担心

I don't get what do you mean. the c10k is related to web-server (apache, nginx etc) not to PHP.

If you use nginx you shouldn't worry about it

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