Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[💡 FEATURE REQUEST]: Concurrent connection handling #17

Open
azjezz opened this issue Nov 29, 2021 · 3 comments
Open

[💡 FEATURE REQUEST]: Concurrent connection handling #17

azjezz opened this issue Nov 29, 2021 · 3 comments
Labels

Comments

@azjezz
Copy link

azjezz commented Nov 29, 2021

Note: This feature would only be possible using tcp/unix relay.


we the arrival of Fiber in PHP 8.1, writing async code within a traditional PHP application is extremely easy.

for example:

use Psl\Shell;
use Psl\Async;

$output = Shell\execute('command', ['arg', 'arg2']);

[$output1, $output2] = Async\concurrent([
  fn() => Shell\execute('command', ['arg', 'arg2']),
  fn() => Shell\execute('command', ['arg', 'arg2'])
]);

this code works as you would expect regardless of the runtime, available extension, or application/framework.

one neat thing about it, is that even tho Shell\execute returns a string, it's an async function, meaning while waiting for the output, any other callback in the event loop can be executed!

now assume we have the following scenario in roadrunner worker.

  1. roadrunner receives a payload
  2. the application starts running to provide a response
  3. the application calls Shell\execute which might take a minute to finish
  4. roadrunner worker will need to wait until Shell\execute is finished, before responding, and being able to handle any new connections.

This in my opinion is a waste of time!

roadrunner could have used to time Shell\execute took waiting to accept new connections, start it up, and then go back to the previous one!

I attempted to create a PoC of what a worker/pool scenario like this would look like.

and here, we have 8 workers, each capable of handling 100 concurrent connections ( configurable ), accepting and handling 800 jobs ( were each job executes $ sleep 1 ), in just 4 seconds!

If we would attempt to do the same with roadrunner, it would take 100 seconds!

image


For this feature to land in roadrunner-worker, there's going to be alot of BC breaks, one of which is the removal of stdin/stdout relay support, as that wouldn't be easy to handle.

I wanted to share this feature idea here as it could help provide better performance of end users.

If interested in seeing how Really\Pool and Really\worker work, i can push it to GitHub, but for now it's just another toy project for me locally 😋 see: https://github.com/azjezz/really


Note: the examples above use azjezz/psl 2.0.x branch.

@wolfy-j
Copy link

wolfy-j commented Nov 29, 2021

We are already talking about the async pool internally! Thank you for the suggestion!

@azjezz
Copy link
Author

azjezz commented Nov 29, 2021

@azjezz
Copy link
Author

azjezz commented Nov 30, 2021

P.S: update result for running really\worker, it actually takes 4 seconds, not 17 seconds!

The issue was that i was stopping the poll before waiting for workers, this forces the worker to wait for all running jobs, and we are doing this to all workers serial, instead of concurrently, now when waiting concurrently, the result is 4 seconds, 96 seconds less than roadrunner :)

commit with the fix: azjezz/really@018d8c1

@rustatian rustatian transferred this issue from roadrunner-php/worker Sep 7, 2023
@rustatian rustatian changed the title [RFC] concurrent connection handling. [💡 FEATURE REQUEST]: Concurrent connection handling. Jul 11, 2024
@rustatian rustatian changed the title [💡 FEATURE REQUEST]: Concurrent connection handling. [💡 FEATURE REQUEST]: Concurrent connection handling Jul 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants