Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pgpool2 load balancing not working

I have a Python/Django app that will require database load balancing at some point in the near future. In the meantime I'm trying to learn to implement pgpool on a local virtual machine setup.

I have 4 Ubuntu 12.04 VMs:

192.168.1.80 <- pool, pgppool2 installed and accessible
192.168.1.81 <- db1 master
192.168.1.82 <- db2 slave
192.168.1.83 <- db3 slave

I have pgpool-II version 3.1.1 and my database servers are running PostgreSQL 9.1.

I have my app's db connection pointed to 192.168.1.80:9999 and it works fine.

The problem is when I use Apache ab to throw some load at it, none of SELECT queries appear to be balanced. All the load goes to my db1 master. Also, quite concerning is the load on the pool server itself, it is really high compared to db1, maybe an average of 8-10 times higher. Meanwhile my db2 and db3 servers have a load of nearly zero, they appear to only be replicating from db1, which isn't very load intensive for my tests with ab.

ab -n 300 -c 4 -C 'sessionid=80a5fd3b6bb59051515e734326735f80' http://192.168.1.17:8000/contacts/

That drives the load on my pool server up to about 2.3. Load on db1 is about 0.4 and load on db2 and db3 is nearly zero.

Can someone take a look at my config and see if what I'm doing wrong?

backend_hostname0 = '192.168.1.81'
backend_port0 = 5432
backend_weight0 = 1
backend_data_directory0 = '/var/lib/postgresql/9.1/main'
backend_flag0 = 'ALLOW_TO_FAILOVER'

backend_hostname1 = '192.168.1.82'
backend_port1 = 5433
backend_weight1 = 1
backend_data_directory1 = '/var/lib/postgresql/9.1/main'
backend_flag1 = 'ALLOW_TO_FAILOVER'

backend_hostname2 = '192.168.1.83'
backend_port2 = 5434
backend_weight2 = 1
backend_data_directory2 = '/var/lib/postgresql/9.1/main'
backend_flag2 = 'ALLOW_TO_FAILOVER'

load_balance_mode = on

My entire config is here:

http://pastebin.com/raw.php?i=wzBc0aSp
like image 688
gdonald Avatar asked Jan 04 '13 17:01

gdonald


People also ask

Is PgBouncer a load balancer?

PgBouncer is a popular connection pooler designed for PostgreSQL, but it is not enough to achieve PostgreSQL High Availability by itself as it doesn't have multi-host configuration, failover, or detection. Using a Load Balancer is a way to have High Availability in your database topology.

What is Load Balancer in PostgreSQL?

In load balancing, If a database is replicated, executing a SELECT query on any server will return the same result. pgpool-II takes advantage of the replication feature to reduce the load on each PostgreSQL server by distributing SELECT queries among multiple servers, improving the system's overall throughput.

What is Pgpool in PostgreSQL?

Pgpool-II is a tool to add useful features to PostgreSQL, including: connection pooling. load balancing. automatic fail over and more.


1 Answers

I needed

replication_mode = off
master_slave_mode = on

Thanks to Tatsuo Ishii:

http://www.pgpool.net/pipermail/pgpool-general/2013-January/001309.html

like image 101
gdonald Avatar answered Oct 02 '22 20:10

gdonald