From: Daniel Gustafsson <dgustafsson@postgresql.org>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Support connection load balancing in libpq
Date: Wed, 29 Mar 2023 20:00:19 +0000
Message-ID: <E1phbxy-000MCu-Bx@gemulon.postgresql.org> (raw)
Support connection load balancing in libpq
This adds support for load balancing connections with libpq using a
connection parameter: load_balance_hosts=<string>. When setting the
param to random, hosts and addresses will be connected to in random
order. This then results in load balancing across these addresses and
hosts when multiple clients or frequent connection setups are used.
The randomization employed performs two levels of shuffling:
1. The given hosts are randomly shuffled, before resolving them
one-by-one.
2. Once a host its addresses get resolved, the returned addresses
are shuffled, before trying to connect to them one-by-one.
Author: Jelte Fennema <postgres@jeltef.nl>
Reviewed-by: Aleksander Alekseev <aleksander@timescale.com>
Reviewed-by: Michael Banck <mbanck@gmx.net>
Reviewed-by: Andrey Borodin <amborodin86@gmail.com>
Discussion: https://postgr.es/m/PR3PR83MB04768E2FF04818EEB2179949F7A69@PR3PR83MB0476.EURPRD83.prod.outlook.
Branch
------
master
Details
-------
https://git.postgresql.org/pg/commitdiff/7f5b19817eaf38e70ad1153db4e644ee9456853e
Modified Files
--------------
.cirrus.yml | 16 ++-
doc/src/sgml/libpq.sgml | 61 ++++++++++
doc/src/sgml/regress.sgml | 13 ++-
src/interfaces/libpq/fe-connect.c | 103 +++++++++++++++++
src/interfaces/libpq/libpq-int.h | 17 ++-
src/interfaces/libpq/meson.build | 2 +
.../libpq/t/003_load_balance_host_list.pl | 81 ++++++++++++++
src/interfaces/libpq/t/004_load_balance_dns.pl | 124 +++++++++++++++++++++
src/test/perl/PostgreSQL/Test/Cluster.pm | 16 +++
src/tools/pgindent/typedefs.list | 1 +
10 files changed, 431 insertions(+), 3 deletions(-)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-committers@postgresql.org
Cc: dgustafsson@postgresql.org, pgsql-committers@lists.postgresql.org
Subject: Re: pgsql: Support connection load balancing in libpq
In-Reply-To: <E1phbxy-000MCu-Bx@gemulon.postgresql.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox