Support load balancing in libpq
Jelte Fennema-Nio <jelte.fennema@microsoft.com>
From: Jelte Fennema <Jelte.Fennema@microsoft.com>
To: "pgsql-hackers@postgresql.org" <pgsql-hackers@postgresql.org>
Date: 2022-06-10T16:31:26Z
Lists: pgsql-hackers
Attachments
- 0001-Support-load-balancing-in-libpq.patch (application/octet-stream) patch 0001
Load balancing connections across multiple read replicas is a pretty common way of scaling out read queries. There are two main ways of doing so, both with their own advantages and disadvantages: 1. Load balancing at the client level 2. Load balancing by connecting to an intermediary load balancer Option 1 has been supported by JDBC (Java) for 8 years and Npgsql (C#) merged support about a year ago. This patch adds the same functionality to libpq. The way it's implemented is the same as the implementation of JDBC, and contains two levels of load balancing: 1. The given hosts are randomly shuffled, before resolving them one-by-one. 2. Once a host its addresses get resolved, those addresses are shuffled, before trying to connect to them one-by-one.
Commits
-
Fix pointer cast for seed calculation on 32-bit systems
- 2fe7a6df94e6 16.0 landed
-
Copy and store addrinfo in libpq-owned private memory
- 44d85ba5a336 16.0 landed
-
libpq: Use modern socket flags, if available.
- bfc9497ece01 16.0 cited