Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport 8.10] Add more docs about keep-alive connections #2049

Merged
merged 1 commit into from
Nov 2, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions docs/connecting.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -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-connect-proxy, Connecting through a proxy>>
* <<client-error-handling, Handling errors>>
* <<keep-alive, Keep-alive connections>>
* <<product-check, Automatic product check>>

[[authentication]]
Expand Down Expand Up @@ -659,6 +660,37 @@ a|* `name` - `string`
* `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]
[[product-check]]
=== Automatic product check
Expand Down
Loading