From 09e23958af17aee360933e0cf1deb9b75f02a004 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?shuxin=20=E3=80=80=E3=80=80zheng?= Date: Wed, 21 Aug 2024 14:05:18 +0800 Subject: [PATCH] Test connection pool. --- lib_acl_cpp/src/connpool/connect_manager.cpp | 12 +++++------- lib_acl_cpp/src/connpool/connect_pool.cpp | 9 ++++----- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/lib_acl_cpp/src/connpool/connect_manager.cpp b/lib_acl_cpp/src/connpool/connect_manager.cpp index 20dc4aead..6669ba9cd 100644 --- a/lib_acl_cpp/src/connpool/connect_manager.cpp +++ b/lib_acl_cpp/src/connpool/connect_manager.cpp @@ -513,7 +513,7 @@ void connect_manager::keep_min_conns(const std::vector& pools, void connect_manager::pools_dump(size_t step, std::vector& out) { - size_t pools_size, check_max, check_pos; + size_t pools_size; unsigned long id = get_id(); lock_.lock(); @@ -529,12 +529,10 @@ void connect_manager::pools_dump(size_t step, std::vector& out) step = pools_size; } - check_pos = pools.check_next++ % pools_size; - check_max = check_pos + step; - - while (check_pos < pools_size && check_pos < check_max) { - connect_pool* pool = pools.pools[check_pos++ % pools_size]; - pool->refer(); // Increase reference to avoid freed. + for (size_t i = 0; i < step; i++) { + connect_pool* pool = pools.pools[pools.check_next % pools_size]; + pools.check_next++; + pool->refer(); out.push_back(pool); } diff --git a/lib_acl_cpp/src/connpool/connect_pool.cpp b/lib_acl_cpp/src/connpool/connect_pool.cpp index a2d70c35f..3effc050d 100644 --- a/lib_acl_cpp/src/connpool/connect_pool.cpp +++ b/lib_acl_cpp/src/connpool/connect_pool.cpp @@ -524,7 +524,6 @@ size_t connect_pool::check_dead(size_t count) size_t connect_pool::check_dead(size_t count, thread_pool& threads) { // Check all connections in threads pool. - size_t n = 0; tbox box; std::vector jobs; @@ -553,8 +552,8 @@ size_t connect_pool::check_dead(size_t count, thread_pool& threads) struct timeval end; gettimeofday(&end, NULL); double tc = stamp_sub(end, begin); - logger("Threads: limit=%zd, count=%d; jobs count=%zd, %zd, time cost=%.2f ms", - threads.get_limit(), threads.threads_count(), jobs.size(), count, tc); + logger("Addr: %s; threads: limit=%zd, count=%d; jobs count=%zd, %zd, time cost=%.2f ms", + addr_, threads.get_limit(), threads.threads_count(), jobs.size(), count, tc); for (std::vector::iterator it = jobs.begin(); it != jobs.end(); ++it) { @@ -716,8 +715,8 @@ void connect_pool::keep_conns(size_t min, thread_pool& threads) struct timeval end; gettimeofday(&end, NULL); double tc = stamp_sub(end, begin); - logger("Threads: limit=%zd, count=%d; jobs count=%zd, time cost=%.2f ms", - threads.get_limit(), threads.threads_count(), jobs.size(), tc); + logger("Addr=%s; threads: limit=%zd, count=%d; jobs count=%zd, time cost=%.2f ms", + addr_, threads.get_limit(), threads.threads_count(), jobs.size(), tc); for (std::vector::iterator it = jobs.begin(); it != jobs.end(); ++it) {