Re: [EXTERNAL] Re: Support load balancing in libpq

2023-03-15 Thread Jelte Fennema
Rebased On Tue, 14 Mar 2023 at 19:05, Gregory Stark (as CFM) wrote: > > The pgindent run in b6dfee28f is causing this patch to need a rebase > for the cfbot to apply it. v12-0002-Refactor-libpq-to-store-addrinfo-in-a-libpq-owne.patch Description: Binary data v12-0003-Support-load-balancing-in

Re: [EXTERNAL] Re: Support load balancing in libpq

2023-03-14 Thread Gregory Stark (as CFM)
The pgindent run in b6dfee28f is causing this patch to need a rebase for the cfbot to apply it.

Re: [EXTERNAL] Re: Support load balancing in libpq

2023-03-06 Thread Jelte Fennema
Small update. Improved some wording in the docs. On Fri, 3 Mar 2023 at 15:37, Jelte Fennema wrote: > > > I want to note that the Fisher-Yates algorithm is implemented in a > > difficult to understand manner. > > +if (j < i) /* avoid fetching undefined data if j=i */ > > This stuff does not make s

Re: [EXTERNAL] Re: Support load balancing in libpq

2023-03-03 Thread Jelte Fennema
> I want to note that the Fisher-Yates algorithm is implemented in a > difficult to understand manner. > +if (j < i) /* avoid fetching undefined data if j=i */ > This stuff does not make sense in case of shuffling arrays inplace. It > is important only for making a new copy of an array and only in

Re: [EXTERNAL] Re: Support load balancing in libpq

2023-03-02 Thread Andrey Borodin
On Wed, Mar 1, 2023 at 12:03 PM Jelte Fennema wrote: > > done and updated cf entry > Hi Jelte! I've looked into the patch. Although so many improvements can be suggested, It definitely makes sense as-is too. These improvements might be, for example, sorting hosts according to ping latency or som

Re: [EXTERNAL] Re: Support load balancing in libpq

2023-03-01 Thread Jelte Fennema
done and updated cf entry On Wed, 1 Mar 2023 at 20:13, Greg S wrote: > > This patch seems to need a rebase. > > I'll update the status to Waiting on Author for now. After rebasing > please update it to either Needs Review or Ready for Committer > depending on how simple the rebase was and whether

Re: [EXTERNAL] Re: Support load balancing in libpq

2023-03-01 Thread Greg S
This patch seems to need a rebase. I'll update the status to Waiting on Author for now. After rebasing please update it to either Needs Review or Ready for Committer depending on how simple the rebase was and whether there are open questions to finish it.

Re: [EXTERNAL] Re: Support load balancing in libpq

2023-01-26 Thread Jelte Fennema
After discussing this patch privately with Andres here's a new version of this patch. The major differences are: 1. Use the pointer value of the connection as a randomness source 2. Use more precise time as randomness source 3. Move addrinfo changes into a separate commit. This is both to make the

Re: [EXTERNAL] Re: Support load balancing in libpq

2023-01-18 Thread Jelte Fennema
As far as I can tell this is ready for committer feedback now btw. I'd really like to get this into PG16. > It hadn't been my intention to block the patch on it, sorry. Just > registering a preference. No problem. I hadn't looked into the shared PRNG solution closely enough to determine if I thou

Re: [EXTERNAL] Re: Support load balancing in libpq

2023-01-17 Thread Jacob Champion
On Fri, Jan 13, 2023 at 10:44 AM Jacob Champion wrote: > And my thought was that the one-time > initialization could be moved to a place that doesn't need to know the > connection options at all, to make it easier to reason about the > architecture. Say, next to the WSAStartup machinery. (And aft

Re: [EXTERNAL] Re: Support load balancing in libpq

2023-01-13 Thread Jacob Champion
On Fri, Jan 13, 2023 at 9:10 AM Jelte Fennema wrote: > > > Just a quick single-issue review, but I agree with Maxim that having > > one PRNG, seeded once, would be simpler > > I don't agree that it's simpler. Because now there's a mutex you have > to manage, and honestly cross-platform threading i

Re: [EXTERNAL] Re: Support load balancing in libpq

2023-01-13 Thread Jelte Fennema
> Just a quick single-issue review, but I agree with Maxim that having > one PRNG, seeded once, would be simpler I don't agree that it's simpler. Because now there's a mutex you have to manage, and honestly cross-platform threading in C is not simple. However, I attached two additional patches tha

Re: [EXTERNAL] Re: Support load balancing in libpq

2023-01-12 Thread Jacob Champion
On Wed, Sep 14, 2022 at 7:54 AM Maxim Orlov wrote: > For the patch itself, I think it is better to use a more precise time > function in libpq_prng_init or call it only once. > Thought it is a special corner case, imagine all the connection attempts at > first second will be seeded with the save

Re: [EXTERNAL] Re: Support load balancing in libpq

2023-01-09 Thread Jelte Fennema
Attached an updated patch which should address your feedback and I updated the commit message. > I wonder whether making the parameter a boolean will paint us into a > corner I made it a string option, just like target_session_attrs. I'm pretty sure a round-robin load balancing policy could be i

