[Backport 8.10] Add more docs about keep-alive connections (#2049)
(cherry picked from commit f1e83ae853)
Co-authored-by: Josh Mock <joshua.mock@elastic.co>
This commit is contained in:
committed by
GitHub
parent
f08691cb9e
commit
8d96cb4342
@ -11,6 +11,7 @@ This page contains the information you need to connect and use the Client with
|
|||||||
* <<client-faas-env, Using the Client in a Function-as-a-Service Environment>>
|
* <<client-faas-env, Using the Client in a Function-as-a-Service Environment>>
|
||||||
* <<client-connect-proxy, Connecting through a proxy>>
|
* <<client-connect-proxy, Connecting through a proxy>>
|
||||||
* <<client-error-handling, Handling errors>>
|
* <<client-error-handling, Handling errors>>
|
||||||
|
* <<keep-alive, Keep-alive connections>>
|
||||||
* <<product-check, Automatic product check>>
|
* <<product-check, Automatic product check>>
|
||||||
|
|
||||||
[[authentication]]
|
[[authentication]]
|
||||||
@ -659,6 +660,37 @@ a|* `name` - `string`
|
|||||||
* `headers` - `object`, the response status code
|
* `headers` - `object`, the response status code
|
||||||
|===
|
|===
|
||||||
|
|
||||||
|
[[keep-alive]]
|
||||||
|
[discrete]
|
||||||
|
=== Keep-alive connections
|
||||||
|
|
||||||
|
By default, the client uses persistent, keep-alive connections to reduce the overhead of creating a new HTTP connection for each Elasticsearch request.
|
||||||
|
If you are using the default `UndiciConnection` connection class, it maintains a pool of 256 connections with a keep-alive of 10 minutes.
|
||||||
|
If you are using the legacy `HttpConnection` connection class, it maintains a pool of 256 connections with a keep-alive of 1 minute.
|
||||||
|
|
||||||
|
If you need to disable keep-alive connections, you can override the HTTP agent with your preferred https://nodejs.org/api/http.html#http_new_agent_options[HTTP agent options]:
|
||||||
|
|
||||||
|
[source,js]
|
||||||
|
----
|
||||||
|
const client = new Client({
|
||||||
|
node: 'http://localhost:9200',
|
||||||
|
// the function takes as parameter the option
|
||||||
|
// object passed to the Connection constructor
|
||||||
|
agent: (opts) => new CustomAgent()
|
||||||
|
})
|
||||||
|
----
|
||||||
|
|
||||||
|
Or you can disable the HTTP agent entirely:
|
||||||
|
|
||||||
|
[source,js]
|
||||||
|
----
|
||||||
|
const client = new Client({
|
||||||
|
node: 'http://localhost:9200',
|
||||||
|
// Disable agent and keep-alive
|
||||||
|
agent: false
|
||||||
|
})
|
||||||
|
----
|
||||||
|
|
||||||
[discrete]
|
[discrete]
|
||||||
[[product-check]]
|
[[product-check]]
|
||||||
=== Automatic product check
|
=== Automatic product check
|
||||||
|
|||||||
Reference in New Issue
Block a user