elastic / elasticsearch-rs

Official Elasticsearch Rust Client
https://www.elastic.co/guide/en/elasticsearch/client/rust-api/current/index.html
Apache License 2.0
705 stars 72 forks source link

[ENHANCEMENT] Implement Single Node Connection pool #7

Closed russcam closed 4 years ago

russcam commented 4 years ago

The client send function currently delegates to Connection's send function

    pub fn send<B, Q>(
        &self,
        method: HttpMethod,
        path: &str,
        query_string: Option<&Q>,
        body: Option<B>,
    ) -> Result<ElasticsearchResponse, ElasticsearchError>
    where
        B: Serialize,
        Q: Serialize + ?Sized,
    {
        self.connection.send(method, path, query_string, body)
    }

This is a seam to implement connection pooling.

A connection pool is a pool of nodes that the client knows about, to which an API request can be sent. The simplest type of connection pool is a single node connection pool, that simply contains a single node.

The client should be updated to accept a ConnectionPool, asking it for a node to which to make an API request. Initial thoughts here are that ConnectionPool would be a trait with a function that can be used to retrieve a "node" to which an API request can be made. A SingleNodeConnectionPool is part of the implementation, and other connection pools can be implemented in separate issues.