summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfumingwei <[email protected]>2023-09-05 21:57:46 +0800
committerfumingwei <[email protected]>2023-09-06 14:47:15 +0800
commit2693d6332e0368f90d4de86ffc4c0a1369d4f247 (patch)
tree08810ffae483c49d6ac23d96f3341192a79f957e
parentd30b79a2fe8fb940ded4265882572bc9602606e9 (diff)
support mulit type lockv3.0.15
-rw-r--r--src/fieldstat_dynamic.cpp139
-rw-r--r--src/fieldstat_internal.h24
-rw-r--r--src/line_protocol_output.cpp20
-rw-r--r--test/src/gtest_dynamic_benchmark.cpp122
4 files changed, 293 insertions, 12 deletions
diff --git a/src/fieldstat_dynamic.cpp b/src/fieldstat_dynamic.cpp
index 275a91d..a0d195e 100644
--- a/src/fieldstat_dynamic.cpp
+++ b/src/fieldstat_dynamic.cpp
@@ -25,12 +25,30 @@ struct fieldstat_dynamic_instance * fieldstat_dynamic_instance_new(const char *n
instance->n_thread = n_thread;
instance->n_thread_dynamic_metric = (struct dynamic_metric **)calloc(instance->n_thread, sizeof(struct dynamic_metric *));
+#if USING_SPINLOCK
instance->uthash_locks = (struct uthash_spinlock *)calloc(n_thread, sizeof(struct uthash_spinlock));
for(int i = 0; i < n_thread; i++)
{
struct uthash_spinlock *uthash_lock = instance->uthash_locks + i;
pthread_spin_init(&(uthash_lock->lock), PTHREAD_PROCESS_SHARED);
}
+#endif
+#if USING_RWLOCK
+ instance->uthash_locks = (struct uthash_rwlock *)calloc(n_thread, sizeof(struct uthash_rwlock));
+ for(int i = 0; i < n_thread; i++)
+ {
+ struct uthash_rwlock *uthash_lock = instance->uthash_locks + i;
+ pthread_rwlock_init(&(uthash_lock->lock), NULL);
+ }
+#endif
+#if USING_MUTEX
+ instance->uthash_locks = (struct uthash_mutex *)calloc(n_thread, sizeof(struct uthash_mutex));
+ for(int i = 0; i < n_thread; i++)
+ {
+ struct uthash_mutex *uthash_lock = instance->uthash_locks + i;
+ pthread_mutex_init(&(uthash_lock->lock), NULL);
+ }
+#endif
return instance;
}
@@ -97,7 +115,7 @@ void fieldstat_dynamic_instance_free(struct fieldstat_dynamic_instance *instance
table_metric_free(instance->table_metrics[i]);
instance->table_metrics[i] = NULL;
}
-
+#if USING_SPINLOCK
if(instance->uthash_locks)
{
for(i = 0; i < instance->n_thread; i++)
@@ -108,6 +126,31 @@ void fieldstat_dynamic_instance_free(struct fieldstat_dynamic_instance *instance
free((void *)instance->uthash_locks);
instance->uthash_locks = NULL;
}
+#endif
+#if USING_RWLOCK
+ if(instance->uthash_locks)
+ {
+ for(i = 0; i < instance->n_thread; i++)
+ {
+ struct uthash_rwlock *uthash_lock = instance->uthash_locks + i;
+ pthread_rwlock_destroy(&(uthash_lock->lock));
+ }
+ free((void *)instance->uthash_locks);
+ instance->uthash_locks = NULL;
+ }
+#endif
+#if USING_MUTEX
+ if(instance->uthash_locks)
+ {
+ for(i = 0; i < instance->n_thread; i++)
+ {
+ struct uthash_mutex *uthash_lock = instance->uthash_locks + i;
+ pthread_mutex_destroy(&(uthash_lock->lock));
+ }
+ free((void *)instance->uthash_locks);
+ instance->uthash_locks = NULL;
+ }
+#endif
free(instance->n_thread_dynamic_metric);
instance->n_thread_dynamic_metric = NULL;
free(instance);
@@ -345,10 +388,30 @@ static struct metric * read_dynamic_metric(struct fieldstat_dynamic_instance *in
return NULL;
}
+#if USING_SPINLOCK
struct uthash_spinlock *uthash_lock = instance->uthash_locks + thread_id;
pthread_spin_lock(&(uthash_lock->lock));
+#endif
+#if USING_RWLOCK
+ struct uthash_rwlock *uthash_lock = instance->uthash_locks + thread_id;
+ pthread_rwlock_rdlock(&(uthash_lock->lock));
+#endif
+
+#if USING_MUTEX
+ struct uthash_mutex *uthash_lock = instance->uthash_locks + thread_id;
+ pthread_mutex_lock(&(uthash_lock->lock));
+#endif
+
HASH_FIND(hh, *head, dynamic_metric_key, dynamic_metric_keylen, find);
+#if USING_SPINLOCK
pthread_spin_unlock(&(uthash_lock->lock));
+#endif
+#if USING_RWLOCK
+ pthread_rwlock_unlock(&(uthash_lock->lock));
+#endif
+#if USING_MUTEX
+ pthread_mutex_unlock(&(uthash_lock->lock));
+#endif
if(find == NULL)
{
return NULL;
@@ -424,10 +487,28 @@ static struct metric * create_dynamic_table_metric(struct fieldstat_dynamic_inst
value->metrics[i] = metric;
}
+#if USING_SPINLOCK
struct uthash_spinlock *uthash_lock = instance->uthash_locks + thread_id;
pthread_spin_lock(&(uthash_lock->lock));
+#endif
+#if USING_RWLOCK
+ struct uthash_rwlock *uthash_lock = instance->uthash_locks + thread_id;
+ pthread_rwlock_wrlock(&(uthash_lock->lock));
+#endif
+#if USING_MUTEX
+ struct uthash_mutex *uthash_lock = instance->uthash_locks + thread_id;
+ pthread_mutex_lock(&(uthash_lock->lock));
+#endif
HASH_ADD_KEYPTR(hh, *head, value->metric_key, value->metric_keylen, value);
+#if USING_SPINLOCK
pthread_spin_unlock(&(uthash_lock->lock));
+#endif
+#if USING_RWLOCK
+ pthread_rwlock_unlock(&(uthash_lock->lock));
+#endif
+#if USING_MUTEX
+ pthread_mutex_unlock(&(uthash_lock->lock));
+#endif
return value->metrics[column_id];
}
@@ -475,10 +556,28 @@ static struct metric * create_dynamic_metric(struct fieldstat_dynamic_instance *
}
*(insert->metrics) = metric;
+#if USING_SPINLOCK
struct uthash_spinlock *uthash_lock = instance->uthash_locks + thread_id;
pthread_spin_lock(&(uthash_lock->lock));
+#endif
+#if USING_RWLOCK
+ struct uthash_rwlock *uthash_lock = instance->uthash_locks + thread_id;
+ pthread_rwlock_wrlock(&(uthash_lock->lock));
+#endif
+#if USING_MUTEX
+ struct uthash_mutex *uthash_lock = instance->uthash_locks + thread_id;
+ pthread_mutex_lock(&(uthash_lock->lock));
+#endif
HASH_ADD_KEYPTR(hh, *head, insert->metric_key, insert->metric_keylen, insert);
+#if USING_SPINLOCK
pthread_spin_unlock(&(uthash_lock->lock));
+#endif
+#if USING_RWLOCK
+ pthread_rwlock_unlock(&(uthash_lock->lock));
+#endif
+#if USING_MUTEX
+ pthread_mutex_unlock(&(uthash_lock->lock));
+#endif
return metric;
}
@@ -588,11 +687,28 @@ static struct metric **read_dynamic_row_metrics(
struct dynamic_metric *find = NULL;
head = &instance->n_thread_dynamic_metric[thread_id];
-
+#if USING_SPINLOCK
struct uthash_spinlock *uthash_lock = instance->uthash_locks + thread_id;
pthread_spin_lock(&(uthash_lock->lock));
+#endif
+#if USING_RWLOCK
+ struct uthash_rwlock *uthash_lock = instance->uthash_locks + thread_id;
+ pthread_rwlock_rdlock(&(uthash_lock->lock));
+#endif
+#if USING_MUTEX
+ struct uthash_mutex *uthash_lock = instance->uthash_locks + thread_id;
+ pthread_mutex_lock(&(uthash_lock->lock));
+#endif
HASH_FIND(hh, *head, metric_key, metric_keylen, find);
+#if USING_SPINLOCK
pthread_spin_unlock(&(uthash_lock->lock));
+#endif
+#if USING_RWLOCK
+ pthread_rwlock_unlock(&(uthash_lock->lock));
+#endif
+#if USING_MUTEX
+ pthread_mutex_unlock(&(uthash_lock->lock));
+#endif
if(find == NULL)
{
return NULL;
@@ -656,11 +772,28 @@ static struct metric **create_dynamic_table_row_metrics(
metric->table_column_id = i;
value->metrics[i] = metric;
}
-
+#if USING_SPINLOCK
struct uthash_spinlock *uthash_lock = instance->uthash_locks + thread_id;
pthread_spin_lock(&(uthash_lock->lock));
+#endif
+#if USING_RWLOCK
+ struct uthash_rwlock *uthash_lock = instance->uthash_locks + thread_id;
+ pthread_rwlock_wrlock(&(uthash_lock->lock));
+#endif
+#if USING_MUTEX
+ struct uthash_mutex *uthash_lock = instance->uthash_locks + thread_id;
+ pthread_mutex_lock(&(uthash_lock->lock));
+#endif
HASH_ADD_KEYPTR(hh, *head, value->metric_key, value->metric_keylen, value);
+#if USING_SPINLOCK
pthread_spin_unlock(&(uthash_lock->lock));
+#endif
+#if USING_RWLOCK
+ pthread_rwlock_unlock(&(uthash_lock->lock));
+#endif
+#if USING_MUTEX
+ pthread_mutex_unlock(&(uthash_lock->lock));
+#endif
return value->metrics;
}
diff --git a/src/fieldstat_internal.h b/src/fieldstat_internal.h
index 132f9f5..628f348 100644
--- a/src/fieldstat_internal.h
+++ b/src/fieldstat_internal.h
@@ -68,6 +68,10 @@
#define CACHE_LINE_SIZE 64
+#define USING_SPINLOCK 1
+#define USING_RWLOCK 0
+#define USING_MUTEX 0
+
enum field_calc_algo
{
FS_CALC_CURRENT=0,
@@ -226,6 +230,18 @@ struct uthash_spinlock
pthread_spinlock_t lock;
} __attribute__((aligned(CACHE_LINE_SIZE)));
+
+struct uthash_rwlock
+{
+ pthread_rwlock_t lock;
+} __attribute__((aligned(CACHE_LINE_SIZE)));
+
+struct uthash_mutex
+{
+ pthread_mutex_t lock;
+} __attribute__((aligned(CACHE_LINE_SIZE)));
+
+
struct fieldstat_dynamic_instance
{
char name[INSTANCE_NAME_LEN];
@@ -247,7 +263,15 @@ struct fieldstat_dynamic_instance
int n_thread;
int output_type; // 0b0000:not output, 0b1000:output file, 0b0100:output line_protocol, 0b0010: output statsd, 0b0001: output prometheus
//pthread_spinlock_t *uthash_locks;
+#if USING_SPINLOCK
struct uthash_spinlock *uthash_locks;
+#endif
+#if USING_RWLOCK
+ struct uthash_rwlock *uthash_locks;
+#endif
+#if USING_MUTEX
+ struct uthash_mutex *uthash_locks;
+#endif
};
void prometheus_endpoint_instance_output(struct http_request_s* request);
diff --git a/src/line_protocol_output.cpp b/src/line_protocol_output.cpp
index 3c687ed..5c01512 100644
--- a/src/line_protocol_output.cpp
+++ b/src/line_protocol_output.cpp
@@ -481,9 +481,18 @@ int line_protocol_dynamic_metric_output(struct fieldstat_dynamic_instance *insta
for(int i = 0; i < instance->n_thread; i++)
{
std::vector<std::string> line_buf_to_send;
+#if USING_SPINLOCK
struct uthash_spinlock *uthash_lock = instance->uthash_locks + i;
-
pthread_spin_lock(&(uthash_lock->lock));
+#endif
+#if USING_RWLOCK
+ struct uthash_rwlock *uthash_lock = instance->uthash_locks + i;
+ pthread_rwlock_wrlock(&(uthash_lock->lock));
+#endif
+#if USING_MUTEX
+ struct uthash_mutex *uthash_lock = instance->uthash_locks + i;
+ pthread_mutex_lock(&(uthash_lock->lock));
+#endif
head = &instance->n_thread_dynamic_metric[i];
HASH_ITER(hh, *head, dyn_metric, tmp_dyn_metric)
{
@@ -504,8 +513,15 @@ int line_protocol_dynamic_metric_output(struct fieldstat_dynamic_instance *insta
/* copy the line_buf as str to vector line_buf_to_send */
line_buf_to_send.push_back(std::string(line_buf));
}
+#if USING_SPINLOCK
pthread_spin_unlock(&(uthash_lock->lock));
-
+#endif
+#if USING_RWLOCK
+ pthread_rwlock_unlock(&(uthash_lock->lock));
+#endif
+#if USING_MUTEX
+ pthread_mutex_unlock(&(uthash_lock->lock));
+#endif
for (std::vector<std::string>::iterator it = line_buf_to_send.begin(); it != line_buf_to_send.end(); ++it)
{
const std::string& str = *it;
diff --git a/test/src/gtest_dynamic_benchmark.cpp b/test/src/gtest_dynamic_benchmark.cpp
index 01e22e2..b93df70 100644
--- a/test/src/gtest_dynamic_benchmark.cpp
+++ b/test/src/gtest_dynamic_benchmark.cpp
@@ -8,6 +8,7 @@
#include <math.h>
/*
+date: 2023/9/5
spinlock, output interval: 1ms
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| | Thread num 1 | Thread num 2 | Thread num 4 | Thread num 8 | Thread num 16 | Thread num 32 | Thread num 64 |
@@ -32,8 +33,7 @@ spinlock, output interval: 1ms
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| 100,000,000 | 19,425,541 | 30,764,254 | 57,262,235 | 97,336,038 | 117,999,613 | 156,962,386 | 203,782,206 |
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-*/
-/*
+
no spinlock, output interval: 1ms
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| | Thread num 1 | Thread num 2 | Thread num 4 | Thread num 8 | Thread num 16 | Thread num 32 | Thread num 64 |
@@ -58,8 +58,7 @@ no spinlock, output interval: 1ms
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| 100,000,000 | 18,784,181 | 18,827,600 | 18,812,896 | 18,875,007 | 18,833,475 | 18,811,591 | 26,965,032 |
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-*/
-/*
+
spinlock with Struct Alignment, output interval: 1ms
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| | Thread num 1 | Thread num 2 | Thread num 4 | Thread num 8 | Thread num 16 | Thread num 32 | Thread num 64 |
@@ -86,6 +85,112 @@ spinlock with Struct Alignment, output interval: 1ms
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
*/
+
+/*
+date: 2023/9/6
+
+no lock, output interval 1ms
+ --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+ | | Thread num 1 | Thread num 2 | Thread num 4 | Thread num 8 | Thread num 16 | Thread num 32 | Thread num 64 |
+ --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+ | operate counter | operation duration(us) | operation duration(us) | operation duration(us) | operation duration(us) | operation duration(us) | operation duration(us) | operation duration(us) |
+ --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+ | 1 | 42 | 28 | 17 | 22 | 59 | 42 | 40 |
+ --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+ | 10 | 29 | 14 | 10 | 11 | 12 | 11 | 9 |
+ --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+ | 100 | 32 | 31 | 34 | 31 | 32 | 30 | 29 |
+ --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+ | 1,000 | 200 | 208 | 208 | 212 | 213 | 212 | 208 |
+ --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+ | 10,000 | 1,989 | 1,975 | 1,953 | 1,932 | 1,952 | 1,958 | 1,948 |
+ --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+ | 100,000 | 20,193 | 19,209 | 19,306 | 19,126 | 19,257 | 19,336 | 21,010 |
+ --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+ | 1,000,000 | 193,482 | 191,674 | 192,383 | 192,317 | 193,822 | 192,023 | 254,656 |
+ --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+ | 10,000,000 | 1,936,361 | 1,931,578 | 1,936,618 | 1,921,114 | 1,926,897 | 1,920,143 | 2,595,562 |
+ --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+ | 100,000,000 | 19,245,473 | 19,243,094 | 19,204,994 | 19,193,001 | 19,196,800 | 19,181,999 | 27,619,589 |
+ --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+
+spinlock, output interval 1ms
+ --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+ | | Thread num 1 | Thread num 2 | Thread num 4 | Thread num 8 | Thread num 16 | Thread num 32 | Thread num 64 |
+ --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+ | operate counter | operation duration(us) | operation duration(us) | operation duration(us) | operation duration(us) | operation duration(us) | operation duration(us) | operation duration(us) |
+ --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+ | 1 | 59 | 18 | 20 | 24 | 38 | 40 | 38 |
+ --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+ | 10 | 27 | 13 | 12 | 13 | 11 | 11 | 9 |
+ --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+ | 100 | 29 | 39 | 32 | 30 | 31 | 30 | 29 |
+ --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+ | 1,000 | 209 | 211 | 327 | 203 | 207 | 206 | 203 |
+ --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+ | 10,000 | 1,896 | 1,897 | 3,162 | 1,893 | 1,897 | 1,905 | 1,908 |
+ --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+ | 100,000 | 18,734 | 18,718 | 31,251 | 18,751 | 18,738 | 18,820 | 20,910 |
+ --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+ | 1,000,000 | 186,970 | 187,683 | 187,262 | 187,649 | 188,037 | 188,369 | 247,677 |
+ --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+ | 10,000,000 | 1,877,762 | 1,880,236 | 1,876,492 | 1,875,297 | 1,878,232 | 1,879,564 | 2,603,063 |
+ --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+ | 100,000,000 | 18,720,506 | 18,736,390 | 18,740,244 | 18,769,749 | 18,779,667 | 18,806,123 | 26,277,081 |
+ --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+
+rwlock, output interval 1ms
+ --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+ | | Thread num 1 | Thread num 2 | Thread num 4 | Thread num 8 | Thread num 16 | Thread num 32 | Thread num 64 |
+ --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+ | operate counter | operation duration(us) | operation duration(us) | operation duration(us) | operation duration(us) | operation duration(us) | operation duration(us) | operation duration(us) |
+ --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+ | 1 | 52 | 18 | 18 | 48 | 61 | 41 | 44 |
+ --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+ | 10 | 30 | 13 | 13 | 11 | 12 | 10 | 19 |
+ --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+ | 100 | 42 | 37 | 34 | 34 | 34 | 31 | 32 |
+ --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+ | 1,000 | 230 | 222 | 377 | 311 | 224 | 222 | 345 |
+ --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+ | 10,000 | 2,101 | 2,369 | 6,710 | 2,944 | 3,537 | 2,069 | 3,560 |
+ --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+ | 100,000 | 20,448 | 24,518 | 39,459 | 30,087 | 34,189 | 20,981 | 38,270 |
+ --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+ | 1,000,000 | 204,923 | 272,109 | 205,070 | 307,572 | 397,855 | 209,094 | 411,857 |
+ --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+ | 10,000,000 | 2,043,604 | 2,048,087 | 3,021,970 | 2,933,224 | 2,070,708 | 2,085,169 | 4,453,767 |
+ --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+ | 100,000,000 | 20,413,678 | 20,465,977 | 26,326,140 | 29,201,649 | 20,692,983 | 20,822,775 | 46,712,568 |
+ --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+
+mutex, output interval 1ms
+ --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+ | | Thread num 1 | Thread num 2 | Thread num 4 | Thread num 8 | Thread num 16 | Thread num 32 | Thread num 64 |
+ --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+ | operate counter | operation duration(us) | operation duration(us) | operation duration(us) | operation duration(us) | operation duration(us) | operation duration(us) | operation duration(us) |
+ --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+ | 1 | 53 | 15 | 29 | 24 | 41 | 44 | 40 |
+ --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+ | 10 | 34 | 13 | 13 | 13 | 13 | 12 | 10 |
+ --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+ | 100 | 37 | 34 | 33 | 31 | 35 | 31 | 31 |
+ --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+ | 1,000 | 220 | 224 | 614 | 223 | 225 | 223 | 224 |
+ --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+ | 10,000 | 2,108 | 2,113 | 4,294 | 2,111 | 2,110 | 2,132 | 2,167 |
+ --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+ | 100,000 | 21,089 | 20,854 | 65,000 | 21,106 | 21,021 | 21,553 | 24,513 |
+ --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+ | 1,000,000 | 210,556 | 270,618 | 209,851 | 209,477 | 382,730 | 215,677 | 285,425 |
+ --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+ | 10,000,000 | 2,091,623 | 2,095,177 | 2,096,735 | 2,093,514 | 2,114,204 | 2,203,298 | 2,920,734 |
+ --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+ | 100,000,000 | 20,968,000 | 20,874,788 | 20,943,953 | 20,944,974 | 21,137,730 | 21,657,745 | 30,985,793 |
+ --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+
+*/
+
struct thread_para
{
int loops;
@@ -108,6 +213,7 @@ void _worker_thread_one_metric(void *arg)
int loops = para->loops;
int thread_id = para->thread_id;
struct fieldstat_dynamic_instance *instance = para->instance;
+ char metric_name[128] = {0};
int ret = 0;
long long start_time, end_time;
@@ -115,8 +221,10 @@ void _worker_thread_one_metric(void *arg)
start_time = current_timestamp();
for(int i = 0; i < loops; i++)
{
+ memset(metric_name, 0, sizeof(metric_name));
+ snprintf(metric_name, sizeof(metric_name), "Active_sessions_%d", i);
ret = fieldstat_dynamic_metric_value_incrby(instance, FIELD_TYPE_GAUGE,
- "Active_sessions", 10,
+ metric_name, 10,
NULL, 0, thread_id);
EXPECT_EQ(0, ret);
}
@@ -196,10 +304,10 @@ TEST(FeildStatDynamicAPI, AllConditions)
int n_thread = 0;
int n_loops = 0;
- for(int i = 0; i < 7; i++)
+ for(int i = 0; i < 5; i++)
{
n_thread = 1 << i;
- for(int j = 0; j < 9; j++)
+ for(int j = 0; j < 6; j++)
{
n_loops = (int)pow(10, (double)j);
fieldstat_dynamic_benchmark(n_thread, n_loops);