Compare commits
No commits in common. "dd0d4dbc19096308a563bbc1b7ea6eaea8fd6142" and "fda26794357b0473feb39216cc5f5033bf6642fb" have entirely different histories.
dd0d4dbc19
...
fda2679435
|
|
@ -63,7 +63,6 @@ src/tests/test_sorted_queue
|
||||||
src/tests/test_thread_local
|
src/tests/test_thread_local
|
||||||
src/tests/test_memcpy
|
src/tests/test_memcpy
|
||||||
src/tests/mblock_benchmark
|
src/tests/mblock_benchmark
|
||||||
src/tests/cpool_benchmark
|
|
||||||
|
|
||||||
# other
|
# other
|
||||||
*.swp
|
*.swp
|
||||||
|
|
|
||||||
|
|
@ -52,11 +52,7 @@ static int node_init_for_rdma(ConnectionNode *node,
|
||||||
static inline void conn_pool_get_key(const ConnectionInfo *conn,
|
static inline void conn_pool_get_key(const ConnectionInfo *conn,
|
||||||
char *key, int *key_len)
|
char *key, int *key_len)
|
||||||
{
|
{
|
||||||
*key_len = strlen(conn->ip_addr);
|
*key_len = sprintf(key, "%s-%u", conn->ip_addr, conn->port);
|
||||||
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,
|
static int close_conn(ConnectionPool *cp, ConnectionManager *cm,
|
||||||
|
|
|
||||||
|
|
@ -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_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_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_queue_perf test_normalize_path test_sorted_array test_sorted_queue \
|
||||||
test_thread_local test_memcpy mblock_benchmark cpool_benchmark
|
test_thread_local test_memcpy mblock_benchmark
|
||||||
|
|
||||||
all: $(ALL_PRGS)
|
all: $(ALL_PRGS)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,144 +0,0 @@
|
||||||
/*
|
|
||||||
* 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 <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <math.h>
|
|
||||||
#include <time.h>
|
|
||||||
#include <inttypes.h>
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include <sys/time.h>
|
|
||||||
#include <sys/stat.h>
|
|
||||||
#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 = 10000000;
|
|
||||||
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<loop_count; i++) {
|
|
||||||
if ((conn=conn_pool_get_connection_ex(&cpool, &cinfo,
|
|
||||||
NULL, true, &result)) == NULL)
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
conn_pool_close_connection(&cpool, conn);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (i == loop_count) {
|
|
||||||
printf("thread #%d done\n", thread_index);
|
|
||||||
} else {
|
|
||||||
printf("thread #%d loop count: %"PRId64"\n", thread_index, i);
|
|
||||||
}
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
|
||||||
{
|
|
||||||
const int stack_size = 64 * 1024;
|
|
||||||
const int connect_timeout = 2;
|
|
||||||
const int max_count_per_entry = 0;
|
|
||||||
const int max_idle_time = 3600;
|
|
||||||
const int htable_capacity = 163;
|
|
||||||
const int extra_data_size = 0;
|
|
||||||
int result;
|
|
||||||
int i;
|
|
||||||
int64_t qps;
|
|
||||||
pthread_t *tids;
|
|
||||||
pthread_attr_t thread_attr;
|
|
||||||
int64_t start_time;
|
|
||||||
int64_t end_time;
|
|
||||||
int64_t time_used;
|
|
||||||
ConnectionExtraParams params;
|
|
||||||
|
|
||||||
log_init();
|
|
||||||
g_log_context.log_level = LOG_INFO;
|
|
||||||
g_schedule_flag = true;
|
|
||||||
g_current_time = time(NULL);
|
|
||||||
|
|
||||||
memset(¶ms, 0, sizeof(params));
|
|
||||||
params.tls.enabled = false;
|
|
||||||
params.tls.htable_capacity = 13;
|
|
||||||
if ((result=conn_pool_init_ex1(&cpool, connect_timeout, max_count_per_entry,
|
|
||||||
max_idle_time, htable_capacity, NULL, NULL, NULL, NULL,
|
|
||||||
extra_data_size, ¶ms)) != 0)
|
|
||||||
{
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((result=pthread_attr_init(&thread_attr)) != 0) {
|
|
||||||
logError("file: "__FILE__", line: %d, "
|
|
||||||
"call pthread_attr_init fail, "
|
|
||||||
"errno: %d, error info: %s",
|
|
||||||
__LINE__, result, STRERROR(result));
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
if ((result=pthread_attr_setstacksize(&thread_attr,
|
|
||||||
stack_size)) != 0)
|
|
||||||
{
|
|
||||||
logError("file: "__FILE__", line: %d, "
|
|
||||||
"call pthread_attr_setstacksize to %d fail, "
|
|
||||||
"errno: %d, error info: %s", __LINE__,
|
|
||||||
stack_size, result, STRERROR(result));
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
tids = fc_malloc(sizeof(pthread_t) * thread_count);
|
|
||||||
|
|
||||||
start_time = get_current_time_us();
|
|
||||||
for (i=0; i<thread_count; i++) {
|
|
||||||
if ((result=pthread_create(tids + i, &thread_attr,
|
|
||||||
thread_run, (void *)((long)i))) != 0)
|
|
||||||
{
|
|
||||||
logError("file: "__FILE__", line: %d, "
|
|
||||||
"create thread failed, "
|
|
||||||
"errno: %d, error info: %s",
|
|
||||||
__LINE__, result, STRERROR(result));
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i=0; i<thread_count; i++) {
|
|
||||||
pthread_join(tids[i], NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
end_time = get_current_time_us();
|
|
||||||
time_used = end_time - start_time;
|
|
||||||
qps = (thread_count * loop_count * 1000 * 1000) / time_used;
|
|
||||||
printf("time used: %"PRId64" ms, QPS: %"PRId64"\n", time_used / 1000, qps);
|
|
||||||
|
|
||||||
free(tids);
|
|
||||||
conn_pool_destroy(&cpool);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue