-
-
Notifications
You must be signed in to change notification settings - Fork 8
Description
This project should provide a Throttle
class that can be used to limit the throughput to X elements in Y seconds. This can be used in a piping context with or without a Transformer
like this:
$throttle = new Throttle(10, 3600, $loop);
$input->pipe($throttle)->pipe($transformer)->pipe($output);
I've started working on a prototype implementation and it seems to work quite well, but I'd like to flesh out a decent API and address some subtle edge cases before filing this here. For example, do we also need a ReadThrottle
or WriteThrottle
decorator for readable/writable streams respectively? Also, by throttling before piping to the Transformer
, we may end up sending too many requests anyway, so this might be better suited as part of the Transformer
instead?
See also clue/reactphp-mq#14 for similar implementation ideas.
IMHO this mechanism should be independent of a "bandwidth" mechanism, i.e. it should only limit full elements instead of accepting a string
data stream that will be broken down into the appropriate number of bytes per time frame. There's definitely also room for this implementation, but I don't see a lot of cohesion with the rest of this package, so this might be better off in a separate package.