From 6cd5dd79bcc928691fcfecc44cac7604201a89a0 Mon Sep 17 00:00:00 2001 From: Aleksandr Denisyuk Date: Wed, 26 Jun 2024 18:06:20 +0300 Subject: [PATCH] Update docs --- docs/index.md | 60 +++++++++++++++++++++++++++++---------------------- 1 file changed, 34 insertions(+), 26 deletions(-) diff --git a/docs/index.md b/docs/index.md index 8a06d62..be7f2dc 100644 --- a/docs/index.md +++ b/docs/index.md @@ -22,7 +22,7 @@ The following strategies are available: ### Random -Random is a strategy where each node has an equal probability of being chosen, regardless of previous selections or the order of nodes. Use [Orangesoft\Throttler\RandomThrottler](../src/RandomThrottler.php) as below: +Random is a strategy where each node has an equal probability of being chosen, regardless of previous selections or the order of nodes. Use [Orangesoft\Throttler\RandomThrottler](../src/RandomThrottler.php) as shown below: ```php pick($collection, [ - 'throttler' => RoundRobinStrategy::class, -]); +$node = $throttler->pick( + collection: $collection, + context: [ + 'throttler' => RoundRobinStrategy::class, + 'counter' => InMemoryCounter::class, + ], +); ``` -[...] +The context parameter `throttler` specifies the class of the strategy to be accessed, while `counter` sets the name for the counter, which will be passed to the `Orangesoft\Throttler\Counter\CounterInterface::next(string $name = 'default'): int` method to avoid conflicts between strategies. ## Balance cluster -[...] +You can add specific node collections to clusters and run the load balancer only for a specific cluster. Configure `Orangesoft\Throttler\Cluster\ClusterPool::class`, where you need to bind the desired strategies to the cluster name, and create the required number of clusters `Orangesoft\Throttler\Cluster\Cluster::class`: ```php balance($pool); +$node = $cluster->balance( + pool: $pool, + context: [ + 'counter' => InMemoryCounter::class, + ], +); ``` -[...] +Note that you can also pass an optional context parameter `counter` with the counter name to avoid conflicts between clusters that use *round-robin based* strategies. ## Guzzle middleware