From: | Satoshi Nagayasu <snaga(at)uptime(dot)jp> |
---|---|
To: | Pgsql Hackers <pgsql-hackers(at)postgresql(dot)org> |
Subject: | [PoC] load balancing in libpq |
Date: | 2012-09-23 10:50:59 |
Message-ID: | 505EE993.40508@uptime.jp |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
Hi all,
I have just written the first PoC code to enable load balancing
in the libpq library.
This libpq enhancement is intended to allow PostgreSQL users to
take advantage of the replication in easier way.
With using this patch, PQconnectdb() function accepts multiple
connection info strings, and pick one of them by round-robin basis
to connect.
This example, shown in below, shows that PQconnect() accepts
a connection string that contains four different databases
(db1~db4) on different servers (dbhost1~dbhost4), and then,
connects them in round-robin basis.
I know there are several things to be considered, but at first,
I need your feedback or comments for this enhancement.
Do you think it would be useful?
Regards,
----------------------------------------------------------------
[snaga(at)devvm03 libpq_repli]$ cat libpq_lb_test.c
#include <stdio.h>
#include <libpq-fe.h>
void
_connect()
{
PGconn *conn;
PGresult *res;
conn = PQconnectdb("host=dbhost1 dbname=db1 user=snaga; host=dbhost2
dbname=db2 user=snaga; host=dbhost3 dbname=db3 user=snaga; host=dbhost4
dbname=db4 user=snaga");
res = PQexec(conn, "SELECT current_database()");
if ( PQresultStatus(res)==PGRES_TUPLES_OK )
{
printf("current_database = %s on %s\n", PQgetvalue(res, 0, 0),
PQhost(conn));
}
PQfinish(conn);
}
int
main(void)
{
int i;
for (i=0 ; i<8 ; i++)
_connect();
return 0;
}
[snaga(at)devvm03 libpq_repli]$ ./libpq_lb_test
current_database = db1 on dbhost1
current_database = db2 on dbhost2
current_database = db3 on dbhost3
current_database = db4 on dbhost4
current_database = db1 on dbhost1
current_database = db2 on dbhost2
current_database = db3 on dbhost3
current_database = db4 on dbhost4
[snaga(at)devvm03 libpq_repli]$
----------------------------------------------------------------
--
Satoshi Nagayasu <snaga(at)uptime(dot)jp>
Uptime Technologies, LLC. http://www.uptime.jp
Attachment | Content-Type | Size |
---|---|---|
libpq_repli_v0.diff | text/plain | 2.3 KB |
From | Date | Subject | |
---|---|---|---|
Next Message | Peter Eisentraut | 2012-09-23 12:33:48 | Re: [ADMIN] pg_upgrade from 9.1.3 to 9.2 failed |
Previous Message | Kohei KaiGai | 2012-09-23 06:25:44 | Re: [v9.3] writable foreign tables |