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

Add LimitConcurrentRequestsMiddleware to limit how many next handlers can be executed concurrently #272

Merged
merged 6 commits into from
Dec 9, 2017

Conversation

clue
Copy link
Member

@clue clue commented Dec 7, 2017

The new ~~~LimitHandlersMiddleware (name subject to discussion / change)~~~ LimitConcurrentRequestsMiddleware allows consumers to limit how many next handlers can be executed concurrently. This can be useful in a streaming context, where the number of concurrent buffers have to be limited. Or if can be used to avoid concurrent execution of handlers entirely. See also README changes for more details.

Accordingly, this functionality is also a requirement for implementing a buffering server (via #259). This allows you to limit this so that for example up to 100 requests with a maximum of 2 MiB each can be buffered and may take up to 200 MiB concurrently.

In a follow-up PR, we will eventually implement similar logic to limit total memory consumption instead. This will allow a higher concurrency under the reasonable assumption that many requests are way below a given limit (see #255).

Supersedes / closes #218, thanks @WyriHaximus!
Refs #194
Refs #259

@clue clue added this to the v0.8.0 milestone Dec 7, 2017
$pending--;
$that->processQueue();

throw $error;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to cause build errors on PHP versions below 7: https://travis-ci.org/reactphp/http/jobs/313201152#L517

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, updated to explicitly reject() in case the rejection value is not an Exception: https://github.com/reactphp/http/pull/272/files#diff-ab60bdad04437904e8a3c3e4c8eff52fR137 :shipit:

$once = $this->expectCallableOnce();
$deferred = new Deferred(function () use ($once) {
$once();
throw new RuntimeException('Cancelled');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duh, updated invalid reference just now :shipit:

@clue clue changed the title Add LimitHandlersMiddleware to limit how many next handlers can be executed concurrently Add LimitConcurrentRequestsMiddleware to limit how many next handlers can be executed concurrently Dec 8, 2017
@clue
Copy link
Member Author

clue commented Dec 8, 2017

Rebased to resolve merge conflict with #264 :shipit:

README.md Outdated
]));
```

More sophisticated examples include limiting the total number of of requests
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

of of

*
* This class is used to buffer all events that happen on a given stream while
* it is paused. This allows you to pause a stream and no longer watch for any
* of its events. Once the stream is resumed, all buffered event will be
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all buffered events

* ]));
* ```
*
* More sophisticated examples include limiting the total number of of requests
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

of of

@clue
Copy link
Member Author

clue commented Dec 8, 2017

Thanks for spotting, updated :shipit:

@WyriHaximus
Copy link
Member

🚨 Merge conflicts 🚨

@clue
Copy link
Member Author

clue commented Dec 9, 2017

Rebased to resolve merge conflict now that #274 is in :shipit:

Copy link
Member

@WyriHaximus WyriHaximus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@WyriHaximus WyriHaximus merged commit 262bd0f into reactphp:master Dec 9, 2017
@clue clue deleted the limit-handlers branch December 9, 2017 15:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants