PgPool + PostgreSQL集群的高并发性

时间:2017-11-15 00:21:33

标签: postgresql pgpool

我有一个PgPool II集群,其中有2个PostreSQL 9.5后端(4vCores,8gb ram)进行loadbalacing +复制。我的用例是一个只提供SSO登录/注册的网站,是一个相对较小的数据库,查询非常简单但需要支持非常高的并发性(几千个并发用户)。

在添加更多后端之前,我想确保当前群集的配置是最佳的。用pgbench进行一些测试(定期的SELECT查询模拟网站的正常行为),我能够不费力地重载连接池(pgbench -c 64 -j 4 -t 1000 -f queries.sql),即使在那里LB和后端有足够的CPU / RAM。

这是相关设置:

pgPool II

listen_backlog_multiplier = 3
connection_cache = on
num_init_children = 62
max_pool = 4
child_life_time = 0
child_max_connections = 0
connection_life_time = 0
client_idle_limit = 0

的PostgreSQL

max_connections = 256
shared_buffers = 2GB
effective_cache_size = 6GB
work_mem = 8MB
maintenance_work_mem = 512MB
min_wal_size = 1GB
max_wal_size = 2GB
checkpoint_completion_target = 0.7
wal_buffers = 16MB
default_statistics_target = 100

增加num_init_children / max_pool会强制我增加后端的max_connections,这似乎不建议使用。有什么建议?谢谢!

1 个答案:

答案 0 :(得分:0)

没有办法通过Pgpool-II实现比num_init_children的值更多的并发连接。

Pgpool-II中的

num_init_children直接对应于Pgpool-II可以处理的最大并发客户端连接数,因此您无法将num_init_children值设置为低于您要支持的最大并发连接数。

但是为了保存PG端的max_connections,可以使用max_pool config的较低值。由于Pgpool-II子进程仅在请求的[user,database]对尚未在缓存中时才打开新的后端连接。如果应用程序仅使用一个用户连接到一个数据库,Say [user1,db1],则可以将max_pool设置为1,并且PG后端的max_connection等于(num_init_children +1)。