StickyRoundRobinSelectoredit

This selector is "sticky", in that it prefers to reuse the same connection repeatedly. For example, Node #1 is chosen on the first request. Node #1 will continue to be re-used for each subsequent request until that node fails. Upon failure, the selector will round-robin to the next available node, then "stick" to that node.

This is an ideal strategy for many PHP scripts. Since PHP scripts are shared-nothing and tend to exit quickly, creating new connections for each request is often a sub-optimal strategy and introduces a lot of overhead. Instead, it is better to "stick" to a single connection for the duration of the script.

By default, this selector will randomize the hosts upon initialization, which will still guarantee an even distribution of load across the cluster. It changes the round-robin dynamics from per-request to per-script.

If you are using Future Mode, the "sticky" behavior of this selector will be non-ideal, since all parallel requests will go to the same node instead of multiple nodes in your cluster. When using future mode, the default RoundRobinSelector should be preferred.

If you wish to use this selector, you may do so with:

$client = ClientBuilder::create()
            ->setSelector('\Elasticsearch\ConnectionPool\Selectors\StickyRoundRobinSelector')
            ->build();

Note that the implementation is specified via a namespace path to the class.