[PoC] load balancing in libpq

Поиск
Список
Период
Сортировка
От Satoshi Nagayasu
Тема [PoC] load balancing in libpq
Дата
Msg-id 505EE993.40508@uptime.jp
обсуждение исходный текст
Ответы Re: [PoC] load balancing in libpq  (Euler Taveira <euler@timbira.com>)
Re: [PoC] load balancing in libpq  (Simon Riggs <simon@2ndQuadrant.com>)
Список 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@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@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@devvm03 libpq_repli]$
----------------------------------------------------------------

--
Satoshi Nagayasu <snaga@uptime.jp>
Uptime Technologies, LLC. http://www.uptime.jp

Вложения

В списке pgsql-hackers по дате отправления:

Предыдущее
От: Kohei KaiGai
Дата:
Сообщение: Re: [v9.3] writable foreign tables
Следующее
От: Peter Eisentraut
Дата:
Сообщение: Re: [ADMIN] pg_upgrade from 9.1.3 to 9.2 failed