swoole-bundle icon indicating copy to clipboard operation
swoole-bundle copied to clipboard

Use cooperative scheduling in request handling by enabling swoole coroutine hooks for IO functions

Open Rastusik opened this issue 3 years ago • 2 comments

Is your feature request related to a problem? Please describe. Current architecture of the swoole bundle expects the swoole http server process to handle exactly one request at once. I would like to enable cooperative scheduling by enabling the swoole IO functions coroutine hooks to be able to handle multiple requests concurrently, as the usage if Swoole was intended by design.

Describe the solution you'd like The bundle should have a configuration option (e.g. cooperative_scheduling) which would enable concurrent request processing. I'm currently doing research and figuring out how to do it, I've identified these pin points:

  • to be able to use standard Syfony and Doctrine code, Swoole hooks for PHP IO functions need to be enabled (https://www.swoole.co.uk/docs/modules/swoole-coroutine-enableCoroutine)
  • a context manager for stateful Symfony services in DI container needs to be implemented (something like this https://www.swoole.co.uk/article/isolating-variables-with-coroutine-context)
  • maybe there should be some kind of concurrent request limiter implemented so php wouldn't run out of memory, but I'm not sure yet... or at least the default memory limit should be higher as usual, because in this mode, only one swoole web process should be sufficient to squeeze out the complete performance of a CPU core instead of multiple processes in the current implementation

Describe alternatives you've considered I don't see any alternatives here, except the current implementation, feel free to discuss

Additional context Nope

Rastusik avatar Jul 31 '21 21:07 Rastusik

@k911 I was finally able to get some time to create a working POC, what do you think about it? Btw. is this project still maintained?

Rastusik avatar Dec 12 '21 19:12 Rastusik

@Rastusik looks good for me. Currently, I don't develop anything so we might say it's not maintained properly.

k911 avatar Dec 12 '21 19:12 k911