简体   繁体   English

PostgreSQL + pgpool 复制与未命中平衡

[英]PostgreSQL + pgpool replication with miss balancing

I have a PostgreSQL replication MS with pgpool as a load balancer on master server only.我有一个 PostgreSQL 复制 MS,pgpool 仅作为主服​​务器上的负载平衡器。 The replication is going OK and there is no delay on the process.复制过程正常,过程没有延迟。 The problem is that the master server is receiving more request than the slave even when I have configured a balance different from 50% for each server.问题是,即使我为每台服务器配置了不同于 50% 的余额,主服务器收到的请求也比从服务器多。

This is the pgpool show_pool_nodes with backend weigth M(1)-S(2)这是后端权重为 M(1)-S(2) 的 pgpool show_pool_nodes

node_id |  hostname   | port | status | lb_weight |  role   | select_cnt | load_balance_node | replication_delay
---------+-------------+------+--------+-----------+---------+------------+-------------------+-------------------
 0       | master-ip   | 9999 | up     | 0.333333  | primary | 56348331   | false             | 0
 1       | slave-ip    | 9999 | up     | 0.666667  | standby | 3691734    | true              | 0

as you can appreciate the master server is receiving +10x request than slave正如你所理解的,主服务器比从服务器接收 +10 倍的请求

This is the pgpool show_pool_nodes with backend weigth M(1)-S(5)这是后端权重为 M(1)-S(5) 的 pgpool show_pool_nodes

 node_id |  hostname   | port | status | lb_weight |  role   | select_cnt | load_balance_node | replication_delay
---------+-------------+------+--------+-----------+---------+------------+-------------------+-------------------
 0       | master-ip   | 9999 | up     | 0.166667  | primary | 10542201   | false             | 0
 1       | slave-ip    | 9999 | up     | 0.833333  | standby | 849494     | true              | 0

The behave is quite similar when I assign M(1)-S(1)当我分配 M(1)-S(1) 时,行为非常相似

Now I wonder if I miss understood the pgpool functioning:现在我想知道我是否想念理解 pgpool 的功能:

  1. Pgpool only balances read queries(as write queries are sent to master always) Pgpool 只平衡读查询(因为写查询总是发送到主服务器)

  2. Backend Weight parameter is assigned to calculate distribution only in balancing mode.分配后端权重参数仅在平衡模式下计算分布。 As greater the value is more likely to be chosen for pgpool, so if a server has a greater lb_weight it would be selected more times than others with lower values.越大的值越有可能被 pgpool 选择,所以如果一个服务器有一个更大的 lb_weight 它会比其他值更低的服务器被选择更多的次数。

If I'm right why is happening this?如果我是对的,为什么会发生这种情况? Is there a way that I can actually assign a proper balancing configuration of select_cnt queries?有没有一种方法可以实际分配 select_cnt 查询的适当平衡配置? My intention is to overcharge the slave with read queries and let to master only a "few" read queries as it is taking all the writing.我的目的是通过读取查询对从站过度收费,并让其掌握“少数”读取查询,因为它正在处理所有写入。

You are right on pgpool load balancing.你是对的 pgpool 负载平衡。 There could be some reasons why this doesn't seem to work.可能有一些原因导致这似乎不起作用。 For start, notice that you have the same port number for both backends.首先,请注意两个后端的端口号相同。 Try configuring your backend connection settings like shown in the sample pgpool.conf : https://github.com/pgpool/pgpool2/blob/master/src/sample/pgpool.conf.sample (lines 66-87), (where you also set the weights to your needs) and assign different port numbers to each backend.尝试配置您的后端连接设置,如示例pgpool.conf所示: https : //github.com/pgpool/pgpool2/blob/master/src/sample/pgpool.conf.sample (第 66-87 行),(您在哪里还可以根据需要设置权重)并为每个后端分配不同的端口号。

Also check (assuming your running mode is master/slave):还要检查(假设您的运行模式是主/从):

  • load_balance_mode = on
  • master_slave_mode = on

-- changes require restart -- 更改需要重启

There is a relevant FAQ entry " It seems my pgpool-II does not do load balancing. Why?"有一个相关的FAQ条目“看来我的pgpool-II没有做负载均衡。为什么?” here: https://www.pgpool.net/mediawiki/index.php/FAQ (if pgpool version 4.1 also consider statement_level_load_balance ).在这里: https : //www.pgpool.net/mediawiki/index.php/FAQ (如果 pgpool 4.1 版也考虑statement_level_load_balance )。 So far, i have assumed that the general conditions for load balancing ( https://www.pgpool.net/docs/latest/en/html/runtime-config-load-balancing.html ) are met.到目前为止,我已经假设负载平衡的一般条件 ( https://www.pgpool.net/docs/latest/en/html/runtime-config-load-balancing.html ) 得到满足。

You can try to adjust below one configs in pgpool.conf file: 1. wal lag delay size delay_threshold = 10000000您可以尝试在 pgpool.conf 文件中调整以下配置: 1. wal lag delay size delay_threshold = 10000000

it is used to let pgpool know if the slave postgresql wal is too delay to use.它用于让 pgpool 知道从属 postgresql wal 是否太延迟无法使用。 Change large more query can be pass to slave.更改较大的查询可以传递给从站。 Change small more query will go to master.更改小更多查询将转到高手。

Besides, the pgbench testing parameter is also key.此外,pgbench 测试参数也是关键。 Use -C parameter, it will let connection per query, otherwise connection per session.使用 -C 参数,它将让每个查询连接,否则每个会话连接。

pgpoll load balance decision making depends of a matrix of parameter combination. pgpoll 负载平衡决策取决于参数组合矩阵。 not only a single parameter不仅仅是一个参数

Here is reference.这里是参考。 https://www.pgpool.net/docs/latest/en/html/runtime-config-load-balancing.html#GUC-LOAD-BALANCE-MODE https://www.pgpool.net/docs/latest/en/html/runtime-config-load-balancing.html#GUC-LOAD-BALANCE-MODE

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM