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

Items totally unbalanced between hot, synchronous consumers #8

Open
acrylic-origami opened this issue Jul 15, 2017 · 1 comment
Open

Comments

@acrylic-origami
Copy link
Owner

acrylic-origami commented Jul 15, 2017

It turns out that, thanks to the lack of proactive action to balance items for hot consumers, both HHReactor and AmpReactor suffer from the same issue. In Hack, although the scheduler "is stochastic", in 3.19 it's actually deterministic, which gives one synchronous consumer all the control when racing the others in the foreach-await.

See for yourself:

<?hh
$source = HHReactor\Producer::create(async { for($i = 0; $i < 10; $i++) { await \HH\Asio\later(); yield $i; } });
\HH\Asio\join(\HH\Asio\va(
  async { foreach($source await as $v) printf("Consumer 1: %d\n", $v); },
  async { foreach($source await as $v) printf("Consumer 2: %d\n", $v); }
));

Notice how something like the following is balanced, thanks to random deferral:

<?hh
$source = HHReactor\Producer::create(async { for($i = 0; $i < 10; $i++) { await \HH\Asio\later(); yield $i; } });
\HH\Asio\join(\HH\Asio\va(
  async { foreach($source await as $v) { printf("Consumer 1: %d\n", $v);
    if(round(mt_rand()/getrandmax())) await \HH\Asio\later();
  } },
  async { foreach($source await as $v) { printf("Consumer 2: %d\n", $v);
    if(round(mt_rand()/getrandmax())) await \HH\Asio\later(); 
  } }
));
@acrylic-origami
Copy link
Owner Author

On a side note, this seems to show that Awaitable subscribers are processed in FIFO order despite ready wait handles being processed in LIFO (as of HHVM 3.19 — subject to change).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant