Skip to content

Commit f1e83ae

Browse files
authored
Add more docs about keep-alive connections (#2048)
1 parent a6392eb commit f1e83ae

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

docs/connecting.asciidoc

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ This page contains the information you need to connect and use the Client with
1111
* <<client-faas-env, Using the Client in a Function-as-a-Service Environment>>
1212
* <<client-connect-proxy, Connecting through a proxy>>
1313
* <<client-error-handling, Handling errors>>
14+
* <<keep-alive, Keep-alive connections>>
1415
* <<product-check, Automatic product check>>
1516

1617
[[authentication]]
@@ -659,6 +660,37 @@ a|* `name` - `string`
659660
* `headers` - `object`, the response status code
660661
|===
661662

663+
[[keep-alive]]
664+
[discrete]
665+
=== Keep-alive connections
666+
667+
By default, the client uses persistent, keep-alive connections to reduce the overhead of creating a new HTTP connection for each Elasticsearch request.
668+
If you are using the default `UndiciConnection` connection class, it maintains a pool of 256 connections with a keep-alive of 10 minutes.
669+
If you are using the legacy `HttpConnection` connection class, it maintains a pool of 256 connections with a keep-alive of 1 minute.
670+
671+
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]:
672+
673+
[source,js]
674+
----
675+
const client = new Client({
676+
node: 'http://localhost:9200',
677+
// the function takes as parameter the option
678+
// object passed to the Connection constructor
679+
agent: (opts) => new CustomAgent()
680+
})
681+
----
682+
683+
Or you can disable the HTTP agent entirely:
684+
685+
[source,js]
686+
----
687+
const client = new Client({
688+
node: 'http://localhost:9200',
689+
// Disable agent and keep-alive
690+
agent: false
691+
})
692+
----
693+
662694
[discrete]
663695
[[product-check]]
664696
=== Automatic product check

0 commit comments

Comments
 (0)