From 3010a9c5d10912a7742b09449d36513eee9b4992 Mon Sep 17 00:00:00 2001 From: liangwenjia <1757640220@qq.com> Date: Tue, 18 Jun 2024 10:21:58 +0800 Subject: [PATCH 1/2] add connection balance mtr --- .../r/threadpool_connection_balance.result | 42 ++++++++++++ .../t/threadpool_connection_balance.test | 68 +++++++++++++++++++ 2 files changed, 110 insertions(+) create mode 100644 mysql-test/suite/thread_pool/r/threadpool_connection_balance.result create mode 100644 mysql-test/suite/thread_pool/t/threadpool_connection_balance.test diff --git a/mysql-test/suite/thread_pool/r/threadpool_connection_balance.result b/mysql-test/suite/thread_pool/r/threadpool_connection_balance.result new file mode 100644 index 000000000..18726afca --- /dev/null +++ b/mysql-test/suite/thread_pool/r/threadpool_connection_balance.result @@ -0,0 +1,42 @@ +# restart: --plugin-load-add=thread_pool.so --thread_pool_size=9 --thread_pool_connection_balance=ON --admin-address=127.0.0.1 --admin-port=ADMIN_PORT --innodb_lock_wait_timeout=3600 --loose-debug-sync-timeout=300 +SELECT 1; +SELECT 1; +SELECT 1; +SELECT 1; +SELECT 1; +SELECT 1; +SELECT 1; +SELECT 1; +SELECT 1; +SELECT CONNECTIONS FROM INFORMATION_SCHEMA.THREAD_POOL_GROUPS; +CONNECTIONS +1 +1 +1 +1 +1 +1 +1 +1 +2 +SET GLOBAL thread_pool_size=3; +SELECT 1; +SELECT 1; +SELECT 1; +SELECT 1; +SELECT 1; +SELECT 1; +SELECT 1; +SELECT 1; +SELECT 1; +SELECT CONNECTIONS FROM INFORMATION_SCHEMA.THREAD_POOL_GROUPS; +CONNECTIONS +3 +3 +3 +0 +0 +0 +0 +0 +1 diff --git a/mysql-test/suite/thread_pool/t/threadpool_connection_balance.test b/mysql-test/suite/thread_pool/t/threadpool_connection_balance.test new file mode 100644 index 000000000..9691620f7 --- /dev/null +++ b/mysql-test/suite/thread_pool/t/threadpool_connection_balance.test @@ -0,0 +1,68 @@ +# Restart with plugin-load-add=thread_pool.so + +--disable_query_log +CALL mtr.add_suppression("Failed to initialize TLS for channel: mysql_admin"); +CALL mtr.add_suppression("Failed to set up SSL because of the following SSL library error"); +--enable_query_log + +# Calculate value for admin port +--let $PORT_OFFSET = 1 +--expr $ADMIN_PORT = $MASTER_MYPORT + $PORT_OFFSET + +--let $restart_parameters=restart: --plugin-load-add=thread_pool.so --thread_pool_size=9 --thread_pool_connection_balance=ON --admin-address=127.0.0.1 --admin-port=$ADMIN_PORT --innodb_lock_wait_timeout=3600 --loose-debug-sync-timeout=300 +--replace_result $ADMIN_PORT ADMIN_PORT +--source include/restart_mysqld.inc + +connect(conn0,127.0.0.1,root,,,); +connect(conn1,127.0.0.1,root,,,); +connect(conn2,127.0.0.1,root,,,); +connect(conn3,127.0.0.1,root,,,); +connect(conn4,127.0.0.1,root,,,); +connect(conn5,127.0.0.1,root,,,); +connect(conn6,127.0.0.1,root,,,); +connect(conn7,127.0.0.1,root,,,); +connect(conn8,127.0.0.1,root,,,); +connect(extracon,127.0.0.1,root,,,$ADMIN_PORT); + +--let $counter=0 +while ($counter<9) +{ + connection conn$counter; + --disable_result_log + SELECT 1; + --enable_result_log + + --inc $counter +} + +connection extracon; +SELECT CONNECTIONS FROM INFORMATION_SCHEMA.THREAD_POOL_GROUPS; +SET GLOBAL thread_pool_size=3; + +--let $counter=0 +while ($counter<9) +{ + connection conn$counter; + --disable_result_log + SELECT 1; + --enable_result_log + --sleep 1 + + --inc $counter +} + +connection extracon; +# Test that under this circumstance, information offered by information schema is as expected +# I_S.THREAD_POOL_GROUPS +SELECT CONNECTIONS FROM INFORMATION_SCHEMA.THREAD_POOL_GROUPS; + +disconnect conn0; +disconnect conn1; +disconnect conn2; +disconnect conn3; +disconnect conn4; +disconnect conn5; +disconnect conn6; +disconnect conn7; +disconnect conn8; +disconnect extracon; \ No newline at end of file -- Gitee From e0f2419cd522aa52af16e5e09439028c1e90aea4 Mon Sep 17 00:00:00 2001 From: liangwenjia <1757640220@qq.com> Date: Thu, 8 Aug 2024 10:15:42 +0800 Subject: [PATCH 2/2] modify mtr --- mysql-test/suite/thread_pool/t/threadpool_admin_port.test | 2 ++ mysql-test/suite/thread_pool/t/threadpool_pool_size.test | 2 ++ mysql-test/suite/thread_pool/t/threadpool_too_busy_active.test | 2 ++ .../suite/thread_pool/t/threadpool_too_busy_wait-debug.test | 1 + 4 files changed, 7 insertions(+) diff --git a/mysql-test/suite/thread_pool/t/threadpool_admin_port.test b/mysql-test/suite/thread_pool/t/threadpool_admin_port.test index 99eb0d62f..90a091771 100644 --- a/mysql-test/suite/thread_pool/t/threadpool_admin_port.test +++ b/mysql-test/suite/thread_pool/t/threadpool_admin_port.test @@ -64,7 +64,9 @@ connect(admin_local_con,localhost,root,,,$ADMIN_PORT,,TCP); connection admin_local_con; SELECT CURRENT_USER(); +--disable_warnings ER_WARN_DEPRECATED_SYNTAX select user, command, state, info from information_schema.processlist where user = "root" order by id asc; +--enable_warnings ER_WARN_DEPRECATED_SYNTAX --disable_query_log eval KILL QUERY $conn0_id; diff --git a/mysql-test/suite/thread_pool/t/threadpool_pool_size.test b/mysql-test/suite/thread_pool/t/threadpool_pool_size.test index 30aff1b38..3646ba877 100644 --- a/mysql-test/suite/thread_pool/t/threadpool_pool_size.test +++ b/mysql-test/suite/thread_pool/t/threadpool_pool_size.test @@ -34,7 +34,9 @@ SEND SELECT benchmark(9999999999, md5('very long command 2')); # Test that only one command is being executed connection extracon; +--disable_warnings ER_WARN_DEPRECATED_SYNTAX SELECT COUNT(Id) FROM INFORMATION_SCHEMA.processlist where Info like 'SELECT benchmark(9999999999, md5(\'very long command%'; +--enable_warnings ER_WARN_DEPRECATED_SYNTAX # Test that under this circumstance, information offered by information schema is as expected # I_S.THREAD_POOL_GROUPS SELECT SUM(CONNECTIONS) FROM INFORMATION_SCHEMA.THREAD_POOL_GROUPS; diff --git a/mysql-test/suite/thread_pool/t/threadpool_too_busy_active.test b/mysql-test/suite/thread_pool/t/threadpool_too_busy_active.test index 44fa02969..cd4bb941c 100644 --- a/mysql-test/suite/thread_pool/t/threadpool_too_busy_active.test +++ b/mysql-test/suite/thread_pool/t/threadpool_too_busy_active.test @@ -26,6 +26,8 @@ connection conn2; --let $conn2_id = `SELECT connection_id()` SEND SELECT benchmark(9999999999, md5('very long command 2')); +--sleep 1 + # Test that new connection cannot be established --disable_abort_on_error --echo You should see a Lost connection message diff --git a/mysql-test/suite/thread_pool/t/threadpool_too_busy_wait-debug.test b/mysql-test/suite/thread_pool/t/threadpool_too_busy_wait-debug.test index e1371b5e7..2d626cc64 100644 --- a/mysql-test/suite/thread_pool/t/threadpool_too_busy_wait-debug.test +++ b/mysql-test/suite/thread_pool/t/threadpool_too_busy_wait-debug.test @@ -41,6 +41,7 @@ SELECT * FROM db1.t1 WHERE c1=2 FOR UPDATE; connection conn1; START TRANSACTION; SEND SELECT * FROM db1.t1 WHERE c1=2 LOCK IN SHARE MODE; +--sleep 1 connection conn2; START TRANSACTION; -- Gitee