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?