Skip to content

Commit 6fce47f

Browse files
author
Maria Scharin
authored
Merge pull request #39 from neo4j/zhenlineo-1.5-new
Conn Pool management and load balancing strategy
2 parents b448424 + a397a80 commit 6fce47f

File tree

2 files changed

+118
-1
lines changed

2 files changed

+118
-1
lines changed

src/main/asciidoc/client-applications.adoc

+118
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,79 @@ include::{python-examples}/config_trust_example.py[tags=config-trust]
363363
====
364364

365365

366+
[[driver-config-connection-pool-management]]
367+
=== Connection pool management
368+
369+
The driver maintains a pool of connections.
370+
The pooled connections are reused by sessions and transactions to avoid the overhead added by establishing new connections for every query.
371+
The connection pool always starts up empty.
372+
New connections are created on demand by sessions and transactions.
373+
When a session or a transaction is done with its execution, the connection will be returned to the pool to be reused.
374+
375+
Application users can tune connection pool settings to configure the driver for different use cases based on client performance requirements and database resource consumption limits.
376+
377+
Detailed descriptions of connection pool settings available via driver configuration are listed below:
378+
379+
`MaxConnectionLifetime`::
380+
Pooled connections older than this threshold will be closed and removed from the pool.
381+
Such removal happens during connection acquisition so that new session is never backed by an old connection.
382+
Setting this option to a low value will cause a high connection churn and might result in a performance drop.
383+
It is recommended to set driver's maximum lifetime to a value smaller than the maximum lifetime configured in its application system infrastructure (such as operation system, router, load balancer, proxy and firewall).
384+
Negative values result in lifetime not being checked.
385+
Default value: 1h.
386+
387+
`MaxConnectionPoolSize`::
388+
This setting defines the maximum total number of connections allowed to be managed by the connection pool on each host.
389+
In other words, for a direct driver, this sets the maximum amount of connections towards a single database.
390+
For a routing driver this sets the maximum amount of connections towards each cluster member.
391+
If a session or transaction tries to acquire a connection at a time when the pool size is at its full capacity, it must wait until a free connection is available in the pool or the request to acquire a new connection times out.
392+
The connection acquiring timeout is configured via `ConnectionAcquisitionTimeout`.
393+
Default value: This is different for different drivers, but is a number in the order of 100.
394+
395+
`ConnectionAcquisitionTimeout`::
396+
This setting limits the amount of time a session or transaction can spend waiting for a free connection to appear in the pool before throwing an exception.
397+
The exception thrown in this case is `ClientException`.
398+
Timeout only applies when connection pool is at its max capacity.
399+
Default value: 1m.
400+
401+
402+
[.tabbed-example]
403+
.Connection pool management
404+
====
405+
[.include-with-dotnet]
406+
======
407+
[source, csharp]
408+
----
409+
include::{dotnet-examples}/Examples.cs[tags=config-connection-pool]
410+
----
411+
======
412+
413+
[.include-with-java]
414+
======
415+
[source, java]
416+
----
417+
include::{java-examples}/ConfigConnectionPoolExample.java[tags=config-connection-pool]
418+
----
419+
======
420+
421+
[.include-with-javascript]
422+
======
423+
[source, javascript]
424+
----
425+
include::{javascript-examples}/examples.test.js[tags=config-connection-pool]
426+
----
427+
======
428+
429+
[.include-with-python]
430+
======
431+
[source, python]
432+
----
433+
include::{python-examples}/config_connection_pool_example.py[tags=config-connection-pool]
434+
----
435+
======
436+
====
437+
438+
366439
[[driver-configuration-connection-timeout]]
367440
=== Connection timeout
368441

@@ -406,6 +479,51 @@ include::{python-examples}/config_connection_timeout_example.py[tags=config-conn
406479
====
407480

408481

482+
[[driver-load-balancing-strategy]]
483+
=== Load balancing strategy
484+
485+
A routing driver contains a load balancer to route queries evenly among many cluster members.
486+
The built-in load balancer provides two strategies: `least-connected` and `round-robin`.
487+
The `least-connected` strategy in general gives a better performance as it takes query execution time and server load into consideration when distributing queries among the cluster members.
488+
Default value: `least-connected`.
489+
490+
[.tabbed-example]
491+
.Load balancing strategy
492+
====
493+
[.include-with-dotnet]
494+
======
495+
[source, csharp]
496+
----
497+
include::{dotnet-examples}/Examples.cs[tags=config-load-balancing-strategy]
498+
----
499+
======
500+
501+
[.include-with-java]
502+
======
503+
[source, java]
504+
----
505+
include::{java-examples}/ConfigLoadBalancingStrategyExample.java[tags=config-load-balancing-strategy]
506+
----
507+
======
508+
509+
[.include-with-javascript]
510+
======
511+
[source, javascript]
512+
----
513+
include::{javascript-examples}/examples.test.js[tags=config-load-balancing-strategy]
514+
----
515+
======
516+
517+
[.include-with-python]
518+
======
519+
[source, python]
520+
----
521+
include::{python-examples}/config_load_balancing_strategy_example.py[tags=config-load-balancing-strategy]
522+
----
523+
======
524+
====
525+
526+
409527
[[driver-configuration-max-retry-time]]
410528
=== Max retry time
411529

src/main/asciidoc/sessions-and-transactions.adoc

-1
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,6 @@ include::{python-examples}/read_write_transaction_example.py[tags=read-write-tra
288288
======
289289
====
290290

291-
--
292291

293292
== Asynchronous programming
294293

0 commit comments

Comments
 (0)