From a1ae1cbcb09158cfcec7eeb8df73890e34e8dd74 Mon Sep 17 00:00:00 2001 From: YuQing <384681@qq.com> Date: Sat, 26 Jul 2025 15:02:23 +0800 Subject: [PATCH] add file: src/tests/cpool_benchmark.c --- .gitignore | 1 + src/tests/cpool_benchmark.c | 144 ++++++++++++++++++++++++++++++++++++ 2 files changed, 145 insertions(+) create mode 100644 src/tests/cpool_benchmark.c diff --git a/.gitignore b/.gitignore index c9008a7..f74980c 100644 --- a/.gitignore +++ b/.gitignore @@ -63,6 +63,7 @@ src/tests/test_sorted_queue src/tests/test_thread_local src/tests/test_memcpy src/tests/mblock_benchmark +src/tests/cpool_benchmark # other *.swp diff --git a/src/tests/cpool_benchmark.c b/src/tests/cpool_benchmark.c new file mode 100644 index 0000000..2a5b6fd --- /dev/null +++ b/src/tests/cpool_benchmark.c @@ -0,0 +1,144 @@ +/* + * Copyright (c) 2025 YuQing <384681@qq.com> + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the Lesser GNU General Public License, version 3 + * or later ("LGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the Lesser GNU General Public License + * along with this program. If not, see . + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "fastcommon/logger.h" +#include "fastcommon/shared_func.h" +#include "fastcommon/pthread_func.h" +#include "fastcommon/connection_pool.h" + +static int thread_count = 2; +static int64_t loop_count = 1000000; +static ConnectionPool cpool; + +static void *thread_run(void *args) +{ + int thread_index; + int result; + int64_t i; + ConnectionInfo cinfo; + ConnectionInfo *conn; + + thread_index = (long)args; + printf("thread #%d start\n", thread_index); + + if ((result=conn_pool_parse_server_info("127.0.0.1:23000", &cinfo, 23000)) != 0) { + return NULL; + } + for (i=0; i