- PHP Client: other versions:
- Overview
- Quickstart
- Installation
- Configuration
- Inline Host Configuration
- Extended Host Configuration
- Authorization and Encryption
- Set retries
- Enabling the Logger
- Configure the HTTP Handler
- Setting the Connection Pool
- Setting the Connection Selector
- Setting the Serializer
- Setting a custom ConnectionFactory
- Set the Endpoint closure
- Building the client from a configuration hash
- Per-request configuration
- Future Mode
- Dealing with JSON Arrays and Objects in PHP
- Index Management Operations
- Indexing Documents
- Getting Documents
- Updating Documents
- Deleting documents
- Search Operations
- Namespaces
- Security
- Connection Pool
- Selectors
- Serializers
- PHP Version Requirement
- Breaking changes from 5.x
- Community DSLs
- Community Integrations
- Reference - Endpoints
- Elasticsearch\Client
- Elasticsearch\ClientBuilder
- Elasticsearch\Namespaces\CatNamespace
- Elasticsearch\Namespaces\ClusterNamespace
- Elasticsearch\Namespaces\IndicesNamespace
- Elasticsearch\Namespaces\IngestNamespace
- Elasticsearch\Namespaces\NodesNamespace
- Elasticsearch\Namespaces\RemoteNamespace
- Elasticsearch\Namespaces\SnapshotNamespace
- Elasticsearch\Namespaces\TasksNamespace
StickyRoundRobinSelector
editStickyRoundRobinSelector
editThis 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.