From dd0d4dbc19096308a563bbc1b7ea6eaea8fd6142 Mon Sep 17 00:00:00 2001 From: YuQing <384681@qq.com> Date: Sat, 26 Jul 2025 16:58:25 +0800 Subject: [PATCH] func conn_pool_get_key performance optimization --- src/connection_pool.c | 6 +++++- src/tests/Makefile | 2 +- src/tests/cpool_benchmark.c | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/connection_pool.c b/src/connection_pool.c index 9e6498d..9490dd5 100644 --- a/src/connection_pool.c +++ b/src/connection_pool.c @@ -52,7 +52,11 @@ static int node_init_for_rdma(ConnectionNode *node, static inline void conn_pool_get_key(const ConnectionInfo *conn, char *key, int *key_len) { - *key_len = sprintf(key, "%s-%u", conn->ip_addr, conn->port); + *key_len = strlen(conn->ip_addr); + memcpy(key, conn->ip_addr, *key_len); + *(key + (*key_len)++) = '-'; + *(key + (*key_len)++) = (conn->port >> 8) & 0xFF; + *(key + (*key_len)++) = conn->port & 0xFF; } static int close_conn(ConnectionPool *cp, ConnectionManager *cm, diff --git a/src/tests/Makefile b/src/tests/Makefile index 3a7bd09..7aa22a8 100644 --- a/src/tests/Makefile +++ b/src/tests/Makefile @@ -11,7 +11,7 @@ ALL_PRGS = test_allocator test_skiplist test_multi_skiplist test_mblock test_blo test_server_id_func test_pipe test_atomic test_file_write_hole test_file_lock \ test_pthread_wait test_thread_pool test_data_visible test_mutex_lock_perf \ test_queue_perf test_normalize_path test_sorted_array test_sorted_queue \ - test_thread_local test_memcpy mblock_benchmark + test_thread_local test_memcpy mblock_benchmark cpool_benchmark all: $(ALL_PRGS) diff --git a/src/tests/cpool_benchmark.c b/src/tests/cpool_benchmark.c index 2a5b6fd..b2c49d7 100644 --- a/src/tests/cpool_benchmark.c +++ b/src/tests/cpool_benchmark.c @@ -28,7 +28,7 @@ #include "fastcommon/connection_pool.h" static int thread_count = 2; -static int64_t loop_count = 1000000; +static int64_t loop_count = 10000000; static ConnectionPool cpool; static void *thread_run(void *args)