Re: Support load balancing in libpq

2023-01-06 Thread Michael Banck
Hi, On Tue, Nov 29, 2022 at 02:57:08PM +, Jelte Fennema wrote: > Attached is a new version with the tests cleaned up a bit (more > comments mostly). > > @Michael, did you have a chance to look at the last version? Because I > feel that the patch is pretty much ready for a committer to look at

Re: Support load balancing in libpq

2022-11-29 Thread Jelte Fennema
Attached is a new version with the tests cleaned up a bit (more comments mostly). @Michael, did you have a chance to look at the last version? Because I feel that the patch is pretty much ready for a committer to look at, at this point. v5-0001-Support-load-balancing-in-libpq.patch Description

Re: Support load balancing in libpq

2022-10-03 Thread Jelte Fennema
I attached a new patch which does the following: 1. adds tap tests 2. adds random_seed parameter to libpq (required for tap tests) 3. frees conn->loadbalance in freePGConn 4. add more expansive docs on the feature its behaviour Apart from bike shedding on the name of the option I think it's pretty

Re: [EXTERNAL] Re: Support load balancing in libpq

2022-09-17 Thread Michael Banck
Hi, On Mon, Sep 12, 2022 at 02:16:56PM +, Jelte Fennema wrote: > Attached is an updated patch with the following changes: > 1. rebased (including solved merge conflict) > 2. fixed failing tests in CI > 3. changed the commit message a little bit > 4. addressed the two remarks from Micheal > 5.

Re: [EXTERNAL] Re: Support load balancing in libpq

2022-09-17 Thread Michael Banck
Hi, On Wed, Sep 14, 2022 at 05:53:48PM +0300, Maxim Orlov wrote: > > Also, IMO, the solution must have a fallback mechanism if the > > standby/chosen host isn't reachable. > > Yeah, I think it should. I'm not insisting on a particular name of options > here, but in my view, the overall idea may b

Re: [EXTERNAL] Re: Support load balancing in libpq

2022-09-14 Thread Maxim Orlov
+1 for overall idea of load balancing via random host selection. For the patch itself, I think it is better to use a more precise time function in libpq_prng_init or call it only once. Thought it is a special corner case, imagine all the connection attempts at first second will be seeded with the

Re: [EXTERNAL] Re: Support load balancing in libpq

2022-09-12 Thread Jelte Fennema
Attached is an updated patch with the following changes: 1. rebased (including solved merge conflict) 2. fixed failing tests in CI 3. changed the commit message a little bit 4. addressed the two remarks from Micheal 5. changed the prng_state from a global to a connection level value for thread-saf

Re: Support load balancing in libpq

2022-09-10 Thread Michael Banck
Hi, the patch no longer applies cleanly, please rebase (it's trivial). I don't like the provided commit message very much, I think the discussion about pgJDBC having had load balancing for a while belongs elsewhere. On Wed, Jun 22, 2022 at 07:54:19AM +, Jelte Fennema wrote: > I tried to stay

RE: Support load balancing in libpq

2022-07-27 Thread kuroda.hay...@fujitsu.com
Dear Jelte, > With plain Postgres this assumption is probably correct. But the main reason > I'm interested in this patch was because I would like to be able to load > balance across the workers in a Citus cluster. These workers are all > primaries. > Similar usage would likely be possible with B

Re: Support load balancing in libpq

2022-07-15 Thread Jelte Fennema
> we can assume that one of members is a primary and others are secondary. With plain Postgres this assumption is probably correct. But the main reason I'm interested in this patch was because I would like to be able to load balance across the workers in a Citus cluster. These workers are all prim

RE: Support load balancing in libpq

2022-07-14 Thread kuroda.hay...@fujitsu.com
Dear Jelte, I like your idea. But do we have to sort randomly even if target_session_attr is set to 'primary' or 'read-write'? I think this parameter can be used when all listed servers have same data, and we can assume that one of members is a primary and others are secondary. In this case use

Re: [EXTERNAL] Re: Support load balancing in libpq

2022-07-05 Thread Jelte Fennema
> I'm quoting a previous attempt by Satyanarayana Narlapuram on this > topic [1], it also has a patch set. Thanks for sharing that. It's indeed a different approach to solve the same problem. I think my approach is much simpler, since it only requires minimal changes to the libpq client and none

Re: Support load balancing in libpq

2022-07-05 Thread Bharath Rupireddy
On Fri, Jun 10, 2022 at 10:01 PM Jelte Fennema wrote: > > 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

Re: Support load balancing in libpq

2022-06-22 Thread Jelte Fennema
I tried to stay in line with the naming of this same option in JDBC and Npgsql, where it's called "loadBalanceHosts" and "Load Balance Hosts" respectively. So, actually to be more in line it should be the option for libpq should be called "load_balance_hosts" (not "loadbalance" like in the previo

Re: Support load balancing in libpq

2022-06-21 Thread Aleksander Alekseev
Hi Jelte, > 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 interm