Re: [EXTERNAL] Re: Support load balancing in libpq - Mailing list pgsql-hackers

From Maxim Orlov
Subject Re: [EXTERNAL] Re: Support load balancing in libpq
Date
Msg-id CACG=ezYazYUj3TQVSPL-G5Bhea0hApTbknhAbCX=yNDdu=gpyw@mail.gmail.com
Whole thread Raw
In response to Re: [EXTERNAL] Re: Support load balancing in libpq  (Jelte Fennema <Jelte.Fennema@microsoft.com>)
Responses Re: [EXTERNAL] Re: Support load balancing in libpq
Re: [EXTERNAL] Re: Support load balancing in libpq
List pgsql-hackers
+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 save
value, i.e. will attempt to connect to the same host. I think, this is not we want to achieve.

And the "hostroder" option should be free'd in freePGconn.

> 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 be next:
- we have two libpq's options: "load_balance_hosts" and "failover_timeout";
- the "load_balance_hosts" should be "sequential" or "random";
- the "failover_timeout" is a time period, within which, if connection to the server is not established, we switch to the next address or host.

While writing this text, I start thinking that load balancing is a combination of two parameters above.

> 3) Isn't it good to provide a way to test the patch?

Good idea too. I think, we should add tap test here.


--
Best regards,
Maxim Orlov.

pgsql-hackers by date:

Previous
From: Daniel Gustafsson
Date:
Subject: Re: pg_receivewal and SIGTERM
Next
From: Fujii Masao
Date:
Subject: Re: Refactoring postgres_fdw/connection.c