diff options
| author | chenzizhan <[email protected]> | 2023-08-01 18:13:26 +0800 |
|---|---|---|
| committer | chenzizhan <[email protected]> | 2023-08-01 18:13:26 +0800 |
| commit | 264a2cfc86ca11527bd7676f6bd51b24a5a9661e (patch) | |
| tree | cfb69d64972c6700005c5d04da146a089e7c5666 /test/test_performance.cpp | |
| parent | 6b14c3c7a6dc22a25b913c0cfda3598b16131005 (diff) | |
readme and more performance tests
Diffstat (limited to 'test/test_performance.cpp')
| -rw-r--r-- | test/test_performance.cpp | 293 |
1 files changed, 205 insertions, 88 deletions
diff --git a/test/test_performance.cpp b/test/test_performance.cpp index 721c339..27ac20e 100644 --- a/test/test_performance.cpp +++ b/test/test_performance.cpp @@ -6,7 +6,7 @@ #include "utils.hpp" -TEST(test_performance, merge_performance_when_comprehensive_sampling) +TEST(test_performance, merge_performance_when_comprehensive_sampling_multi_instance) { const int INSTANCE_NUM = 100; const int MAX_CELL_NUM = 65535; @@ -45,7 +45,7 @@ TEST(test_performance, merge_performance_when_comprehensive_sampling) clock_t end = clock(); double elapsed_secs = double(end - start) / CLOCKS_PER_SEC; - printf("performance_test_when_comprehensive_sampling elapsed_secs: %f\n", elapsed_secs); + printf("merge_performance_when_comprehensive_sampling_multi_instance elapsed_secs: %f\n", elapsed_secs); EXPECT_TRUE(elapsed_secs < 0.1); fieldstat_free(instance_dest); @@ -57,90 +57,166 @@ TEST(test_performance, merge_performance_when_comprehensive_sampling) } } -TEST(test_performance, merge_performance_when_topk_sampling){ - const int INSTANCE_NUM = 100; - const int MAX_CELL_NUM = 1024; - const int DIMENSION_TOTAL = 100000; - const int CUBE_NUM = 100; - - Fieldstat_tag_list_wrapper *tags[DIMENSION_TOTAL]; - for (int i = 0; i < DIMENSION_TOTAL; i++) - { - if (i%2) - tags[i] = new Fieldstat_tag_list_wrapper("my key", i); - else - tags[i] = new Fieldstat_tag_list_wrapper("elephant", i % 1024); - } - - Fieldstat_tag_list_wrapper *shared_tags[CUBE_NUM]; - for (int i = 0; i < CUBE_NUM; i++) - { - shared_tags[i] = new Fieldstat_tag_list_wrapper("shared key", i); +clock_t perform_merge_test(std::function<void (struct fieldstat*, int, int, int)> metric_add_func, + std::function<int(struct fieldstat*, int)> metric_register_func, enum sampling_mode mode, bool merge_empty_dest) +{ + const int MAX_CELL_NUM = 1000; + Fieldstat_tag_list_wrapper *tags[MAX_CELL_NUM]; + for (int i = 0; i < MAX_CELL_NUM; i++) { + tags[i] = new Fieldstat_tag_list_wrapper("my key", i); } - - struct fieldstat *instances[INSTANCE_NUM]; - for (int i = 0; i < INSTANCE_NUM; i++) { - for (int j = 0; j < CUBE_NUM; j++) { - struct fieldstat *tmp_i = fieldstat_new(); - int cube_id = fieldstat_register_cube(tmp_i, shared_tags[j]->get_tag(), 1, SAMPLING_MODE_TOPK, MAX_CELL_NUM); - int metric_id = fieldstat_register_counter(tmp_i, cube_id, "metric name", false); - for (int j = 0; j < MAX_CELL_NUM; j++) { - int cell_id = fieldstat_cube_add(tmp_i, cube_id, tags[rand() % DIMENSION_TOTAL]->get_tag(), 1, 1); - if (cell_id == -1) { - continue; - } - fieldstat_counter_incrby(tmp_i, cube_id, metric_id, cell_id, 1); - } - instances[i] = tmp_i; - } + struct fieldstat *instance = fieldstat_new(); + int cube_id = fieldstat_register_cube(instance, &TEST_SHARED_TAG, 1, mode, MAX_CELL_NUM); + int metric_id = metric_register_func(instance, cube_id); + for (int j = 0; j < MAX_CELL_NUM; j++) { + int cell_id = fieldstat_cube_add(instance, cube_id, tags[j]->get_tag(), 1, 1); + metric_add_func(instance, cube_id, metric_id, cell_id); } struct fieldstat *instance_dest = fieldstat_new(); - printf("prepare done\n"); - clock_t start = clock(); - // getchar(); - for (int i = 0; i < INSTANCE_NUM; i++) { - fieldstat_merge(instance_dest, instances[i]); + if (!merge_empty_dest) { + fieldstat_merge(instance_dest, instance); } - // exit(0); - clock_t end = clock(); - double elapsed_secs = double(end - start) / CLOCKS_PER_SEC; - printf("performance_test_when_comprehensive_sampling elapsed_secs: %f\n", elapsed_secs); - EXPECT_TRUE(elapsed_secs < 0.2); + clock_t start = clock(); + fieldstat_merge(instance_dest, instance); + clock_t end = clock(); fieldstat_free(instance_dest); - for (int i = 0; i < INSTANCE_NUM; i++) { - fieldstat_free(instances[i]); - } - for (int i = 0; i < DIMENSION_TOTAL; i++) { + fieldstat_free(instance); + for (int i = 0; i < MAX_CELL_NUM; i++) { delete tags[i]; } + + return end - start; } -TEST(metric_test_counter, performance_test_on_1_cells_1000000_times) -{ - // getchar(); - struct fieldstat *instance = fieldstat_new(); - fieldstat_register_cube(instance, &TEST_TAG_INT_collided, 1, SAMPLING_MODE_COMPREHENSIVE, 10); - fieldstat_register_counter(instance, 0, "test", 0); - int cell_id = fieldstat_cube_add(instance, 0, &TEST_TAG_DOUBLE, 1, 1); - clock_t start = clock(); - for (size_t i = 0; i < 1000000; i++) { - fieldstat_counter_incrby(instance, 0, 0, cell_id, 1); - } - clock_t end = clock(); - double seconds = (double)(end - start) / CLOCKS_PER_SEC; - printf("performance_test_on_1_cells_1000000_times time cost: %f\n", seconds); - EXPECT_TRUE(seconds < 1); // 1 = 0.000001 * 1000000 - fieldstat_free(instance); +TEST(test_performance, merge_performance_one_instance_comprehensive_counter_empty_dest) +{ + // int metric_id = fieldstat_register_counter(tmp_i, cube_id, "metric name", false); + // fieldstat_counter_incrby(instance, cube_id, metric_id, cell_id, 1); + auto metric_add_func = [](struct fieldstat *instance, int cube_id, int metric_id, int cell_id) { + fieldstat_counter_incrby(instance, cube_id, metric_id, cell_id, 1); + }; + auto metric_register_func = [](struct fieldstat *instance, int cube_id) { + return fieldstat_register_counter(instance, cube_id, "metric name", false); + }; + + clock_t elapsed = perform_merge_test(metric_add_func, metric_register_func, SAMPLING_MODE_COMPREHENSIVE, true); + printf("merge_performance_one_instance_comprehensive_counter_empty_dest elapsed_secs: %ld\n", elapsed); +} + +TEST(test_performance, merge_performance_one_instance_comprehensive_hll_empty_dest) +{ + // int metric_id = fieldstat_register_hll(instance, cube_id, "czz_test hll metric", 10); + // int ret = fieldstat_hll_add(instance, cube_id, metric_id, cell_id, "hello", 5); + + auto metric_add_func = [](struct fieldstat *instance, int cube_id, int metric_id, int cell_id) { + fieldstat_hll_add(instance, cube_id, metric_id, cell_id, "hello", 5); + }; + auto metric_register_func = [](struct fieldstat *instance, int cube_id) { + return fieldstat_register_hll(instance, cube_id, "hll metric", 6); + }; + + clock_t elapsed = perform_merge_test(metric_add_func, metric_register_func, SAMPLING_MODE_COMPREHENSIVE, true); + printf("merge_performance_one_instance_comprehensive_counter_empty_dest elapsed_secs: %ld\n", elapsed); +} + +TEST(test_performance, merge_performance_one_instance_comprehensive_histogram_empty_dest) +{ + // int metric_id = fieldstat_register_histogram(instance, cube_id, "czz_test", 1, 100000, 1); + // int ret = fieldstat_histogram_record(instance, cube_id, metric_id, cell_id, 1234); + + auto metric_add_func = [](struct fieldstat *instance, int cube_id, int metric_id, int cell_id) { + fieldstat_histogram_record(instance, cube_id, metric_id, cell_id, 1234); + }; + auto metric_register_func = [](struct fieldstat *instance, int cube_id) { + return fieldstat_register_histogram(instance, cube_id, "histogram metric", 1, 100000, 1); + }; + + clock_t elapsed = perform_merge_test(metric_add_func, metric_register_func, SAMPLING_MODE_COMPREHENSIVE, true); + printf("merge_performance_one_instance_comprehensive_counter_empty_dest elapsed_secs: %ld\n", elapsed); +} + +TEST(test_performance, merge_performance_one_instance_topk_counter_empty_dest) +{ + auto metric_add_func = [](struct fieldstat *instance, int cube_id, int metric_id, int cell_id) { + fieldstat_counter_incrby(instance, cube_id, metric_id, cell_id, rand() % 1000); + }; + auto metric_register_func = [](struct fieldstat *instance, int cube_id) { + return fieldstat_register_counter(instance, cube_id, "metric name", false); + }; + + clock_t elapsed = perform_merge_test(metric_add_func, metric_register_func, SAMPLING_MODE_TOPK, true); + printf("merge_performance_one_instance_comprehensive_counter_empty_dest elapsed_secs: %ld\n", elapsed); +} + +TEST(test_performance, merge_performance_one_instance_comprehensive_counter_full_dest) +{ + // int metric_id = fieldstat_register_counter(tmp_i, cube_id, "metric name", false); + // fieldstat_counter_incrby(instance, cube_id, metric_id, cell_id, 1); + auto metric_add_func = [](struct fieldstat *instance, int cube_id, int metric_id, int cell_id) { + fieldstat_counter_incrby(instance, cube_id, metric_id, cell_id, 1); + }; + auto metric_register_func = [](struct fieldstat *instance, int cube_id) { + return fieldstat_register_counter(instance, cube_id, "metric name", false); + }; + + clock_t elapsed = perform_merge_test(metric_add_func, metric_register_func, SAMPLING_MODE_COMPREHENSIVE, false); + printf("merge_performance_one_instance_comprehensive_counter_empty_dest elapsed_secs: %ld\n", elapsed); +} + +TEST(test_performance, merge_performance_one_instance_comprehensive_hll_full_dest) +{ + // int metric_id = fieldstat_register_hll(instance, cube_id, "czz_test hll metric", 10); + // int ret = fieldstat_hll_add(instance, cube_id, metric_id, cell_id, "hello", 5); + + auto metric_add_func = [](struct fieldstat *instance, int cube_id, int metric_id, int cell_id) { + fieldstat_hll_add(instance, cube_id, metric_id, cell_id, "hello", 5); + }; + auto metric_register_func = [](struct fieldstat *instance, int cube_id) { + return fieldstat_register_hll(instance, cube_id, "hll metric", 6); + }; + + clock_t elapsed = perform_merge_test(metric_add_func, metric_register_func, SAMPLING_MODE_COMPREHENSIVE, false); + printf("merge_performance_one_instance_comprehensive_counter_empty_dest elapsed_secs: %ld\n", elapsed); } -TEST(metric_test_counter, performance_test_on_60000_cells_comprehensive_1000000_times) +TEST(test_performance, merge_performance_one_instance_comprehensive_histogram_full_dest) +{ + // int metric_id = fieldstat_register_histogram(instance, cube_id, "czz_test", 1, 600000, 3); + // int ret = fieldstat_histogram_record(instance, cube_id, metric_id, cell_id, 1234); + + auto metric_add_func = [](struct fieldstat *instance, int cube_id, int metric_id, int cell_id) { + fieldstat_histogram_record(instance, cube_id, metric_id, cell_id, 1234); + }; + auto metric_register_func = [](struct fieldstat *instance, int cube_id) { + return fieldstat_register_histogram(instance, cube_id, "histogram metric", 1, 100000, 1); + }; + + clock_t elapsed = perform_merge_test(metric_add_func, metric_register_func, SAMPLING_MODE_COMPREHENSIVE, false); + printf("merge_performance_one_instance_comprehensive_counter_empty_dest elapsed_secs: %ld\n", elapsed); +} + +TEST(test_performance, merge_performance_one_instance_topk_counter_full_dest) +{ + auto metric_add_func = [](struct fieldstat *instance, int cube_id, int metric_id, int cell_id) { + fieldstat_counter_incrby(instance, cube_id, metric_id, cell_id, rand() % 1000); + }; + auto metric_register_func = [](struct fieldstat *instance, int cube_id) { + return fieldstat_register_counter(instance, cube_id, "metric name", false); + }; + + clock_t elapsed = perform_merge_test(metric_add_func, metric_register_func, SAMPLING_MODE_TOPK, false); + printf("merge_performance_one_instance_comprehensive_counter_empty_dest elapsed_secs: %ld\n", elapsed); +} + + +TEST(test_performance, performance_test_add_cells_comprehensive) { - int cell_count = 60000; + size_t cell_count = 100000; struct fieldstat_tag tags[cell_count]; - for (int i = 0; i < cell_count; i++) { + for (size_t i = 0; i < cell_count; i++) { tags[i] = TEST_TAG_INT; tags[i].value_longlong = i; } @@ -150,25 +226,21 @@ TEST(metric_test_counter, performance_test_on_60000_cells_comprehensive_1000000_ fieldstat_register_counter(instance, 0, "test", 0); clock_t start = clock(); - for (size_t i = 0; i < 1000000; i++) { - int cell_id = fieldstat_cube_add(instance, 0, &tags[i % cell_count], 1, 1); - if (cell_id < 0) { - continue; - } - fieldstat_counter_incrby(instance, 0, 0, cell_id, 1); + for (size_t i = 0; i < cell_count; i++) { + fieldstat_cube_add(instance, 0, &tags[i % cell_count], 1, 1); } clock_t end = clock(); - double seconds = (double)(end - start) / CLOCKS_PER_SEC; - printf("performance_test_on_60000_cells_comprehensive_1000000_times time cost: %f\n", seconds); - EXPECT_TRUE(seconds < 1); // 1 = 0.000001 * 1000000 + double seconds = (double)(end - start) / cell_count; + printf("performance_test_add_cells_comprehensive time cost: %f\n", seconds); + EXPECT_TRUE(seconds < 1); fieldstat_free(instance); } -TEST(metric_test_counter, performance_test_on_1000_cells_topk_1000000_times) +TEST(test_performance, performance_test_add_cells_topk) { - int cell_count = 60000; + size_t cell_count = 100000; struct fieldstat_tag tags[cell_count]; - for (int i = 0; i < cell_count; i++) { + for (size_t i = 0; i < cell_count; i++) { tags[i] = TEST_TAG_INT; // tags[i].value_longlong = rand() % 10000; if (rand()%2) @@ -182,21 +254,66 @@ TEST(metric_test_counter, performance_test_on_1000_cells_topk_1000000_times) // getchar(); clock_t start = clock(); - for (size_t i = 0; i < 1000000; i++) { - int cell_id = fieldstat_cube_add(instance, 0, &tags[i % cell_count], 1, 1); - if (cell_id != -1) - fieldstat_counter_incrby(instance, 0, 0, cell_id, 1); + for (size_t i = 0; i < cell_count; i++) { + fieldstat_cube_add(instance, 0, &tags[i % cell_count], 1, 1); } clock_t end = clock(); - double seconds = (double)(end - start) / CLOCKS_PER_SEC; + double seconds = (double)(end - start) / cell_count; // exit(0); - EXPECT_TRUE(seconds < 1); // 1 = 0.000001 * 1000000 + EXPECT_TRUE(seconds < 1); printf("performance_test_on_1000_cells_topk_1000000_times time cost: %f\n", seconds); fieldstat_free(instance); } +TEST(test_performance, performance_test_add_cells_histogram_record) +{ + struct fieldstat *instance = fieldstat_new(); + fieldstat_register_cube(instance, &TEST_TAG_INT_collided, 1, SAMPLING_MODE_COMPREHENSIVE, 10); + fieldstat_register_histogram(instance, 0, "test", 1, 1000000, 3); + int cell_id = fieldstat_cube_add(instance, 0, &TEST_TAG_DOUBLE, 1, 1); + size_t test_num = 100000; + long long vals[test_num]; + for (size_t i = 0; i < test_num; i++) { + vals[i] = rand() % 1000000 + 1; + } + + clock_t start = clock(); + for (size_t i = 0; i < test_num; i++) { + fieldstat_histogram_record(instance, 0, 0, cell_id, vals[i]); + } + clock_t end = clock(); + double seconds = (double)(end - start) / test_num; + printf("performance_test_add_cells_histogram_record time cost: %f\n", seconds); + EXPECT_TRUE(seconds < 1); + fieldstat_free(instance); +} + +TEST(test_performance, performance_test_add_cells_hll_add) +{ + struct fieldstat *instance = fieldstat_new(); + fieldstat_register_cube(instance, &TEST_TAG_INT_collided, 1, SAMPLING_MODE_COMPREHENSIVE, 10); + fieldstat_register_hll(instance, 0, "test", 6); + int cell_id = fieldstat_cube_add(instance, 0, &TEST_TAG_DOUBLE, 1, 1); + size_t test_num = 100000; + std::string vals[test_num]; + for (size_t i = 0; i < test_num; i++) { + vals[i] = std::to_string(rand() % 1000000 + 1); + } + + clock_t start = clock(); + for (size_t i = 0; i < test_num; i++) { + fieldstat_hll_add(instance, 0, 0, cell_id, vals[i].c_str(), vals[i].length()); + } + clock_t end = clock(); + double seconds = (double)(end - start) / test_num; + printf("performance_test_add_cells_hll_add time cost: %f\n", seconds); + EXPECT_TRUE(seconds < 1); + fieldstat_free(instance); +} + + int main(int argc, char *argv[]) { testing::InitGoogleTest(&argc, argv); |
