单线读取PHP,例如Dart或nodejs
我有一个服务a
功能相当有限的功能:当客户端请求时,它只是将请求发送到服务b
。这可能需要花费很多时间:Service A
等待Service B
大多数时间(〜99%)的响应。如果我从头开始编写它,我会使用一些单线程环境(例如Dart或Node),但问题在于它是用PHP编写的。因此,每个HTTP请求都会产生一个子过程,并且每个请求都使用一个CPU。因此,没有充分的理由使用大量的CPU:他们每个人只需等待Service b
的响应。
相反,我宁愿有一个带有一个线程的过程,例如在nodejs中:
那么,我的问题是,当仅使用单个CPU时,我该如何实现这种nodejs的行为?
我已经检查了一些异步库,例如swoole,reactphp,amphp等,但是它们大多提到多路复用,例如当我有几个并发请求时,我可以同时发送,而不是顺序发送它们。但这不是我需要的。
那么,我有什么选择?
I have a service A
with pretty limited functionality: when clients request it, it just sends a request to service B
. It can take quite some time: service A
waits for a response from service B
most (~99%) of the time. If I'd written it from scratch, I would have used some single-threaded environment like dart or node, but the problem is that it's written in php. So a child process is spawned per each http request, and each of them utilizes one CPU. So huge amount of CPUs is utilized for no good reason: each of them just waits for a response from service B
.
Here is an image elaborating on what I have:
Instead, I'd rather have a single process with a single thread, like in NodeJS:
So, my question is how can I achieve this nodeJS-like behavior, when only single CPU is used?
I've checked some async libraries like swoole, reactphp, amphp, etc, but they mostly mention multiplexing, like when I have several concurrent requests and I can send them concurrently, not sequentially. But it's not what I need.
So, what options do I have?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论