How to Test Haproxy Load Balancing for TiDB Database

Note:
This topic has been translated from a Chinese forum by GPT and might contain errors.

Original topic: Haproxy负载Tidb数据库如何测试

| username: 随缘天空

[TiDB Usage Environment] Production Environment
[TiDB Version] V7.1.1
[Reproduction Path] Using Haproxy for database load balancing, both the load and cluster services have started successfully. However, when testing the balancing rules with relevant commands, the results are not as expected. I’m not sure about the reason or how to test it properly.
[Encountered Issue: Phenomenon and Impact]
[Resource Configuration]
[Attachments: Screenshots/Logs/Monitoring]
Self-test result:


Expected result:

| username: yulei7633 | Original post link

Are you unsure about which node to connect to?

| username: yulei7633 | Original post link

haproxy configuration, after connecting, check the number of connections in TiDB to know which machine you are connected to.

| username: 裤衩儿飞上天 | Original post link

  1. select * from INFORMATION_SCHEMA.CLUSTER_PROCESSLIST;

    The INSTANCE column is the TiDB server IP.

  2. Your query is also fine; it might be that the TiDB server is not configured with a hostname.

| username: zhanggame1 | Original post link

What you want to ask is whether you don’t know which node to connect to?
Your SQL query indeed doesn’t work, here’s an SQL query for you:

select instance from INFORMATION_SCHEMA.CLUSTER_PROCESSLIST where id=(select connection_id());
| username: 随缘天空 | Original post link

How do you check the number of connections in the configuration file? Isn’t this set before startup? Also, mine is the same as the official one, I just changed an IP.

| username: 随缘天空 | Original post link

My configuration is:


After replacing my SQL with yours and executing it multiple times, why does it always show the same type of machine? Is it because my strategy is the least number of connections? Since I just created the cluster and it is not in use, each database should have no connections. If they are all 0, shouldn’t it round-robin the connections?

| username: 随缘天空 | Original post link

Yes, after executing the command multiple times in the console, check what the polling strategy is. After replacing my SQL with yours and executing it multiple times, why does it always show the same machine? Is it because my strategy is the least number of connections? Because I just created the cluster and it is not in use yet.

| username: zhanggame1 | Original post link

How many connections did you open? Don’t close the previous connections, open dozens of windows to see how they are connected.

It seems that your testing method has a problem. Closing connections means that for haproxy, the number of connections is 0 every time you connect.

After logging into MySQL, don’t exit. Open a new window to continue logging in, and then check each connection.

| username: chenhanneu | Original post link

In the HAProxy configuration file, the listen admin_stats and stats uri settings allow you to log in and monitor the connection status.

| username: 随缘天空 | Original post link

Yes, I made a mistake. The IP returned by executing multiple instances in the same window is different. Initially, it was my mistake.

| username: 随缘天空 | Original post link

Well, I’m not clear about the specific meaning of the panel parameters right now. I’ll research it later.

| username: system | Original post link

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.