You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+67-1Lines changed: 67 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,73 @@
4
4
<spanclass="badge-npmversion"><ahref="https://npmjs.org/package/pg"title="View this project on NPM"><imgsrc="https://img.shields.io/npm/v/pg.svg"alt="NPM version" /></a></span>
5
5
<spanclass="badge-npmdownloads"><ahref="https://npmjs.org/package/pg"title="View this project on NPM"><imgsrc="https://img.shields.io/npm/dm/pg.svg"alt="NPM downloads" /></a></span>
6
6
7
-
This is a fork of [node-postgres](https://github.com/brianc/node-postgres) which includes smart feature like Cluster Aware and Topology Aware load balancing. To know more visit the [docs page](https://docs.yugabyte.com/preview/drivers-orms/).
7
+
This is a fork of [node-postgres](https://github.com/brianc/node-postgres) which includes the following additional features:
In the cluster-aware connection load balancing, connections are distributed across all the tservers in the cluster, irrespective of their placements.
16
+
17
+
To enable the cluster-aware connection load balancing, provide the parameter `loadBalance` set to true as `loadBalance=true` in the connection url or the connection string (DSN style).
With this parameter specified in the url, the driver will fetch and maintain the list of tservers from the given endpoint (`localhost` in above example) available in the YugabyteDB cluster and distribute the connections equally across them.
24
+
25
+
This list is refreshed every 5 minutes, when a new connection request is received.
26
+
27
+
Application needs to use the same connection url to create every connection it needs, so that the distribution happens equally.
28
+
29
+
### Topology-aware connection load balancing
30
+
31
+
With topology-aware connnection load balancing, users can target tservers in specific zones by specifying these zones as `topologyKeys` with values in the format `cloudname.regionname.zonename`. Multiple zones can be specified as comma separated values.
32
+
33
+
The connections will be distributed equally with the tservers in these zones.
34
+
35
+
Note that, you would still need to specify `loadBalance=true` to enable the topology-aware connection load balancing.
For topology-aware load balancing, you can now specify fallback placements too. This is not applicable for cluster-aware load balancing.
43
+
Each placement value can be suffixed with a colon (`:`) followed by a preference value between 1 and 10.
44
+
A preference value of `:1` means it is a primary placement. A preference value of `:2` means it is the first fallback placement and so on.If no preference value is provided, it is considered to be a primary placement (equivalent to one with preference value `:1`). Example given below.
The driver attempts to connect to a node in following order: the least loaded node in the 1) primary placement(s), else in the 2) first fallback if specified, else in the 3) second fallback if specified and so on.
57
+
If no nodes are available either in primary placement(s) or in any of the fallback placements, then nodes in the rest of the cluster are attempted.
58
+
And this repeats for each connection request.
59
+
60
+
## Specifying Refresh Interval
61
+
62
+
Users can specify Refresh Time Interval, in seconds. It is the time interval between two attempts to refresh the information about cluster nodes. Default is 300. Valid values are integers between 0 and 600. Value 0 means refresh for each connection request. Any value outside this range is ignored and the default is used.
63
+
64
+
To specify Refresh Interval, use the parameter `ybServersRefreshInterval` in the connection url or the connection string.
Here, X is the value of the refresh interval (seconds) in integer.
70
+
71
+
To know more visit the [docs page](https://docs.yugabyte.com/preview/drivers-orms/).
72
+
73
+
For a working example which demonstrates the configurations of connection load balancing see the [driver-examples](https://github.com/yugabyte/driver-examples/tree/main/nodejs) repository.
8
74
9
75
Non-blocking PostgreSQL client for Node.js. Pure JavaScript and optional native libpq bindings.
0 commit comments