Merge branch 'gitee-master' into gitlab-upstream

This commit is contained in:
zhengshuxin 2024-08-21 14:05:51 +08:00
commit e06eb8d5f5
2 changed files with 9 additions and 12 deletions

View File

@ -513,7 +513,7 @@ void connect_manager::keep_min_conns(const std::vector<connect_pool*>& pools,
void connect_manager::pools_dump(size_t step, std::vector<connect_pool*>& out) void connect_manager::pools_dump(size_t step, std::vector<connect_pool*>& out)
{ {
size_t pools_size, check_max, check_pos; size_t pools_size;
unsigned long id = get_id(); unsigned long id = get_id();
lock_.lock(); lock_.lock();
@ -529,12 +529,10 @@ void connect_manager::pools_dump(size_t step, std::vector<connect_pool*>& out)
step = pools_size; step = pools_size;
} }
check_pos = pools.check_next++ % pools_size; for (size_t i = 0; i < step; i++) {
check_max = check_pos + step; connect_pool* pool = pools.pools[pools.check_next % pools_size];
pools.check_next++;
while (check_pos < pools_size && check_pos < check_max) { pool->refer();
connect_pool* pool = pools.pools[check_pos++ % pools_size];
pool->refer(); // Increase reference to avoid freed.
out.push_back(pool); out.push_back(pool);
} }

View File

@ -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) size_t connect_pool::check_dead(size_t count, thread_pool& threads)
{ {
// Check all connections in threads pool. // Check all connections in threads pool.
size_t n = 0; size_t n = 0;
tbox<bool> box; tbox<bool> box;
std::vector<check_job*> jobs; std::vector<check_job*> jobs;
@ -553,8 +552,8 @@ size_t connect_pool::check_dead(size_t count, thread_pool& threads)
struct timeval end; struct timeval end;
gettimeofday(&end, NULL); gettimeofday(&end, NULL);
double tc = stamp_sub(end, begin); double tc = stamp_sub(end, begin);
logger("Threads: limit=%zd, count=%d; jobs count=%zd, %zd, time cost=%.2f ms", logger("Addr: %s; threads: limit=%zd, count=%d; jobs count=%zd, %zd, time cost=%.2f ms",
threads.get_limit(), threads.threads_count(), jobs.size(), count, tc); addr_, threads.get_limit(), threads.threads_count(), jobs.size(), count, tc);
for (std::vector<check_job*>::iterator it = jobs.begin(); for (std::vector<check_job*>::iterator it = jobs.begin();
it != jobs.end(); ++it) { it != jobs.end(); ++it) {
@ -716,8 +715,8 @@ void connect_pool::keep_conns(size_t min, thread_pool& threads)
struct timeval end; struct timeval end;
gettimeofday(&end, NULL); gettimeofday(&end, NULL);
double tc = stamp_sub(end, begin); double tc = stamp_sub(end, begin);
logger("Threads: limit=%zd, count=%d; jobs count=%zd, time cost=%.2f ms", logger("Addr=%s; threads: limit=%zd, count=%d; jobs count=%zd, time cost=%.2f ms",
threads.get_limit(), threads.threads_count(), jobs.size(), tc); addr_, threads.get_limit(), threads.threads_count(), jobs.size(), tc);
for (std::vector<check_job*>::iterator it = jobs.begin(); for (std::vector<check_job*>::iterator it = jobs.begin();
it != jobs.end(); ++it) { it != jobs.end(); ++it) {