diff --git a/scanner/expr_matcher/adapter_rs/adapter_rs.cpp b/scanner/expr_matcher/adapter_rs/adapter_rs.cpp index e43fef7..1459ab1 100644 --- a/scanner/expr_matcher/adapter_rs/adapter_rs.cpp +++ b/scanner/expr_matcher/adapter_rs/adapter_rs.cpp @@ -65,7 +65,7 @@ struct adapter_rs_runtime { struct bool_matcher *bm; }; -/* adapter_hs instance */ +/* adapter_rs instance */ struct adapter_rs { size_t n_worker_thread; size_t n_expr; @@ -106,7 +106,7 @@ int adapter_rs_verify_regex_expression(const char *regex_expr, return ret; } /** - * @brief build hs block database for literal string and regex expression respectively + * @brief build rs database for literal string and regex expression respectively * * @retval 0(success) -1(failed) */ @@ -196,7 +196,7 @@ static struct bool_expr *bool_exprs_new(struct expr_rule *rules, size_t n_rule, struct bool_expr *bool_exprs = ALLOC(struct bool_expr, n_rule); - /* populate adpt_hs_compile_data and bool_expr */ + /* populate adpt_rs_compile_data and bool_expr */ for (size_t i = 0; i < n_rule; i++) { for (size_t j = 0; j < rules[i].n_patterns; j++) { @@ -276,22 +276,22 @@ void *adapter_rs_new(struct expr_rule *rules, size_t n_rule, rs_inst->rs_rt = ALLOC(struct adapter_rs_runtime, 1); - //hs_rt->bm + //rs_rt->bm rs_inst->rs_rt->bm = bool_matcher_new(bool_exprs, n_rule, &mem_size); if (rs_inst->rs_rt->bm != NULL) { log_info(logger, MODULE_ADAPTER_RS, - "Adapter_hs module: build bool matcher of %zu expressions" + "Adapter_rs module: build bool matcher of %zu expressions" " with %zu bytes memory", n_rule, mem_size); } else { log_error(logger, MODULE_ADAPTER_RS, - "[%s:%d] Adapter_hs module: build bool matcher failed", + "[%s:%d] Adapter_rs module: build bool matcher failed", __FUNCTION__, __LINE__); rs_ret = -1; } FREE(bool_exprs); - /* build hs database hs_rt->literal_db & hs_rt->regex_db */ + /* build rs database rs_rt->literal_db & rs_rt->regex_db */ int ret = adpt_rs_build_database(rs_inst->rs_rt, n_worker_thread, literal_cd, regex_cd, logger); if (ret < 0) { @@ -577,16 +577,6 @@ int adapter_rs_scan_stream(void *rs_stream, const char *data, size_t data_len, return -1; } - /* - In streaming mode, a non-zero return from the user-specified event-handler - function has consequences for the rest of that stream's lifetime: when a - non-zero return occurs, it signals that no more of the stream should be - scanned. Consequently if the user makes a subsequent call to - `hs_scan_stream` on a stream whose processing was terminated in this way, - hs_scan_stream will return `HS_SCAN_TERMINATED`. This case has not been - demonstrated in pcapscan, as its callback always returns 0. - */ - int ret = 0, err_count = 0; struct adapter_rs_stream *stream = (struct adapter_rs_stream *)rs_stream; int thread_id = stream->thread_id; diff --git a/src/maat_command.c b/src/maat_command.c index 36dc00d..c646741 100644 --- a/src/maat_command.c +++ b/src/maat_command.c @@ -252,7 +252,6 @@ int maat_wrap_redis_get_reply(redisContext *c, redisReply **reply) int maat_cmd_set_line(struct maat *maat_inst, const struct maat_cmd_line *line_rule) { - int i = 0; int ret = 0; long long absolute_expire_time = 0; @@ -268,42 +267,42 @@ int maat_cmd_set_line(struct maat *maat_inst, const struct maat_cmd_line *line_r struct serial_rule *s_rule = ALLOC(struct serial_rule, 1); - int table_id = table_manager_get_table_id(maat_inst->tbl_mgr, line_rule->table_name); - if (table_id < 0) { - log_error(maat_inst->logger, MODULE_MAAT_COMMAND, - "[%s:%d] Command set line id %lld failed: unknown table %s", - __FUNCTION__, __LINE__, line_rule->rule_id, line_rule->table_name); - FREE(s_rule); - return -1; - } + int table_id = table_manager_get_table_id(maat_inst->tbl_mgr, line_rule->table_name); + if (table_id < 0) { + log_error(maat_inst->logger, MODULE_MAAT_COMMAND, + "[%s:%d] Command set line id %lld failed: unknown table %s", + __FUNCTION__, __LINE__, line_rule->rule_id, line_rule->table_name); + FREE(s_rule); + return -1; + } - int valid_column = table_manager_get_valid_column(maat_inst->tbl_mgr, table_id); - if (valid_column < 0) { - log_error(maat_inst->logger, MODULE_MAAT_COMMAND, - "[%s:%d] Command set line id %lld failed: table %s is not a plugin or ip_plugin table", - __FUNCTION__, __LINE__, line_rule->rule_id, line_rule->table_name); - FREE(s_rule); - return -1; - } - - int valid_offset = maat_get_valid_flag_offset(line_rule->table_line, valid_column); - if (valid_offset < 0) { - log_error(maat_inst->logger, MODULE_MAAT_COMMAND, - "[%s:%d] Command set line id %lld failed: table %s valid_offset error", - __FUNCTION__, __LINE__, line_rule->rule_id, line_rule->table_name); - FREE(s_rule); - return -1; - } + int valid_column = table_manager_get_valid_column(maat_inst->tbl_mgr, table_id); + if (valid_column < 0) { + log_error(maat_inst->logger, MODULE_MAAT_COMMAND, + "[%s:%d] Command set line id %lld failed: table %s is not a plugin or ip_plugin table", + __FUNCTION__, __LINE__, line_rule->rule_id, line_rule->table_name); + FREE(s_rule); + return -1; + } - int is_valid = atoi(line_rule->table_line + valid_offset); - if (line_rule->expire_after > 0) { - absolute_expire_time = server_time + line_rule->expire_after; - } + int valid_offset = maat_get_valid_flag_offset(line_rule->table_line, valid_column); + if (valid_offset < 0) { + log_error(maat_inst->logger, MODULE_MAAT_COMMAND, + "[%s:%d] Command set line id %lld failed: table %s valid_offset error", + __FUNCTION__, __LINE__, line_rule->rule_id, line_rule->table_name); + FREE(s_rule); + return -1; + } - maat_set_serial_rule(s_rule + i, (enum maat_operation)is_valid, line_rule->rule_id, + int is_valid = atoi(line_rule->table_line + valid_offset); + if (line_rule->expire_after > 0) { + absolute_expire_time = server_time + line_rule->expire_after; + } + + maat_set_serial_rule(s_rule, (enum maat_operation)is_valid, line_rule->rule_id, line_rule->table_name, line_rule->table_line, absolute_expire_time); - int success_cnt = maat_cmd_write_rule(write_ctx, s_rule, 1, server_time, maat_inst->logger); + int success_cnt = maat_cmd_write_rule(write_ctx, s_rule, 1, server_time, maat_inst->logger); if (success_cnt != 1) { ret = -1; goto error_out; diff --git a/src/maat_expr.c b/src/maat_expr.c index 2c53d21..2bf90eb 100644 --- a/src/maat_expr.c +++ b/src/maat_expr.c @@ -1173,4 +1173,4 @@ long long expr_runtime_scan_bytes(struct expr_runtime *expr_rt) alignment_int64_array_reset(expr_rt->scan_bytes, expr_rt->n_worker_thread); return sum; -} \ No newline at end of file +} diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 5157f1f..f3be40b 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -34,6 +34,7 @@ add_executable(maat_ex_data_gtest maat_ex_data_gtest.cpp) target_link_libraries(maat_ex_data_gtest maat_frame_static gtest_static) add_subdirectory(group_exclude) +add_subdirectory(benchmark) file(COPY table_info.conf DESTINATION ./) file(COPY tsg_table_info.conf DESTINATION ./) @@ -47,6 +48,7 @@ file(COPY testdata DESTINATION ./) file(COPY test_streamfiles DESTINATION ./) file(COPY json_update DESTINATION ./) file(COPY group_exclude DESTINATION ./) +file(COPY benchmark DESTINATION ./) include(GoogleTest) gtest_discover_tests(maat_framework_gtest) diff --git a/test/benchmark/CMakeLists.txt b/test/benchmark/CMakeLists.txt new file mode 100644 index 0000000..d62c4e6 --- /dev/null +++ b/test/benchmark/CMakeLists.txt @@ -0,0 +1,7 @@ +include_directories(${PROJECT_SOURCE_DIR}/src/inc_internal) + +add_executable(benchmark_hs_gtest benchmark_hs_gtest.cpp) +target_link_libraries(benchmark_hs_gtest maat_frame_static gtest_static) + +add_executable(benchmark_rs_gtest benchmark_rs_gtest.cpp) +target_link_libraries(benchmark_rs_gtest maat_frame_static gtest_static) \ No newline at end of file diff --git a/test/benchmark/benchmark_hs_gtest.cpp b/test/benchmark/benchmark_hs_gtest.cpp new file mode 100644 index 0000000..8aea023 --- /dev/null +++ b/test/benchmark/benchmark_hs_gtest.cpp @@ -0,0 +1,3122 @@ +#include "maat.h" +#include "log/log.h" +#include "maat_utils.h" +#include "maat_rule.h" +#include "json2iris.h" +#include "ip_matcher.h" +#include "maat_table.h" +#include "maat_config_monitor.h" + +#include + +#define MODULE_BENCHMARK_GTEST module_name_str("maat.benchmark_gtest") + +#define MAX_EXPR_RULE_NUM 2000000 +#define MID_EXPR_RULE_NUM 1000000 + +#define MAX_IP_RULE_NUM 8000000 +#define MID_IP_RULE_NUM 4000000 + +#define MAX_INTEGER_RULE_NUM 10000 +#define MID_INTEGER_RULE_NUM 5000 + +#define MAX_FLAG_RULE_NUM 10000 +#define MID_FLAG_RULE_NUM 5000 + +#define ARRAY_SIZE 10 +#define PERF_THREAD_NUM 5 +#define MAX_SCAN_COUNT 1000000 + +const char *table_info_path = "./benchmark_table_info.conf"; +struct log_handle *g_logger = NULL; + +struct thread_param { + int thread_id; + int test_count; + int rule_count; + struct maat *maat_inst; + const char *table_name; + long long time_elapse_ms; + struct log_handle *logger; +}; + +static void random_keyword_generate(char *keyword_buf, size_t sz) +{ +#define MIN_KEYWORD_LEN 4 + size_t i = 0, len = 0; + len = random() % (sz - 1 - MIN_KEYWORD_LEN) + MIN_KEYWORD_LEN; + + for (i = 0; i < len; i++) { + keyword_buf[i] = 'a' + random() % ('z' - 'a'); + } + keyword_buf[i] = '\0'; +} + +void generate_expr_sample(const char *table_name, int sample_count) +{ + FILE *fp = fopen(table_name, "w+"); + if (NULL == fp) { + log_error(g_logger, "open file %s failed", table_name); + return; + } + + fprintf(fp, "%d\n", sample_count); + fprintf(fp, "1\t1\t%s\t1\t0\t0\t1\n", "the souls of the departed"); + + for (int i = 2; i <= sample_count; i++) { + char keyword_buf[64] = {0}; + random_keyword_generate(keyword_buf, sizeof(keyword_buf)); + fprintf(fp, "%d\t%d\t%s\t1\t0\t0\t1\n", i, i, keyword_buf); + } + + fclose(fp); +} + +void generate_ip_sample(const char *table_name, int sample_count) +{ + FILE *fp = fopen(table_name, "w+"); + if (NULL == fp) { + log_error(g_logger, "open file %s failed", table_name); + return; + } + + fprintf(fp, "%d\n", sample_count); + fprintf(fp, "1\t1\t4\t%s\t%s\t%s\t%s\t%d\t%d\t-1\t1\n", "range", + "100.64.1.1", "100.64.1.1", "range", 20000, 20000); + + for (int i = 2; i <= sample_count-1; i++) { + char ip_buf[64] = {0}; + sprintf(ip_buf, "%d.%d.%d.%d", (int)(random() % 256), (int)(random() % 256), + (int)(random() % 256), (int)(random() % 256)); + fprintf(fp, "%d\t%d\t4\t%s\t%s\t%s\t%s\t%d\t%d\t-1\t1\n", + i+1, i+1, "range", ip_buf, ip_buf, "range", 20000, 20000); + } + + fclose(fp); +} + +void generate_integer_sample(const char *table_name, int sample_count) +{ + FILE *fp = fopen(table_name, "w+"); + if (NULL == fp) { + log_error(g_logger, "open file %s failed", table_name); + return; + } + + fprintf(fp, "%d\n", sample_count); + fprintf(fp, "1\t1\t%d\t%d\t1\n", 1000000, 1000000); + + for (int i = 2; i <= sample_count-1; i++) { + fprintf(fp, "%d\t%d\t%d\t%d\t1\n", i+1, i+1, i+1, i+1); + } + + fclose(fp); +} + +void generate_flag_sample(const char *table_name, int sample_count) +{ + FILE *fp = fopen(table_name, "w+"); + if (NULL == fp) { + log_error(g_logger, "open file %s failed", table_name); + return; + } + + fprintf(fp, "%d\n", sample_count); + fprintf(fp, "1\t1\t%d\t%d\t1\n", 1000000, 1111111); + + for (int i = 2; i <= sample_count-1; i++) { + fprintf(fp, "%d\t%d\t%d\t%d\t1\n", i+1, i+1, i+1, i+1); + } + + fclose(fp); +} + +void generate_compile_sample(const char *table_name, int sample_count) +{ + FILE *fp = fopen(table_name, "w+"); + if (NULL == fp) { + log_error(g_logger, "open file %s failed", table_name); + return; + } + + fprintf(fp, "%d\n", sample_count); + + for (int i = 0; i < sample_count; i++) { + fprintf(fp, "%d\t1\t1\t1\t1\t0\t%s\t1\t1\n", 100+i, "null"); + } + + fclose(fp); +} + +void generate_group2compile_sample(const char *table_name, int sample_count) +{ + FILE *fp = fopen(table_name, "w+"); + if (NULL == fp) { + log_error(g_logger, "open file %s failed", table_name); + return; + } + + fprintf(fp, "%d\n", sample_count); + + for (int i = 0; i < sample_count; i++) { + fprintf(fp, "%d\t%d\t1\t0\t%s\t1\n", i+1, 100+i, "null"); + } + + fclose(fp); +} + +void *perf_literal_scan_thread(void *arg) +{ + struct thread_param *param = (struct thread_param *)arg; + struct maat *maat_inst = param->maat_inst; + const char *table_name = param->table_name; + struct timespec start, end; + const char *scan_data = "Maat was the goddness of harmony, justice, and truth in ancient Egyptian." + " Her feather was the measure that determined whether the souls of the departed " + "would reach the paradise of the afterlife successfully"; + long long results[ARRAY_SIZE] = {0}; + int hit_times = 0; + size_t n_hit_result = 0; + struct maat_state *state = maat_state_new(maat_inst, param->thread_id); + + int table_id = maat_get_table_id(maat_inst, table_name); + + clock_gettime(CLOCK_MONOTONIC, &start); + for (int i = 0; i < param->test_count; i++) { + int ret = maat_scan_string(maat_inst, table_id, scan_data, strlen(scan_data), + results, ARRAY_SIZE, &n_hit_result, state); + if (ret == MAAT_SCAN_HIT) { + hit_times++; + } + maat_state_reset(state); + } + clock_gettime(CLOCK_MONOTONIC, &end); + + param->time_elapse_ms = (end.tv_sec - start.tv_sec) * 1000 + + (end.tv_nsec - start.tv_nsec) / 1000000; + int *is_all_hit = ALLOC(int, 1); + *is_all_hit = (hit_times == param->test_count ? 1 : 0); + log_info(param->logger, MODULE_BENCHMARK_GTEST, + "thread_id:%d rule_count:%d literal_scan time_elapse:%lldms hit_times:%d", + param->thread_id, param->rule_count, param->time_elapse_ms, hit_times); + + return is_all_hit; +} + +void *perf_literal_update_thread(void *arg) +{ + struct thread_param *param = (struct thread_param *)arg; + const char *table_name = param->table_name; + const int CMD_EXPR_NUM = 10; + char keyword_buf[128]; + + for (int i = 0; i < CMD_EXPR_NUM; i++) { + random_keyword_generate(keyword_buf, sizeof(keyword_buf)); + FILE *fp = fopen(table_name, "a+"); + if (NULL == fp) { + continue; + } + + fprintf(fp, "%d\t%d\t%s\t1\t0\t0\t1\n", 2000001+i, 2000001+i, keyword_buf); + fclose(fp); + + sleep(1); + } + + int *is_all_hit = ALLOC(int, 1); + *is_all_hit = 1; + + return is_all_hit; +} + +void *perf_stream_scan_thread(void *arg) +{ + struct thread_param *param = (struct thread_param *)arg; + struct maat *maat_inst = param->maat_inst; + const char *table_name = param->table_name; + struct timespec start, end; + const char *scan_data = "Maat was the goddness of harmony, justice, and truth in ancient Egyptian." + " Her feather was the measure that determined whether the souls of the departed " + "would reach the paradise of the afterlife successfully"; + long long results[ARRAY_SIZE] = {0}; + int ret = 0, hit_times = 0; + size_t n_hit_result = 0; + + int table_id = maat_get_table_id(maat_inst, table_name); + struct maat_state *state = maat_state_new(maat_inst, param->thread_id); + struct maat_stream *sp = maat_stream_new(maat_inst, table_id, state); + + clock_gettime(CLOCK_MONOTONIC, &start); + for (int i = 0; i < param->test_count; i++) { + ret = maat_stream_scan(sp, scan_data, strlen(scan_data), results, ARRAY_SIZE, + &n_hit_result, state); + if (ret == MAAT_SCAN_HIT) { + hit_times++; + } + maat_state_reset(state); + } + clock_gettime(CLOCK_MONOTONIC, &end); + maat_stream_free(sp); + maat_state_free(state); + + param->time_elapse_ms = (end.tv_sec - start.tv_sec) * 1000 + + (end.tv_nsec - start.tv_nsec) / 1000000; + int *is_all_hit = ALLOC(int, 1); + *is_all_hit = ((hit_times == param->test_count) ? 1 : 0); + + log_info(param->logger, MODULE_BENCHMARK_GTEST, + "thread_id:%d rule_count:%d stream_scan time_elapse:%lldms hit_times:%d", + param->thread_id, param->rule_count, param->time_elapse_ms, hit_times); + return is_all_hit; +} + +void *perf_ip_scan_thread(void *arg) +{ + struct thread_param *param = (struct thread_param *)arg; + struct maat *maat_inst = param->maat_inst; + const char *table_name = param->table_name; + struct timespec start, end; + long long results[ARRAY_SIZE] = {0}; + int hit_times = 0; + size_t n_hit_result = 0; + struct maat_state *state = maat_state_new(maat_inst, param->thread_id); + + int table_id = maat_get_table_id(maat_inst, table_name); + EXPECT_GT(table_id, 0); + + uint32_t ip_addr; + inet_pton(AF_INET, "100.64.1.1", &ip_addr); + uint16_t port = htons(20000); + int proto = 6; + + clock_gettime(CLOCK_MONOTONIC, &start); + for (int i = 0; i < param->test_count; i++) { + int ret = maat_scan_ipv4(maat_inst, table_id, ip_addr, port, proto, + results, ARRAY_SIZE, &n_hit_result, state); + if (ret == MAAT_SCAN_HIT) { + hit_times++; + } + maat_state_reset(state); + } + clock_gettime(CLOCK_MONOTONIC, &end); + + param->time_elapse_ms = (end.tv_sec - start.tv_sec) * 1000 + + (end.tv_nsec - start.tv_nsec) / 1000000; + int *is_all_hit = ALLOC(int, 1); + *is_all_hit = (hit_times == param->test_count ? 1 : 0); + log_info(param->logger, MODULE_BENCHMARK_GTEST, + "thread_id:%d rule_count:%d ip_scan time_elapse:%lldms hit_times:%d", + param->thread_id, param->rule_count, param->time_elapse_ms, hit_times); + + return is_all_hit; +} + +void *perf_ip_update_thread(void *arg) +{ + struct thread_param *param = (struct thread_param *)arg; + const char *table_name = param->table_name; + const int CMD_EXPR_NUM = 10; + + for (int i = 0; i < CMD_EXPR_NUM; i++) { + FILE *fp = fopen(table_name, "a+"); + if (NULL == fp) { + continue; + } + + char ip_buf[64] = {0}; + sprintf(ip_buf, "%d.%d.%d.%d", (int)(random() % 256), (int)(random() % 256), + (int)(random() % 256), (int)(random() % 256)); + fprintf(fp, "%d\t%d\t4\t%s\t%s\t%s\t%s\t%d\t%d\t-1\t1\n", + 8000001+i, 8000001+i, "range", ip_buf, ip_buf, "range", 20000, 20000); + fclose(fp); + + sleep(1); + } + + int *is_all_hit = ALLOC(int, 1); + *is_all_hit = 1; + + return is_all_hit; +} + +void *perf_integer_scan_thread(void *arg) +{ + struct thread_param *param = (struct thread_param *)arg; + struct maat *maat_inst = param->maat_inst; + const char *table_name = param->table_name; + struct timespec start, end; + long long results[ARRAY_SIZE] = {0}; + int hit_times = 0; + size_t n_hit_result = 0; + struct maat_state *state = maat_state_new(maat_inst, param->thread_id); + + int table_id = maat_get_table_id(maat_inst, table_name); + EXPECT_GT(table_id, 0); + + long long scan_data = 1000000; + + clock_gettime(CLOCK_MONOTONIC, &start); + for (int i = 0; i < param->test_count; i++) { + int ret = maat_scan_integer(maat_inst, table_id, scan_data, results, + ARRAY_SIZE, &n_hit_result, state); + if (ret == MAAT_SCAN_HIT) { + hit_times++; + } + maat_state_reset(state); + } + clock_gettime(CLOCK_MONOTONIC, &end); + + param->time_elapse_ms = (end.tv_sec - start.tv_sec) * 1000 + + (end.tv_nsec - start.tv_nsec) / 1000000; + int *is_all_hit = ALLOC(int, 1); + *is_all_hit = (hit_times == param->test_count ? 1 : 0); + log_info(param->logger, MODULE_BENCHMARK_GTEST, + "thread_id:%d rule_count:%d integer_scan time_elapse:%lldms hit_times:%d", + param->thread_id, param->rule_count, param->time_elapse_ms, hit_times); + + return is_all_hit; +} + +void *perf_integer_update_thread(void *arg) +{ + struct thread_param *param = (struct thread_param *)arg; + const char *table_name = param->table_name; + const int CMD_EXPR_NUM = 10; + + for (int i = 0; i < CMD_EXPR_NUM; i++) { + FILE *fp = fopen(table_name, "a+"); + if (NULL == fp) { + continue; + } + + fprintf(fp, "%d\t%d\t%d\t%d\t1\n", 10001+i, 10001+i, 10001+i, 10001+i); + fclose(fp); + + sleep(1); + } + + int *is_all_hit = ALLOC(int, 1); + *is_all_hit = 1; + + return is_all_hit; +} + +void *perf_flag_scan_thread(void *arg) +{ + struct thread_param *param = (struct thread_param *)arg; + struct maat *maat_inst = param->maat_inst; + const char *table_name = param->table_name; + struct timespec start, end; + long long results[ARRAY_SIZE] = {0}; + int hit_times = 0; + size_t n_hit_result = 0; + struct maat_state *state = maat_state_new(maat_inst, param->thread_id); + + int table_id = maat_get_table_id(maat_inst, table_name); + EXPECT_GT(table_id, 0); + + long long scan_data = 1000000; + + clock_gettime(CLOCK_MONOTONIC, &start); + for (int i = 0; i < param->test_count; i++) { + int ret = maat_scan_flag(maat_inst, table_id, scan_data, results, + ARRAY_SIZE, &n_hit_result, state); + if (ret == MAAT_SCAN_HIT) { + hit_times++; + } + maat_state_reset(state); + } + clock_gettime(CLOCK_MONOTONIC, &end); + + param->time_elapse_ms = (end.tv_sec - start.tv_sec) * 1000 + + (end.tv_nsec - start.tv_nsec) / 1000000; + int *is_all_hit = ALLOC(int, 1); + *is_all_hit = (hit_times == param->test_count ? 1 : 0); + log_info(param->logger, MODULE_BENCHMARK_GTEST, + "thread_id:%d rule_count:%d flag_scan time_elapse:%lldms hit_times:%d", + param->thread_id, param->rule_count, param->time_elapse_ms, hit_times); + + return is_all_hit; +} + +void *perf_flag_update_thread(void *arg) +{ + struct thread_param *param = (struct thread_param *)arg; + const char *table_name = param->table_name; + const int CMD_EXPR_NUM = 10; + + for (int i = 0; i < CMD_EXPR_NUM; i++) { + FILE *fp = fopen(table_name, "a+"); + if (NULL == fp) { + continue; + } + + fprintf(fp, "%d\t%d\t%d\t%d\t1\n", 10001+i, 10001+i, 10001+i, 10001+i); + fclose(fp); + + sleep(1); + } + + int *is_all_hit = ALLOC(int, 1); + *is_all_hit = 1; + + return is_all_hit; +} + +class Expr1KBenchmarkGTest : public ::testing::Test +{ +protected: + static void SetUpTestCase() { + logger = log_handle_create("./benchmark_hs_gtest.log", 0); + ///printf("Start to generate test sample......\n"); + generate_expr_sample("EXPR_LITERAL_1K", 1000); + + FILE *fp = fopen("full_config_index.0000001", "w+"); + if (NULL == fp) { + log_error(g_logger, "open file %s failed", "full_config_index.0000001"); + return; + } + fprintf(fp, "EXPR_LITERAL_1K 1000 ./EXPR_LITERAL_1K\n"); + fprintf(fp, "COMPILE_PERF 10 ./COMPILE_PERF\n"); + fprintf(fp, "GROUP2COMPILE_PERF 10 ./GROUP2COMPILE_PERF\n"); + fclose(fp); + + struct maat_options *opts = maat_options_new(); + maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO); + maat_options_set_iris(opts, "./", "./"); + maat_options_set_rule_effect_interval_ms(opts, 1000); + maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM); + _shared_maat_inst = maat_new(opts, table_info_path); + maat_options_free(opts); + } + + static void TearDownTestCase() { + maat_free(_shared_maat_inst); + log_handle_destroy(logger); + } + + static struct log_handle *logger; + static struct maat *_shared_maat_inst; +}; + +struct maat *Expr1KBenchmarkGTest::_shared_maat_inst; +struct log_handle *Expr1KBenchmarkGTest::logger; + +TEST_F(Expr1KBenchmarkGTest, LiteralScan) { + const char *table_name = "EXPR_LITERAL_1K"; + struct maat *maat_inst = Expr1KBenchmarkGTest::_shared_maat_inst; + + int table_id = maat_get_table_id(maat_inst, table_name); + ASSERT_GT(table_id, 0); + + pthread_t threads[PERF_THREAD_NUM + 1]; + struct thread_param thread_params[PERF_THREAD_NUM + 1]; + int i = 0; + int *is_all_hit = NULL; + + for (i = 0; i < PERF_THREAD_NUM + 1; i++) { + thread_params[i].maat_inst = maat_inst; + thread_params[i].thread_id = i; + thread_params[i].table_name = table_name; + thread_params[i].test_count = MAX_SCAN_COUNT; + thread_params[i].rule_count = 1000; + thread_params[i].time_elapse_ms = 0; + thread_params[i].logger = logger; + + if (i < PERF_THREAD_NUM) { + pthread_create(&threads[i], NULL, perf_literal_scan_thread, thread_params+i); + } else { + thread_params[i].test_count = 0; + pthread_create(&threads[i], NULL, perf_literal_update_thread, thread_params+i); + } + } + + long long time_elapse_ms = 0; + long long scan_count = 0; + long long scan_per_second = 0; + for (i = 0; i < PERF_THREAD_NUM + 1; i++) { + pthread_join(threads[i], (void **)&is_all_hit); + time_elapse_ms += thread_params[i].time_elapse_ms; + scan_count += thread_params[i].test_count; + + EXPECT_EQ(*is_all_hit, 1); + *is_all_hit = 0; + free(is_all_hit); + } + scan_per_second = scan_count * 1000 / time_elapse_ms; + + log_info(maat_inst->logger, MODULE_BENCHMARK_GTEST, + "Expr1KLiteralScan match rate on %d-threads speed %lld lookups/s/thread", + PERF_THREAD_NUM, scan_per_second); +} + +class Expr5KBenchmarkGTest : public ::testing::Test +{ +protected: + static void SetUpTestCase() { + logger = log_handle_create("./benchmark_hs_gtest.log", 0); + generate_expr_sample("EXPR_LITERAL_5K", 5000); + + FILE *fp = fopen("full_config_index.0000001", "w+"); + if (NULL == fp) { + log_error(g_logger, "open file %s failed", "full_config_index.0000001"); + return; + } + fprintf(fp, "EXPR_LITERAL_5K 5000 ./EXPR_LITERAL_5K\n"); + fprintf(fp, "COMPILE_PERF 10 ./COMPILE_PERF\n"); + fprintf(fp, "GROUP2COMPILE_PERF 10 ./GROUP2COMPILE_PERF\n"); + fclose(fp); + + struct maat_options *opts = maat_options_new(); + maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO); + maat_options_set_iris(opts, "./", "./"); + maat_options_set_rule_effect_interval_ms(opts, 1000); + maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM); + _shared_maat_inst = maat_new(opts, table_info_path); + maat_options_free(opts); + } + + static void TearDownTestCase() { + maat_free(_shared_maat_inst); + log_handle_destroy(logger); + } + + static struct log_handle *logger; + static struct maat *_shared_maat_inst; +}; + +struct maat *Expr5KBenchmarkGTest::_shared_maat_inst; +struct log_handle *Expr5KBenchmarkGTest::logger; + +TEST_F(Expr5KBenchmarkGTest, LiteralScan) { + const char *table_name = "EXPR_LITERAL_5K"; + struct maat *maat_inst = Expr5KBenchmarkGTest::_shared_maat_inst; + + int table_id = maat_get_table_id(maat_inst, table_name); + ASSERT_GT(table_id, 0); + + pthread_t threads[PERF_THREAD_NUM + 1]; + struct thread_param thread_params[PERF_THREAD_NUM + 1]; + int i = 0; + int *is_all_hit = NULL; + + for (i = 0; i < PERF_THREAD_NUM + 1; i++) { + thread_params[i].maat_inst = maat_inst; + thread_params[i].thread_id = i; + thread_params[i].table_name = table_name; + thread_params[i].test_count = MAX_SCAN_COUNT; + thread_params[i].rule_count = 5000; + thread_params[i].time_elapse_ms = 0; + thread_params[i].logger = logger; + + if (i < PERF_THREAD_NUM) { + pthread_create(&threads[i], NULL, perf_literal_scan_thread, thread_params+i); + } else { + thread_params[i].test_count = 0; + pthread_create(&threads[i], NULL, perf_literal_update_thread, thread_params+i); + } + } + + long long time_elapse_ms = 0; + long long scan_count = 0; + long long scan_per_second = 0; + for (i = 0; i < PERF_THREAD_NUM + 1; i++) { + pthread_join(threads[i], (void **)&is_all_hit); + time_elapse_ms += thread_params[i].time_elapse_ms; + scan_count += thread_params[i].test_count; + + EXPECT_EQ(*is_all_hit, 1); + *is_all_hit = 0; + free(is_all_hit); + } + scan_per_second = scan_count * 1000 / time_elapse_ms; + + log_info(maat_inst->logger, MODULE_BENCHMARK_GTEST, + "Expr5KLiteralScan match rate on %d-threads speed %lld lookups/s/thread", + PERF_THREAD_NUM, scan_per_second); +} + +class Expr10KBenchmarkGTest : public ::testing::Test +{ +protected: + static void SetUpTestCase() { + logger = log_handle_create("./benchmark_hs_gtest.log", 0); + generate_expr_sample("EXPR_LITERAL_10K", 10000); + + FILE *fp = fopen("full_config_index.0000001", "w+"); + if (NULL == fp) { + log_error(g_logger, "open file %s failed", "full_config_index.0000001"); + return; + } + fprintf(fp, "EXPR_LITERAL_10K 10000 ./EXPR_LITERAL_10K\n"); + fprintf(fp, "COMPILE_PERF 10 ./COMPILE_PERF\n"); + fprintf(fp, "GROUP2COMPILE_PERF 10 ./GROUP2COMPILE_PERF\n"); + fclose(fp); + + struct maat_options *opts = maat_options_new(); + maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO); + maat_options_set_iris(opts, "./", "./"); + maat_options_set_rule_effect_interval_ms(opts, 1000); + maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM); + _shared_maat_inst = maat_new(opts, table_info_path); + maat_options_free(opts); + } + + static void TearDownTestCase() { + maat_free(_shared_maat_inst); + log_handle_destroy(logger); + } + + static struct log_handle *logger; + static struct maat *_shared_maat_inst; +}; + +struct maat *Expr10KBenchmarkGTest::_shared_maat_inst; +struct log_handle *Expr10KBenchmarkGTest::logger; + +TEST_F(Expr10KBenchmarkGTest, LiteralScan) { + const char *table_name = "EXPR_LITERAL_10K"; + struct maat *maat_inst = Expr10KBenchmarkGTest::_shared_maat_inst; + + int table_id = maat_get_table_id(maat_inst, table_name); + ASSERT_GT(table_id, 0); + + pthread_t threads[PERF_THREAD_NUM + 1]; + struct thread_param thread_params[PERF_THREAD_NUM + 1]; + int i = 0; + int *is_all_hit = NULL; + + for (i = 0; i < PERF_THREAD_NUM + 1; i++) { + thread_params[i].maat_inst = maat_inst; + thread_params[i].thread_id = i; + thread_params[i].table_name = table_name; + thread_params[i].test_count = MAX_SCAN_COUNT; + thread_params[i].rule_count = 10000; + thread_params[i].time_elapse_ms = 0; + thread_params[i].logger = logger; + + if (i < PERF_THREAD_NUM) { + pthread_create(&threads[i], NULL, perf_literal_scan_thread, thread_params+i); + } else { + thread_params[i].test_count = 0; + pthread_create(&threads[i], NULL, perf_literal_update_thread, thread_params+i); + } + } + + long long time_elapse_ms = 0; + long long scan_count = 0; + long long scan_per_second = 0; + for (i = 0; i < PERF_THREAD_NUM + 1; i++) { + pthread_join(threads[i], (void **)&is_all_hit); + time_elapse_ms += thread_params[i].time_elapse_ms; + scan_count += thread_params[i].test_count; + + EXPECT_EQ(*is_all_hit, 1); + *is_all_hit = 0; + free(is_all_hit); + } + scan_per_second = scan_count * 1000 / time_elapse_ms; + + log_info(maat_inst->logger, MODULE_BENCHMARK_GTEST, + "Expr10KLiteralScan match rate on %d-threads speed %lld lookups/s/thread", + PERF_THREAD_NUM, scan_per_second); +} + +class Expr50KBenchmarkGTest : public ::testing::Test +{ +protected: + static void SetUpTestCase() { + logger = log_handle_create("./benchmark_hs_gtest.log", 0); + generate_expr_sample("EXPR_LITERAL_50K", 50000); + + FILE *fp = fopen("full_config_index.0000001", "w+"); + if (NULL == fp) { + log_error(g_logger, "open file %s failed", "full_config_index.0000001"); + return; + } + fprintf(fp, "EXPR_LITERAL_50K 50000 ./EXPR_LITERAL_50K\n"); + fprintf(fp, "COMPILE_PERF 10 ./COMPILE_PERF\n"); + fprintf(fp, "GROUP2COMPILE_PERF 10 ./GROUP2COMPILE_PERF\n"); + fclose(fp); + + struct maat_options *opts = maat_options_new(); + maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO); + maat_options_set_iris(opts, "./", "./"); + maat_options_set_rule_effect_interval_ms(opts, 1000); + maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM); + _shared_maat_inst = maat_new(opts, table_info_path); + maat_options_free(opts); + } + + static void TearDownTestCase() { + maat_free(_shared_maat_inst); + log_handle_destroy(logger); + } + + static struct log_handle *logger; + static struct maat *_shared_maat_inst; +}; + +struct maat *Expr50KBenchmarkGTest::_shared_maat_inst; +struct log_handle *Expr50KBenchmarkGTest::logger; + +TEST_F(Expr50KBenchmarkGTest, LiteralScan) { + const char *table_name = "EXPR_LITERAL_50K"; + struct maat *maat_inst = Expr50KBenchmarkGTest::_shared_maat_inst; + + int table_id = maat_get_table_id(maat_inst, table_name); + ASSERT_GT(table_id, 0); + + pthread_t threads[PERF_THREAD_NUM + 1]; + struct thread_param thread_params[PERF_THREAD_NUM + 1]; + int i = 0; + int *is_all_hit = NULL; + + for (i = 0; i < PERF_THREAD_NUM + 1; i++) { + thread_params[i].maat_inst = maat_inst; + thread_params[i].thread_id = i; + thread_params[i].table_name = table_name; + thread_params[i].test_count = MAX_SCAN_COUNT; + thread_params[i].rule_count = 50000; + thread_params[i].time_elapse_ms = 0; + thread_params[i].logger = logger; + + if (i < PERF_THREAD_NUM) { + pthread_create(&threads[i], NULL, perf_literal_scan_thread, thread_params+i); + } else { + thread_params[i].test_count = 0; + pthread_create(&threads[i], NULL, perf_literal_update_thread, thread_params+i); + } + } + + long long time_elapse_ms = 0; + long long scan_count = 0; + long long scan_per_second = 0; + for (i = 0; i < PERF_THREAD_NUM + 1; i++) { + pthread_join(threads[i], (void **)&is_all_hit); + time_elapse_ms += thread_params[i].time_elapse_ms; + scan_count += thread_params[i].test_count; + + EXPECT_EQ(*is_all_hit, 1); + *is_all_hit = 0; + free(is_all_hit); + } + scan_per_second = scan_count * 1000 / time_elapse_ms; + + log_info(maat_inst->logger, MODULE_BENCHMARK_GTEST, + "Expr50KLiteralScan match rate on %d-threads speed %lld lookups/s/thread", + PERF_THREAD_NUM, scan_per_second); +} + +class Expr100KBenchmarkGTest : public ::testing::Test +{ +protected: + static void SetUpTestCase() { + logger = log_handle_create("./benchmark_hs_gtest.log", 0); + generate_expr_sample("EXPR_LITERAL_100K", 100000); + + FILE *fp = fopen("full_config_index.0000001", "w+"); + if (NULL == fp) { + log_error(g_logger, "open file %s failed", "full_config_index.0000001"); + return; + } + fprintf(fp, "EXPR_LITERAL_100K 100000 ./EXPR_LITERAL_100K\n"); + fprintf(fp, "COMPILE_PERF 10 ./COMPILE_PERF\n"); + fprintf(fp, "GROUP2COMPILE_PERF 10 ./GROUP2COMPILE_PERF\n"); + fclose(fp); + + struct maat_options *opts = maat_options_new(); + maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO); + maat_options_set_iris(opts, "./", "./"); + maat_options_set_rule_effect_interval_ms(opts, 1000); + maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM); + _shared_maat_inst = maat_new(opts, table_info_path); + maat_options_free(opts); + } + + static void TearDownTestCase() { + maat_free(_shared_maat_inst); + log_handle_destroy(logger); + } + + static struct log_handle *logger; + static struct maat *_shared_maat_inst; +}; + +struct maat *Expr100KBenchmarkGTest::_shared_maat_inst; +struct log_handle *Expr100KBenchmarkGTest::logger; + +TEST_F(Expr100KBenchmarkGTest, LiteralScan) { + const char *table_name = "EXPR_LITERAL_100K"; + struct maat *maat_inst = Expr100KBenchmarkGTest::_shared_maat_inst; + + int table_id = maat_get_table_id(maat_inst, table_name); + ASSERT_GT(table_id, 0); + + pthread_t threads[PERF_THREAD_NUM + 1]; + struct thread_param thread_params[PERF_THREAD_NUM + 1]; + int i = 0; + int *is_all_hit = NULL; + + for (i = 0; i < PERF_THREAD_NUM + 1; i++) { + thread_params[i].maat_inst = maat_inst; + thread_params[i].thread_id = i; + thread_params[i].table_name = table_name; + thread_params[i].test_count = MAX_SCAN_COUNT; + thread_params[i].rule_count = 100000; + thread_params[i].time_elapse_ms = 0; + thread_params[i].logger = logger; + + if (i < PERF_THREAD_NUM) { + pthread_create(&threads[i], NULL, perf_literal_scan_thread, thread_params+i); + } else { + thread_params[i].test_count = 0; + pthread_create(&threads[i], NULL, perf_literal_update_thread, thread_params+i); + } + } + + long long time_elapse_ms = 0; + long long scan_count = 0; + long long scan_per_second = 0; + for (i = 0; i < PERF_THREAD_NUM + 1; i++) { + pthread_join(threads[i], (void **)&is_all_hit); + time_elapse_ms += thread_params[i].time_elapse_ms; + scan_count += thread_params[i].test_count; + + EXPECT_EQ(*is_all_hit, 1); + *is_all_hit = 0; + free(is_all_hit); + } + scan_per_second = scan_count * 1000 / time_elapse_ms; + + log_info(maat_inst->logger, MODULE_BENCHMARK_GTEST, + "Expr100KLiteralScan match rate on %d-threads speed %lld lookups/s/thread", + PERF_THREAD_NUM, scan_per_second); +} + +class Expr500KBenchmarkGTest : public ::testing::Test +{ +protected: + static void SetUpTestCase() { + logger = log_handle_create("./benchmark_hs_gtest.log", 0); + generate_expr_sample("EXPR_LITERAL_500K", 500000); + + FILE *fp = fopen("full_config_index.0000001", "w+"); + if (NULL == fp) { + log_error(g_logger, "open file %s failed", "full_config_index.0000001"); + return; + } + fprintf(fp, "EXPR_LITERAL_500K 500000 ./EXPR_LITERAL_500K\n"); + fprintf(fp, "COMPILE_PERF 10 ./COMPILE_PERF\n"); + fprintf(fp, "GROUP2COMPILE_PERF 10 ./GROUP2COMPILE_PERF\n"); + fclose(fp); + + struct maat_options *opts = maat_options_new(); + maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO); + maat_options_set_iris(opts, "./", "./"); + maat_options_set_rule_effect_interval_ms(opts, 1000); + maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM); + _shared_maat_inst = maat_new(opts, table_info_path); + maat_options_free(opts); + } + + static void TearDownTestCase() { + maat_free(_shared_maat_inst); + log_handle_destroy(logger); + } + + static struct log_handle *logger; + static struct maat *_shared_maat_inst; +}; + +struct maat *Expr500KBenchmarkGTest::_shared_maat_inst; +struct log_handle *Expr500KBenchmarkGTest::logger; + +TEST_F(Expr500KBenchmarkGTest, LiteralScan) { + const char *table_name = "EXPR_LITERAL_500K"; + struct maat *maat_inst = Expr500KBenchmarkGTest::_shared_maat_inst; + + int table_id = maat_get_table_id(maat_inst, table_name); + ASSERT_GT(table_id, 0); + + pthread_t threads[PERF_THREAD_NUM + 1]; + struct thread_param thread_params[PERF_THREAD_NUM + 1]; + int i = 0; + int *is_all_hit = NULL; + + for (i = 0; i < PERF_THREAD_NUM + 1; i++) { + thread_params[i].maat_inst = maat_inst; + thread_params[i].thread_id = i; + thread_params[i].table_name = table_name; + thread_params[i].test_count = MAX_SCAN_COUNT; + thread_params[i].rule_count = 500000; + thread_params[i].time_elapse_ms = 0; + thread_params[i].logger = logger; + + if (i < PERF_THREAD_NUM) { + pthread_create(&threads[i], NULL, perf_literal_scan_thread, thread_params+i); + } else { + thread_params[i].test_count = 0; + pthread_create(&threads[i], NULL, perf_literal_update_thread, thread_params+i); + } + } + + long long time_elapse_ms = 0; + long long scan_count = 0; + long long scan_per_second = 0; + for (i = 0; i < PERF_THREAD_NUM + 1; i++) { + pthread_join(threads[i], (void **)&is_all_hit); + time_elapse_ms += thread_params[i].time_elapse_ms; + scan_count += thread_params[i].test_count; + + EXPECT_EQ(*is_all_hit, 1); + *is_all_hit = 0; + free(is_all_hit); + } + scan_per_second = scan_count * 1000 / time_elapse_ms; + + log_info(maat_inst->logger, MODULE_BENCHMARK_GTEST, + "Expr500KLiteralScan match rate on %d-threads speed %lld lookups/s/thread", + PERF_THREAD_NUM, scan_per_second); +} + +class Expr1MBenchmarkGTest : public ::testing::Test +{ +protected: + static void SetUpTestCase() { + logger = log_handle_create("./benchmark_hs_gtest.log", 0); + generate_expr_sample("EXPR_LITERAL_1M", 1000000); + + FILE *fp = fopen("full_config_index.0000001", "w+"); + if (NULL == fp) { + log_error(g_logger, "open file %s failed", "full_config_index.0000001"); + return; + } + fprintf(fp, "EXPR_LITERAL_1M 1000000 ./EXPR_LITERAL_1M\n"); + fprintf(fp, "COMPILE_PERF 10 ./COMPILE_PERF\n"); + fprintf(fp, "GROUP2COMPILE_PERF 10 ./GROUP2COMPILE_PERF\n"); + fclose(fp); + + struct maat_options *opts = maat_options_new(); + maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO); + maat_options_set_iris(opts, "./", "./"); + maat_options_set_rule_effect_interval_ms(opts, 1000); + maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM); + _shared_maat_inst = maat_new(opts, table_info_path); + maat_options_free(opts); + } + + static void TearDownTestCase() { + maat_free(_shared_maat_inst); + log_handle_destroy(logger); + } + + static struct log_handle *logger; + static struct maat *_shared_maat_inst; +}; + +struct maat *Expr1MBenchmarkGTest::_shared_maat_inst; +struct log_handle *Expr1MBenchmarkGTest::logger; + +TEST_F(Expr1MBenchmarkGTest, LiteralScan) { + const char *table_name = "EXPR_LITERAL_1M"; + struct maat *maat_inst = Expr1MBenchmarkGTest::_shared_maat_inst; + + int table_id = maat_get_table_id(maat_inst, table_name); + ASSERT_GT(table_id, 0); + + pthread_t threads[PERF_THREAD_NUM + 1]; + struct thread_param thread_params[PERF_THREAD_NUM + 1]; + int i = 0; + int *is_all_hit = NULL; + + for (i = 0; i < PERF_THREAD_NUM + 1; i++) { + thread_params[i].maat_inst = maat_inst; + thread_params[i].thread_id = i; + thread_params[i].table_name = table_name; + thread_params[i].test_count = MAX_SCAN_COUNT; + thread_params[i].rule_count = 1000000; + thread_params[i].time_elapse_ms = 0; + thread_params[i].logger = logger; + + if (i < PERF_THREAD_NUM) { + pthread_create(&threads[i], NULL, perf_literal_scan_thread, thread_params+i); + } else { + thread_params[i].test_count = 0; + pthread_create(&threads[i], NULL, perf_literal_update_thread, thread_params+i); + } + } + + long long time_elapse_ms = 0; + long long scan_count = 0; + long long scan_per_second = 0; + for (i = 0; i < PERF_THREAD_NUM + 1; i++) { + pthread_join(threads[i], (void **)&is_all_hit); + time_elapse_ms += thread_params[i].time_elapse_ms; + scan_count += thread_params[i].test_count; + + EXPECT_EQ(*is_all_hit, 1); + *is_all_hit = 0; + free(is_all_hit); + } + scan_per_second = scan_count * 1000 / time_elapse_ms; + + log_info(maat_inst->logger, MODULE_BENCHMARK_GTEST, + "Expr1MLiteralScan match rate on %d-threads speed %lld lookups/s/thread", + PERF_THREAD_NUM, scan_per_second); +} + +class Expr2MBenchmarkGTest : public ::testing::Test +{ +protected: + static void SetUpTestCase() { + logger = log_handle_create("./benchmark_hs_gtest.log", 0); + generate_expr_sample("EXPR_LITERAL_2M", 2000000); + + FILE *fp = fopen("full_config_index.0000001", "w+"); + if (NULL == fp) { + log_error(g_logger, "open file %s failed", "full_config_index.0000001"); + return; + } + fprintf(fp, "EXPR_LITERAL_2M 2000000 ./EXPR_LITERAL_2M\n"); + fprintf(fp, "COMPILE_PERF 10 ./COMPILE_PERF\n"); + fprintf(fp, "GROUP2COMPILE_PERF 10 ./GROUP2COMPILE_PERF\n"); + fclose(fp); + + struct maat_options *opts = maat_options_new(); + maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO); + maat_options_set_iris(opts, "./", "./"); + maat_options_set_rule_effect_interval_ms(opts, 1000); + maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM); + _shared_maat_inst = maat_new(opts, table_info_path); + maat_options_free(opts); + } + + static void TearDownTestCase() { + maat_free(_shared_maat_inst); + log_handle_destroy(logger); + } + + static struct log_handle *logger; + static struct maat *_shared_maat_inst; +}; + +struct maat *Expr2MBenchmarkGTest::_shared_maat_inst; +struct log_handle *Expr2MBenchmarkGTest::logger; + +TEST_F(Expr2MBenchmarkGTest, LiteralScan) { + const char *table_name = "EXPR_LITERAL_2M"; + struct maat *maat_inst = Expr2MBenchmarkGTest::_shared_maat_inst; + + int table_id = maat_get_table_id(maat_inst, table_name); + ASSERT_GT(table_id, 0); + + pthread_t threads[PERF_THREAD_NUM + 1]; + struct thread_param thread_params[PERF_THREAD_NUM + 1]; + int i = 0; + int *is_all_hit = NULL; + + for (i = 0; i < PERF_THREAD_NUM + 1; i++) { + thread_params[i].maat_inst = maat_inst; + thread_params[i].thread_id = i; + thread_params[i].table_name = table_name; + thread_params[i].test_count = MAX_SCAN_COUNT; + thread_params[i].rule_count = 2000000; + thread_params[i].time_elapse_ms = 0; + thread_params[i].logger = logger; + + if (i < PERF_THREAD_NUM) { + pthread_create(&threads[i], NULL, perf_literal_scan_thread, thread_params+i); + } else { + thread_params[i].test_count = 0; + pthread_create(&threads[i], NULL, perf_literal_update_thread, thread_params+i); + } + } + + long long time_elapse_ms = 0; + long long scan_count = 0; + long long scan_per_second = 0; + for (i = 0; i < PERF_THREAD_NUM + 1; i++) { + pthread_join(threads[i], (void **)&is_all_hit); + time_elapse_ms += thread_params[i].time_elapse_ms; + scan_count += thread_params[i].test_count; + + EXPECT_EQ(*is_all_hit, 1); + *is_all_hit = 0; + free(is_all_hit); + } + scan_per_second = scan_count * 1000 / time_elapse_ms; + + log_info(maat_inst->logger, MODULE_BENCHMARK_GTEST, + "Expr2MLiteralScan match rate on %d-threads speed %lld lookups/s/thread", + PERF_THREAD_NUM, scan_per_second); +} + +class Stream1KBenchmarkGTest : public ::testing::Test +{ +protected: + static void SetUpTestCase() { + logger = log_handle_create("./benchmark_hs_gtest.log", 0); + generate_expr_sample("STREAM_1K", 1000); + + FILE *fp = fopen("full_config_index.0000001", "w+"); + if (NULL == fp) { + log_error(g_logger, "open file %s failed", "full_config_index.0000001"); + return; + } + fprintf(fp, "STREAM_1K 1000 ./STREAM_1K\n"); + fprintf(fp, "COMPILE_PERF 10 ./COMPILE_PERF\n"); + fprintf(fp, "GROUP2COMPILE_PERF 10 ./GROUP2COMPILE_PERF\n"); + fclose(fp); + + struct maat_options *opts = maat_options_new(); + maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO); + maat_options_set_iris(opts, "./", "./"); + maat_options_set_rule_effect_interval_ms(opts, 1000); + maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM); + _shared_maat_inst = maat_new(opts, table_info_path); + maat_options_free(opts); + } + + static void TearDownTestCase() { + maat_free(_shared_maat_inst); + log_handle_destroy(logger); + } + + static struct log_handle *logger; + static struct maat *_shared_maat_inst; +}; + +struct maat *Stream1KBenchmarkGTest::_shared_maat_inst; +struct log_handle *Stream1KBenchmarkGTest::logger; + +TEST_F(Stream1KBenchmarkGTest, LiteralScan) { + const char *table_name = "STREAM_1K"; + struct maat *maat_inst = Stream1KBenchmarkGTest::_shared_maat_inst; + + int table_id = maat_get_table_id(maat_inst, table_name); + ASSERT_GT(table_id, 0); + + pthread_t threads[PERF_THREAD_NUM]; + struct thread_param thread_params[PERF_THREAD_NUM]; + int i = 0; + int *is_all_hit = NULL; + + for (i = 0; i < PERF_THREAD_NUM; i++) { + thread_params[i].maat_inst = maat_inst; + thread_params[i].thread_id = i; + thread_params[i].table_name = table_name; + thread_params[i].test_count = MAX_SCAN_COUNT; + thread_params[i].rule_count = 1000; + thread_params[i].time_elapse_ms = 0; + thread_params[i].logger = logger; + + if (i < PERF_THREAD_NUM) { + pthread_create(&threads[i], NULL, perf_stream_scan_thread, thread_params+i); + } + } + + long long time_elapse_ms = 0; + long long scan_count = 0; + long long scan_per_second = 0; + for (i = 0; i < PERF_THREAD_NUM; i++) { + pthread_join(threads[i], (void **)&is_all_hit); + time_elapse_ms += thread_params[i].time_elapse_ms; + scan_count += thread_params[i].test_count; + + EXPECT_EQ(*is_all_hit, 1); + *is_all_hit = 0; + free(is_all_hit); + } + scan_per_second = scan_count * 1000 / time_elapse_ms; + + log_info(maat_inst->logger, MODULE_BENCHMARK_GTEST, + "Stream1KScan match rate on %d-threads speed %lld lookups/s/thread", + PERF_THREAD_NUM, scan_per_second); +} + +class Stream5KBenchmarkGTest : public ::testing::Test +{ +protected: + static void SetUpTestCase() { + logger = log_handle_create("./benchmark_hs_gtest.log", 0); + generate_expr_sample("STREAM_5K", 5000); + + FILE *fp = fopen("full_config_index.0000001", "w+"); + if (NULL == fp) { + log_error(g_logger, "open file %s failed", "full_config_index.0000001"); + return; + } + fprintf(fp, "STREAM_5K 5000 ./STREAM_5K\n"); + fprintf(fp, "COMPILE_PERF 10 ./COMPILE_PERF\n"); + fprintf(fp, "GROUP2COMPILE_PERF 10 ./GROUP2COMPILE_PERF\n"); + fclose(fp); + + struct maat_options *opts = maat_options_new(); + maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO); + maat_options_set_iris(opts, "./", "./"); + maat_options_set_rule_effect_interval_ms(opts, 1000); + maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM); + _shared_maat_inst = maat_new(opts, table_info_path); + maat_options_free(opts); + } + + static void TearDownTestCase() { + maat_free(_shared_maat_inst); + log_handle_destroy(logger); + } + + static struct log_handle *logger; + static struct maat *_shared_maat_inst; +}; + +struct maat *Stream5KBenchmarkGTest::_shared_maat_inst; +struct log_handle *Stream5KBenchmarkGTest::logger; + +TEST_F(Stream5KBenchmarkGTest, LiteralScan) { + const char *table_name = "STREAM_5K"; + struct maat *maat_inst = Stream5KBenchmarkGTest::_shared_maat_inst; + + int table_id = maat_get_table_id(maat_inst, table_name); + ASSERT_GT(table_id, 0); + + pthread_t threads[PERF_THREAD_NUM]; + struct thread_param thread_params[PERF_THREAD_NUM]; + int i = 0; + int *is_all_hit = NULL; + + for (i = 0; i < PERF_THREAD_NUM; i++) { + thread_params[i].maat_inst = maat_inst; + thread_params[i].thread_id = i; + thread_params[i].table_name = table_name; + thread_params[i].test_count = MAX_SCAN_COUNT; + thread_params[i].rule_count = 5000; + thread_params[i].time_elapse_ms = 0; + thread_params[i].logger = logger; + + if (i < PERF_THREAD_NUM) { + pthread_create(&threads[i], NULL, perf_stream_scan_thread, thread_params+i); + } + } + + long long time_elapse_ms = 0; + long long scan_count = 0; + long long scan_per_second = 0; + for (i = 0; i < PERF_THREAD_NUM; i++) { + pthread_join(threads[i], (void **)&is_all_hit); + time_elapse_ms += thread_params[i].time_elapse_ms; + scan_count += thread_params[i].test_count; + + EXPECT_EQ(*is_all_hit, 1); + *is_all_hit = 0; + free(is_all_hit); + } + scan_per_second = scan_count * 1000 / time_elapse_ms; + + log_info(maat_inst->logger, MODULE_BENCHMARK_GTEST, + "Stream5KScan match rate on %d-threads speed %lld lookups/s/thread", + PERF_THREAD_NUM, scan_per_second); +} + +class Stream10KBenchmarkGTest : public ::testing::Test +{ +protected: + static void SetUpTestCase() { + logger = log_handle_create("./benchmark_hs_gtest.log", 0); + generate_expr_sample("STREAM_10K", 10000); + + FILE *fp = fopen("full_config_index.0000001", "w+"); + if (NULL == fp) { + log_error(g_logger, "open file %s failed", "full_config_index.0000001"); + return; + } + fprintf(fp, "STREAM_10K 10000 ./STREAM_10K\n"); + fprintf(fp, "COMPILE_PERF 10 ./COMPILE_PERF\n"); + fprintf(fp, "GROUP2COMPILE_PERF 10 ./GROUP2COMPILE_PERF\n"); + fclose(fp); + + struct maat_options *opts = maat_options_new(); + maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO); + maat_options_set_iris(opts, "./", "./"); + maat_options_set_rule_effect_interval_ms(opts, 1000); + maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM); + _shared_maat_inst = maat_new(opts, table_info_path); + maat_options_free(opts); + } + + static void TearDownTestCase() { + maat_free(_shared_maat_inst); + log_handle_destroy(logger); + } + + static struct log_handle *logger; + static struct maat *_shared_maat_inst; +}; + +struct maat *Stream10KBenchmarkGTest::_shared_maat_inst; +struct log_handle *Stream10KBenchmarkGTest::logger; + +TEST_F(Stream10KBenchmarkGTest, LiteralScan) { + const char *table_name = "STREAM_10K"; + struct maat *maat_inst = Stream10KBenchmarkGTest::_shared_maat_inst; + + int table_id = maat_get_table_id(maat_inst, table_name); + ASSERT_GT(table_id, 0); + + pthread_t threads[PERF_THREAD_NUM]; + struct thread_param thread_params[PERF_THREAD_NUM]; + int i = 0; + int *is_all_hit = NULL; + + for (i = 0; i < PERF_THREAD_NUM; i++) { + thread_params[i].maat_inst = maat_inst; + thread_params[i].thread_id = i; + thread_params[i].table_name = table_name; + thread_params[i].test_count = MAX_SCAN_COUNT; + thread_params[i].rule_count = 10000; + thread_params[i].time_elapse_ms = 0; + thread_params[i].logger = logger; + + if (i < PERF_THREAD_NUM) { + pthread_create(&threads[i], NULL, perf_stream_scan_thread, thread_params+i); + } + } + + long long time_elapse_ms = 0; + long long scan_count = 0; + long long scan_per_second = 0; + for (i = 0; i < PERF_THREAD_NUM; i++) { + pthread_join(threads[i], (void **)&is_all_hit); + time_elapse_ms += thread_params[i].time_elapse_ms; + scan_count += thread_params[i].test_count; + + EXPECT_EQ(*is_all_hit, 1); + *is_all_hit = 0; + free(is_all_hit); + } + scan_per_second = scan_count * 1000 / time_elapse_ms; + + log_info(maat_inst->logger, MODULE_BENCHMARK_GTEST, + "Stream10KScan match rate on %d-threads speed %lld lookups/s/thread", + PERF_THREAD_NUM, scan_per_second); +} + +class Stream50KBenchmarkGTest : public ::testing::Test +{ +protected: + static void SetUpTestCase() { + logger = log_handle_create("./benchmark_hs_gtest.log", 0); + generate_expr_sample("STREAM_50K", 50000); + + FILE *fp = fopen("full_config_index.0000001", "w+"); + if (NULL == fp) { + log_error(g_logger, "open file %s failed", "full_config_index.0000001"); + return; + } + fprintf(fp, "STREAM_50K 50000 ./STREAM_50K\n"); + fprintf(fp, "COMPILE_PERF 10 ./COMPILE_PERF\n"); + fprintf(fp, "GROUP2COMPILE_PERF 10 ./GROUP2COMPILE_PERF\n"); + fclose(fp); + + struct maat_options *opts = maat_options_new(); + maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO); + maat_options_set_iris(opts, "./", "./"); + maat_options_set_rule_effect_interval_ms(opts, 1000); + maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM); + _shared_maat_inst = maat_new(opts, table_info_path); + maat_options_free(opts); + } + + static void TearDownTestCase() { + maat_free(_shared_maat_inst); + log_handle_destroy(logger); + } + + static struct log_handle *logger; + static struct maat *_shared_maat_inst; +}; + +struct maat *Stream50KBenchmarkGTest::_shared_maat_inst; +struct log_handle *Stream50KBenchmarkGTest::logger; + +TEST_F(Stream50KBenchmarkGTest, LiteralScan) { + const char *table_name = "STREAM_50K"; + struct maat *maat_inst = Stream50KBenchmarkGTest::_shared_maat_inst; + + int table_id = maat_get_table_id(maat_inst, table_name); + ASSERT_GT(table_id, 0); + + pthread_t threads[PERF_THREAD_NUM]; + struct thread_param thread_params[PERF_THREAD_NUM]; + int i = 0; + int *is_all_hit = NULL; + + for (i = 0; i < PERF_THREAD_NUM; i++) { + thread_params[i].maat_inst = maat_inst; + thread_params[i].thread_id = i; + thread_params[i].table_name = table_name; + thread_params[i].test_count = MAX_SCAN_COUNT; + thread_params[i].rule_count = 50000; + thread_params[i].time_elapse_ms = 0; + thread_params[i].logger = logger; + + if (i < PERF_THREAD_NUM) { + pthread_create(&threads[i], NULL, perf_stream_scan_thread, thread_params+i); + } + } + + long long time_elapse_ms = 0; + long long scan_count = 0; + long long scan_per_second = 0; + for (i = 0; i < PERF_THREAD_NUM; i++) { + pthread_join(threads[i], (void **)&is_all_hit); + time_elapse_ms += thread_params[i].time_elapse_ms; + scan_count += thread_params[i].test_count; + + EXPECT_EQ(*is_all_hit, 1); + *is_all_hit = 0; + free(is_all_hit); + } + scan_per_second = scan_count * 1000 / time_elapse_ms; + + log_info(maat_inst->logger, MODULE_BENCHMARK_GTEST, + "Stream50KScan match rate on %d-threads speed %lld lookups/s/thread", + PERF_THREAD_NUM, scan_per_second); +} + +class Stream100KBenchmarkGTest : public ::testing::Test +{ +protected: + static void SetUpTestCase() { + logger = log_handle_create("./benchmark_hs_gtest.log", 0); + generate_expr_sample("STREAM_100K", 100000); + + FILE *fp = fopen("full_config_index.0000001", "w+"); + if (NULL == fp) { + log_error(g_logger, "open file %s failed", "full_config_index.0000001"); + return; + } + fprintf(fp, "STREAM_100K 100000 ./STREAM_100K\n"); + fprintf(fp, "COMPILE_PERF 10 ./COMPILE_PERF\n"); + fprintf(fp, "GROUP2COMPILE_PERF 10 ./GROUP2COMPILE_PERF\n"); + fclose(fp); + + struct maat_options *opts = maat_options_new(); + maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO); + maat_options_set_iris(opts, "./", "./"); + maat_options_set_rule_effect_interval_ms(opts, 1000); + maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM); + _shared_maat_inst = maat_new(opts, table_info_path); + maat_options_free(opts); + } + + static void TearDownTestCase() { + maat_free(_shared_maat_inst); + log_handle_destroy(logger); + } + + static struct log_handle *logger; + static struct maat *_shared_maat_inst; +}; + +struct maat *Stream100KBenchmarkGTest::_shared_maat_inst; +struct log_handle *Stream100KBenchmarkGTest::logger; + +TEST_F(Stream100KBenchmarkGTest, LiteralScan) { + const char *table_name = "STREAM_100K"; + struct maat *maat_inst = Stream100KBenchmarkGTest::_shared_maat_inst; + + int table_id = maat_get_table_id(maat_inst, table_name); + ASSERT_GT(table_id, 0); + + pthread_t threads[PERF_THREAD_NUM]; + struct thread_param thread_params[PERF_THREAD_NUM]; + int i = 0; + int *is_all_hit = NULL; + + for (i = 0; i < PERF_THREAD_NUM; i++) { + thread_params[i].maat_inst = maat_inst; + thread_params[i].thread_id = i; + thread_params[i].table_name = table_name; + thread_params[i].test_count = MAX_SCAN_COUNT; + thread_params[i].rule_count = 100000; + thread_params[i].time_elapse_ms = 0; + thread_params[i].logger = logger; + + if (i < PERF_THREAD_NUM) { + pthread_create(&threads[i], NULL, perf_stream_scan_thread, thread_params+i); + } + } + + long long time_elapse_ms = 0; + long long scan_count = 0; + long long scan_per_second = 0; + for (i = 0; i < PERF_THREAD_NUM; i++) { + pthread_join(threads[i], (void **)&is_all_hit); + time_elapse_ms += thread_params[i].time_elapse_ms; + scan_count += thread_params[i].test_count; + + EXPECT_EQ(*is_all_hit, 1); + *is_all_hit = 0; + free(is_all_hit); + } + scan_per_second = scan_count * 1000 / time_elapse_ms; + + log_info(maat_inst->logger, MODULE_BENCHMARK_GTEST, + "Stream100KScan match rate on %d-threads speed %lld lookups/s/thread", + PERF_THREAD_NUM, scan_per_second); +} + +class Stream500KBenchmarkGTest : public ::testing::Test +{ +protected: + static void SetUpTestCase() { + logger = log_handle_create("./benchmark_hs_gtest.log", 0); + generate_expr_sample("STREAM_500K", 500000); + + FILE *fp = fopen("full_config_index.0000001", "w+"); + if (NULL == fp) { + log_error(g_logger, "open file %s failed", "full_config_index.0000001"); + return; + } + fprintf(fp, "STREAM_500K 500000 ./STREAM_500K\n"); + fprintf(fp, "COMPILE_PERF 10 ./COMPILE_PERF\n"); + fprintf(fp, "GROUP2COMPILE_PERF 10 ./GROUP2COMPILE_PERF\n"); + fclose(fp); + + struct maat_options *opts = maat_options_new(); + maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO); + maat_options_set_iris(opts, "./", "./"); + maat_options_set_rule_effect_interval_ms(opts, 1000); + maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM); + _shared_maat_inst = maat_new(opts, table_info_path); + maat_options_free(opts); + } + + static void TearDownTestCase() { + maat_free(_shared_maat_inst); + log_handle_destroy(logger); + } + + static struct log_handle *logger; + static struct maat *_shared_maat_inst; +}; + +struct maat *Stream500KBenchmarkGTest::_shared_maat_inst; +struct log_handle *Stream500KBenchmarkGTest::logger; + +TEST_F(Stream500KBenchmarkGTest, LiteralScan) { + const char *table_name = "STREAM_500K"; + struct maat *maat_inst = Stream500KBenchmarkGTest::_shared_maat_inst; + + int table_id = maat_get_table_id(maat_inst, table_name); + ASSERT_GT(table_id, 0); + + pthread_t threads[PERF_THREAD_NUM]; + struct thread_param thread_params[PERF_THREAD_NUM]; + int i = 0; + int *is_all_hit = NULL; + + for (i = 0; i < PERF_THREAD_NUM; i++) { + thread_params[i].maat_inst = maat_inst; + thread_params[i].thread_id = i; + thread_params[i].table_name = table_name; + thread_params[i].test_count = MAX_SCAN_COUNT; + thread_params[i].rule_count = 500000; + thread_params[i].time_elapse_ms = 0; + thread_params[i].logger = logger; + + if (i < PERF_THREAD_NUM) { + pthread_create(&threads[i], NULL, perf_stream_scan_thread, thread_params+i); + } + } + + long long time_elapse_ms = 0; + long long scan_count = 0; + long long scan_per_second = 0; + for (i = 0; i < PERF_THREAD_NUM; i++) { + pthread_join(threads[i], (void **)&is_all_hit); + time_elapse_ms += thread_params[i].time_elapse_ms; + scan_count += thread_params[i].test_count; + + EXPECT_EQ(*is_all_hit, 1); + *is_all_hit = 0; + free(is_all_hit); + } + scan_per_second = scan_count * 1000 / time_elapse_ms; + + log_info(maat_inst->logger, MODULE_BENCHMARK_GTEST, + "Stream500KScan match rate on %d-threads speed %lld lookups/s/thread", + PERF_THREAD_NUM, scan_per_second); +} + +class Stream1MBenchmarkGTest : public ::testing::Test +{ +protected: + static void SetUpTestCase() { + logger = log_handle_create("./benchmark_hs_gtest.log", 0); + generate_expr_sample("STREAM_1M", 1000000); + + FILE *fp = fopen("full_config_index.0000001", "w+"); + if (NULL == fp) { + log_error(g_logger, "open file %s failed", "full_config_index.0000001"); + return; + } + fprintf(fp, "STREAM_1M 1000000 ./STREAM_1M\n"); + fprintf(fp, "COMPILE_PERF 10 ./COMPILE_PERF\n"); + fprintf(fp, "GROUP2COMPILE_PERF 10 ./GROUP2COMPILE_PERF\n"); + fclose(fp); + + struct maat_options *opts = maat_options_new(); + maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO); + maat_options_set_iris(opts, "./", "./"); + maat_options_set_rule_effect_interval_ms(opts, 1000); + maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM); + _shared_maat_inst = maat_new(opts, table_info_path); + maat_options_free(opts); + } + + static void TearDownTestCase() { + maat_free(_shared_maat_inst); + log_handle_destroy(logger); + } + + static struct log_handle *logger; + static struct maat *_shared_maat_inst; +}; + +struct maat *Stream1MBenchmarkGTest::_shared_maat_inst; +struct log_handle *Stream1MBenchmarkGTest::logger; + +TEST_F(Stream1MBenchmarkGTest, LiteralScan) { + const char *table_name = "STREAM_1M"; + struct maat *maat_inst = Stream1MBenchmarkGTest::_shared_maat_inst; + + int table_id = maat_get_table_id(maat_inst, table_name); + ASSERT_GT(table_id, 0); + + pthread_t threads[PERF_THREAD_NUM]; + struct thread_param thread_params[PERF_THREAD_NUM]; + int i = 0; + int *is_all_hit = NULL; + + for (i = 0; i < PERF_THREAD_NUM; i++) { + thread_params[i].maat_inst = maat_inst; + thread_params[i].thread_id = i; + thread_params[i].table_name = table_name; + thread_params[i].test_count = MAX_SCAN_COUNT; + thread_params[i].rule_count = 1000000; + thread_params[i].time_elapse_ms = 0; + thread_params[i].logger = logger; + + if (i < PERF_THREAD_NUM) { + pthread_create(&threads[i], NULL, perf_stream_scan_thread, thread_params+i); + } + } + + long long time_elapse_ms = 0; + long long scan_count = 0; + long long scan_per_second = 0; + for (i = 0; i < PERF_THREAD_NUM; i++) { + pthread_join(threads[i], (void **)&is_all_hit); + time_elapse_ms += thread_params[i].time_elapse_ms; + scan_count += thread_params[i].test_count; + + EXPECT_EQ(*is_all_hit, 1); + *is_all_hit = 0; + free(is_all_hit); + } + scan_per_second = scan_count * 1000 / time_elapse_ms; + + log_info(maat_inst->logger, MODULE_BENCHMARK_GTEST, + "Stream1MScan match rate on %d-threads speed %lld lookups/s/thread", + PERF_THREAD_NUM, scan_per_second); +} + +class Stream2MBenchmarkGTest : public ::testing::Test +{ +protected: + static void SetUpTestCase() { + logger = log_handle_create("./benchmark_hs_gtest.log", 0); + generate_expr_sample("STREAM_2M", 2000000); + + FILE *fp = fopen("full_config_index.0000001", "w+"); + if (NULL == fp) { + log_error(g_logger, "open file %s failed", "full_config_index.0000001"); + return; + } + fprintf(fp, "STREAM_2M 2000000 ./STREAM_2M\n"); + fprintf(fp, "COMPILE_PERF 10 ./COMPILE_PERF\n"); + fprintf(fp, "GROUP2COMPILE_PERF 10 ./GROUP2COMPILE_PERF\n"); + fclose(fp); + + struct maat_options *opts = maat_options_new(); + maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO); + maat_options_set_iris(opts, "./", "./"); + maat_options_set_rule_effect_interval_ms(opts, 1000); + maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM); + _shared_maat_inst = maat_new(opts, table_info_path); + maat_options_free(opts); + } + + static void TearDownTestCase() { + maat_free(_shared_maat_inst); + log_handle_destroy(logger); + } + + static struct log_handle *logger; + static struct maat *_shared_maat_inst; +}; + +struct maat *Stream2MBenchmarkGTest::_shared_maat_inst; +struct log_handle *Stream2MBenchmarkGTest::logger; + +TEST_F(Stream2MBenchmarkGTest, LiteralScan) { + const char *table_name = "STREAM_2M"; + struct maat *maat_inst = Stream2MBenchmarkGTest::_shared_maat_inst; + + int table_id = maat_get_table_id(maat_inst, table_name); + ASSERT_GT(table_id, 0); + + pthread_t threads[PERF_THREAD_NUM]; + struct thread_param thread_params[PERF_THREAD_NUM]; + int i = 0; + int *is_all_hit = NULL; + + for (i = 0; i < PERF_THREAD_NUM; i++) { + thread_params[i].maat_inst = maat_inst; + thread_params[i].thread_id = i; + thread_params[i].table_name = table_name; + thread_params[i].test_count = MAX_SCAN_COUNT; + thread_params[i].rule_count = 2000000; + thread_params[i].time_elapse_ms = 0; + thread_params[i].logger = logger; + + if (i < PERF_THREAD_NUM) { + pthread_create(&threads[i], NULL, perf_stream_scan_thread, thread_params+i); + } + } + + long long time_elapse_ms = 0; + long long scan_count = 0; + long long scan_per_second = 0; + for (i = 0; i < PERF_THREAD_NUM; i++) { + pthread_join(threads[i], (void **)&is_all_hit); + time_elapse_ms += thread_params[i].time_elapse_ms; + scan_count += thread_params[i].test_count; + + EXPECT_EQ(*is_all_hit, 1); + *is_all_hit = 0; + free(is_all_hit); + } + scan_per_second = scan_count * 1000 / time_elapse_ms; + + log_info(maat_inst->logger, MODULE_BENCHMARK_GTEST, + "Stream2MScan match rate on %d-threads speed %lld lookups/s/thread", + PERF_THREAD_NUM, scan_per_second); +} + +class IP1KBenchmarkGTest : public ::testing::Test +{ +protected: + static void SetUpTestCase() { + logger = log_handle_create("./benchmark_hs_gtest.log", 0); + generate_ip_sample("IP_1K", 1000); + + FILE *fp = fopen("full_config_index.0000001", "w+"); + if (NULL == fp) { + log_error(g_logger, "open file %s failed", "full_config_index.0000001"); + return; + } + fprintf(fp, "IP_1K 1000 ./IP_1K\n"); + fprintf(fp, "COMPILE_PERF 10 ./COMPILE_PERF\n"); + fprintf(fp, "GROUP2COMPILE_PERF 10 ./GROUP2COMPILE_PERF\n"); + fclose(fp); + + struct maat_options *opts = maat_options_new(); + maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO); + maat_options_set_iris(opts, "./", "./"); + maat_options_set_rule_effect_interval_ms(opts, 1000); + maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM); + _shared_maat_inst = maat_new(opts, table_info_path); + maat_options_free(opts); + } + + static void TearDownTestCase() { + maat_free(_shared_maat_inst); + log_handle_destroy(logger); + } + + static struct log_handle *logger; + static struct maat *_shared_maat_inst; +}; + +struct maat *IP1KBenchmarkGTest::_shared_maat_inst; +struct log_handle *IP1KBenchmarkGTest::logger; + +TEST_F(IP1KBenchmarkGTest, IPScan) { + const char *table_name = "IP_1K"; + struct maat *maat_inst = IP1KBenchmarkGTest::_shared_maat_inst; + + int table_id = maat_get_table_id(maat_inst, table_name); + ASSERT_GT(table_id, 0); + + pthread_t threads[PERF_THREAD_NUM + 1]; + struct thread_param thread_params[PERF_THREAD_NUM + 1]; + int i = 0; + int *is_all_hit = NULL; + + for (i = 0; i < PERF_THREAD_NUM + 1; i++) { + thread_params[i].maat_inst = maat_inst; + thread_params[i].thread_id = i; + thread_params[i].table_name = table_name; + thread_params[i].test_count = MAX_SCAN_COUNT; + thread_params[i].rule_count = 1000; + thread_params[i].time_elapse_ms = 0; + thread_params[i].logger = logger; + + if (i < PERF_THREAD_NUM) { + pthread_create(&threads[i], NULL, perf_ip_scan_thread, thread_params+i); + } else { + thread_params[i].test_count = 0; + pthread_create(&threads[i], NULL, perf_ip_update_thread, thread_params+i); + } + } + + long long time_elapse_ms = 0; + long long scan_count = 0; + long long scan_per_second = 0; + for (i = 0; i < PERF_THREAD_NUM + 1; i++) { + pthread_join(threads[i], (void **)&is_all_hit); + time_elapse_ms += thread_params[i].time_elapse_ms; + scan_count += thread_params[i].test_count; + + EXPECT_EQ(*is_all_hit, 1); + *is_all_hit = 0; + free(is_all_hit); + } + scan_per_second = scan_count * 1000 / time_elapse_ms; + + log_info(maat_inst->logger, MODULE_BENCHMARK_GTEST, + "IP1KScan match rate on %d-threads speed %lld lookups/s/thread", + PERF_THREAD_NUM, scan_per_second); +} + +class IP5KBenchmarkGTest : public ::testing::Test +{ +protected: + static void SetUpTestCase() { + logger = log_handle_create("./benchmark_hs_gtest.log", 0); + generate_ip_sample("IP_5K", 5000); + + FILE *fp = fopen("full_config_index.0000001", "w+"); + if (NULL == fp) { + log_error(g_logger, "open file %s failed", "full_config_index.0000001"); + return; + } + fprintf(fp, "IP_5K 5000 ./IP_5K\n"); + fprintf(fp, "COMPILE_PERF 10 ./COMPILE_PERF\n"); + fprintf(fp, "GROUP2COMPILE_PERF 10 ./GROUP2COMPILE_PERF\n"); + fclose(fp); + + struct maat_options *opts = maat_options_new(); + maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO); + maat_options_set_iris(opts, "./", "./"); + maat_options_set_rule_effect_interval_ms(opts, 1000); + maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM); + _shared_maat_inst = maat_new(opts, table_info_path); + maat_options_free(opts); + } + + static void TearDownTestCase() { + maat_free(_shared_maat_inst); + log_handle_destroy(logger); + } + + static struct log_handle *logger; + static struct maat *_shared_maat_inst; +}; + +struct maat *IP5KBenchmarkGTest::_shared_maat_inst; +struct log_handle *IP5KBenchmarkGTest::logger; + +TEST_F(IP5KBenchmarkGTest, IPScan) { + const char *table_name = "IP_5K"; + struct maat *maat_inst = IP5KBenchmarkGTest::_shared_maat_inst; + + int table_id = maat_get_table_id(maat_inst, table_name); + ASSERT_GT(table_id, 0); + + pthread_t threads[PERF_THREAD_NUM + 1]; + struct thread_param thread_params[PERF_THREAD_NUM + 1]; + int i = 0; + int *is_all_hit = NULL; + + for (i = 0; i < PERF_THREAD_NUM + 1; i++) { + thread_params[i].maat_inst = maat_inst; + thread_params[i].thread_id = i; + thread_params[i].table_name = table_name; + thread_params[i].test_count = MAX_SCAN_COUNT; + thread_params[i].rule_count = 5000; + thread_params[i].time_elapse_ms = 0; + thread_params[i].logger = logger; + + if (i < PERF_THREAD_NUM) { + pthread_create(&threads[i], NULL, perf_ip_scan_thread, thread_params+i); + } else { + thread_params[i].test_count = 0; + pthread_create(&threads[i], NULL, perf_ip_update_thread, thread_params+i); + } + } + + long long time_elapse_ms = 0; + long long scan_count = 0; + long long scan_per_second = 0; + for (i = 0; i < PERF_THREAD_NUM + 1; i++) { + pthread_join(threads[i], (void **)&is_all_hit); + time_elapse_ms += thread_params[i].time_elapse_ms; + scan_count += thread_params[i].test_count; + + EXPECT_EQ(*is_all_hit, 1); + *is_all_hit = 0; + free(is_all_hit); + } + scan_per_second = scan_count * 1000 / time_elapse_ms; + + log_info(maat_inst->logger, MODULE_BENCHMARK_GTEST, + "IP5KScan match rate on %d-threads speed %lld lookups/s/thread", + PERF_THREAD_NUM, scan_per_second); +} + +class IP10KBenchmarkGTest : public ::testing::Test +{ +protected: + static void SetUpTestCase() { + logger = log_handle_create("./benchmark_hs_gtest.log", 0); + generate_ip_sample("IP_10K", 10000); + + FILE *fp = fopen("full_config_index.0000001", "w+"); + if (NULL == fp) { + log_error(g_logger, "open file %s failed", "full_config_index.0000001"); + return; + } + fprintf(fp, "IP_10K 10000 ./IP_10K\n"); + fprintf(fp, "COMPILE_PERF 10 ./COMPILE_PERF\n"); + fprintf(fp, "GROUP2COMPILE_PERF 10 ./GROUP2COMPILE_PERF\n"); + fclose(fp); + + struct maat_options *opts = maat_options_new(); + maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO); + maat_options_set_iris(opts, "./", "./"); + maat_options_set_rule_effect_interval_ms(opts, 1000); + maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM); + _shared_maat_inst = maat_new(opts, table_info_path); + maat_options_free(opts); + } + + static void TearDownTestCase() { + maat_free(_shared_maat_inst); + log_handle_destroy(logger); + } + + static struct log_handle *logger; + static struct maat *_shared_maat_inst; +}; + +struct maat *IP10KBenchmarkGTest::_shared_maat_inst; +struct log_handle *IP10KBenchmarkGTest::logger; + +TEST_F(IP10KBenchmarkGTest, IPScan) { + const char *table_name = "IP_10K"; + struct maat *maat_inst = IP10KBenchmarkGTest::_shared_maat_inst; + + int table_id = maat_get_table_id(maat_inst, table_name); + ASSERT_GT(table_id, 0); + + pthread_t threads[PERF_THREAD_NUM + 1]; + struct thread_param thread_params[PERF_THREAD_NUM + 1]; + int i = 0; + int *is_all_hit = NULL; + + for (i = 0; i < PERF_THREAD_NUM + 1; i++) { + thread_params[i].maat_inst = maat_inst; + thread_params[i].thread_id = i; + thread_params[i].table_name = table_name; + thread_params[i].test_count = MAX_SCAN_COUNT; + thread_params[i].rule_count = 10000; + thread_params[i].time_elapse_ms = 0; + thread_params[i].logger = logger; + + if (i < PERF_THREAD_NUM) { + pthread_create(&threads[i], NULL, perf_ip_scan_thread, thread_params+i); + } else { + thread_params[i].test_count = 0; + pthread_create(&threads[i], NULL, perf_ip_update_thread, thread_params+i); + } + } + + long long time_elapse_ms = 0; + long long scan_count = 0; + long long scan_per_second = 0; + for (i = 0; i < PERF_THREAD_NUM + 1; i++) { + pthread_join(threads[i], (void **)&is_all_hit); + time_elapse_ms += thread_params[i].time_elapse_ms; + scan_count += thread_params[i].test_count; + + EXPECT_EQ(*is_all_hit, 1); + *is_all_hit = 0; + free(is_all_hit); + } + scan_per_second = scan_count * 1000 / time_elapse_ms; + + log_info(maat_inst->logger, MODULE_BENCHMARK_GTEST, + "IP10KScan match rate on %d-threads speed %lld lookups/s/thread", + PERF_THREAD_NUM, scan_per_second); +} + +class IP50KBenchmarkGTest : public ::testing::Test +{ +protected: + static void SetUpTestCase() { + logger = log_handle_create("./benchmark_hs_gtest.log", 0); + generate_ip_sample("IP_50K", 50000); + + FILE *fp = fopen("full_config_index.0000001", "w+"); + if (NULL == fp) { + log_error(g_logger, "open file %s failed", "full_config_index.0000001"); + return; + } + fprintf(fp, "IP_50K 50000 ./IP_50K\n"); + fprintf(fp, "COMPILE_PERF 10 ./COMPILE_PERF\n"); + fprintf(fp, "GROUP2COMPILE_PERF 10 ./GROUP2COMPILE_PERF\n"); + fclose(fp); + + struct maat_options *opts = maat_options_new(); + maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO); + maat_options_set_iris(opts, "./", "./"); + maat_options_set_rule_effect_interval_ms(opts, 1000); + maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM); + _shared_maat_inst = maat_new(opts, table_info_path); + maat_options_free(opts); + } + + static void TearDownTestCase() { + maat_free(_shared_maat_inst); + log_handle_destroy(logger); + } + + static struct log_handle *logger; + static struct maat *_shared_maat_inst; +}; + +struct maat *IP50KBenchmarkGTest::_shared_maat_inst; +struct log_handle *IP50KBenchmarkGTest::logger; + +TEST_F(IP50KBenchmarkGTest, IPScan) { + const char *table_name = "IP_50K"; + struct maat *maat_inst = IP50KBenchmarkGTest::_shared_maat_inst; + + int table_id = maat_get_table_id(maat_inst, table_name); + ASSERT_GT(table_id, 0); + + pthread_t threads[PERF_THREAD_NUM + 1]; + struct thread_param thread_params[PERF_THREAD_NUM + 1]; + int i = 0; + int *is_all_hit = NULL; + + for (i = 0; i < PERF_THREAD_NUM + 1; i++) { + thread_params[i].maat_inst = maat_inst; + thread_params[i].thread_id = i; + thread_params[i].table_name = table_name; + thread_params[i].test_count = MAX_SCAN_COUNT; + thread_params[i].rule_count = 50000; + thread_params[i].time_elapse_ms = 0; + thread_params[i].logger = logger; + + if (i < PERF_THREAD_NUM) { + pthread_create(&threads[i], NULL, perf_ip_scan_thread, thread_params+i); + } else { + thread_params[i].test_count = 0; + pthread_create(&threads[i], NULL, perf_ip_update_thread, thread_params+i); + } + } + + long long time_elapse_ms = 0; + long long scan_count = 0; + long long scan_per_second = 0; + for (i = 0; i < PERF_THREAD_NUM + 1; i++) { + pthread_join(threads[i], (void **)&is_all_hit); + time_elapse_ms += thread_params[i].time_elapse_ms; + scan_count += thread_params[i].test_count; + + EXPECT_EQ(*is_all_hit, 1); + *is_all_hit = 0; + free(is_all_hit); + } + scan_per_second = scan_count * 1000 / time_elapse_ms; + + log_info(maat_inst->logger, MODULE_BENCHMARK_GTEST, + "IP50KScan match rate on %d-threads speed %lld lookups/s/thread", + PERF_THREAD_NUM, scan_per_second); +} + +class IP100KBenchmarkGTest : public ::testing::Test +{ +protected: + static void SetUpTestCase() { + logger = log_handle_create("./benchmark_hs_gtest.log", 0); + generate_ip_sample("IP_100K", 100000); + + FILE *fp = fopen("full_config_index.0000001", "w+"); + if (NULL == fp) { + log_error(g_logger, "open file %s failed", "full_config_index.0000001"); + return; + } + fprintf(fp, "IP_100K 100000 ./IP_100K\n"); + fprintf(fp, "COMPILE_PERF 10 ./COMPILE_PERF\n"); + fprintf(fp, "GROUP2COMPILE_PERF 10 ./GROUP2COMPILE_PERF\n"); + fclose(fp); + + struct maat_options *opts = maat_options_new(); + maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO); + maat_options_set_iris(opts, "./", "./"); + maat_options_set_rule_effect_interval_ms(opts, 1000); + maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM); + _shared_maat_inst = maat_new(opts, table_info_path); + maat_options_free(opts); + } + + static void TearDownTestCase() { + maat_free(_shared_maat_inst); + log_handle_destroy(logger); + } + + static struct log_handle *logger; + static struct maat *_shared_maat_inst; +}; + +struct maat *IP100KBenchmarkGTest::_shared_maat_inst; +struct log_handle *IP100KBenchmarkGTest::logger; + +TEST_F(IP100KBenchmarkGTest, IPScan) { + const char *table_name = "IP_100K"; + struct maat *maat_inst = IP100KBenchmarkGTest::_shared_maat_inst; + + int table_id = maat_get_table_id(maat_inst, table_name); + ASSERT_GT(table_id, 0); + + pthread_t threads[PERF_THREAD_NUM + 1]; + struct thread_param thread_params[PERF_THREAD_NUM + 1]; + int i = 0; + int *is_all_hit = NULL; + + for (i = 0; i < PERF_THREAD_NUM + 1; i++) { + thread_params[i].maat_inst = maat_inst; + thread_params[i].thread_id = i; + thread_params[i].table_name = table_name; + thread_params[i].test_count = MAX_SCAN_COUNT; + thread_params[i].rule_count = 100000; + thread_params[i].time_elapse_ms = 0; + thread_params[i].logger = logger; + + if (i < PERF_THREAD_NUM) { + pthread_create(&threads[i], NULL, perf_ip_scan_thread, thread_params+i); + } else { + thread_params[i].test_count = 0; + pthread_create(&threads[i], NULL, perf_ip_update_thread, thread_params+i); + } + } + + long long time_elapse_ms = 0; + long long scan_count = 0; + long long scan_per_second = 0; + for (i = 0; i < PERF_THREAD_NUM + 1; i++) { + pthread_join(threads[i], (void **)&is_all_hit); + time_elapse_ms += thread_params[i].time_elapse_ms; + scan_count += thread_params[i].test_count; + + EXPECT_EQ(*is_all_hit, 1); + *is_all_hit = 0; + free(is_all_hit); + } + scan_per_second = scan_count * 1000 / time_elapse_ms; + + log_info(maat_inst->logger, MODULE_BENCHMARK_GTEST, + "IP100KScan match rate on %d-threads speed %lld lookups/s/thread", + PERF_THREAD_NUM, scan_per_second); +} + +class IP500KBenchmarkGTest : public ::testing::Test +{ +protected: + static void SetUpTestCase() { + logger = log_handle_create("./benchmark_hs_gtest.log", 0); + generate_ip_sample("IP_500K", 500000); + + FILE *fp = fopen("full_config_index.0000001", "w+"); + if (NULL == fp) { + log_error(g_logger, "open file %s failed", "full_config_index.0000001"); + return; + } + fprintf(fp, "IP_500K 500000 ./IP_500K\n"); + fprintf(fp, "COMPILE_PERF 10 ./COMPILE_PERF\n"); + fprintf(fp, "GROUP2COMPILE_PERF 10 ./GROUP2COMPILE_PERF\n"); + fclose(fp); + + struct maat_options *opts = maat_options_new(); + maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO); + maat_options_set_iris(opts, "./", "./"); + maat_options_set_rule_effect_interval_ms(opts, 1000); + maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM); + _shared_maat_inst = maat_new(opts, table_info_path); + maat_options_free(opts); + } + + static void TearDownTestCase() { + maat_free(_shared_maat_inst); + log_handle_destroy(logger); + } + + static struct log_handle *logger; + static struct maat *_shared_maat_inst; +}; + +struct maat *IP500KBenchmarkGTest::_shared_maat_inst; +struct log_handle *IP500KBenchmarkGTest::logger; + +TEST_F(IP500KBenchmarkGTest, IPScan) { + const char *table_name = "IP_500K"; + struct maat *maat_inst = IP500KBenchmarkGTest::_shared_maat_inst; + + int table_id = maat_get_table_id(maat_inst, table_name); + ASSERT_GT(table_id, 0); + + pthread_t threads[PERF_THREAD_NUM + 1]; + struct thread_param thread_params[PERF_THREAD_NUM + 1]; + int i = 0; + int *is_all_hit = NULL; + + for (i = 0; i < PERF_THREAD_NUM + 1; i++) { + thread_params[i].maat_inst = maat_inst; + thread_params[i].thread_id = i; + thread_params[i].table_name = table_name; + thread_params[i].test_count = MAX_SCAN_COUNT; + thread_params[i].rule_count = 500000; + thread_params[i].time_elapse_ms = 0; + thread_params[i].logger = logger; + + if (i < PERF_THREAD_NUM) { + pthread_create(&threads[i], NULL, perf_ip_scan_thread, thread_params+i); + } else { + thread_params[i].test_count = 0; + pthread_create(&threads[i], NULL, perf_ip_update_thread, thread_params+i); + } + } + + long long time_elapse_ms = 0; + long long scan_count = 0; + long long scan_per_second = 0; + for (i = 0; i < PERF_THREAD_NUM + 1; i++) { + pthread_join(threads[i], (void **)&is_all_hit); + time_elapse_ms += thread_params[i].time_elapse_ms; + scan_count += thread_params[i].test_count; + + EXPECT_EQ(*is_all_hit, 1); + *is_all_hit = 0; + free(is_all_hit); + } + scan_per_second = scan_count * 1000 / time_elapse_ms; + + log_info(maat_inst->logger, MODULE_BENCHMARK_GTEST, + "IP500KScan match rate on %d-threads speed %lld lookups/s/thread", + PERF_THREAD_NUM, scan_per_second); +} + +class IP1MBenchmarkGTest : public ::testing::Test +{ +protected: + static void SetUpTestCase() { + logger = log_handle_create("./benchmark_hs_gtest.log", 0); + generate_ip_sample("IP_1M", 1000000); + + FILE *fp = fopen("full_config_index.0000001", "w+"); + if (NULL == fp) { + log_error(g_logger, "open file %s failed", "full_config_index.0000001"); + return; + } + fprintf(fp, "IP_1M 1000000 ./IP_1M\n"); + fprintf(fp, "COMPILE_PERF 10 ./COMPILE_PERF\n"); + fprintf(fp, "GROUP2COMPILE_PERF 10 ./GROUP2COMPILE_PERF\n"); + fclose(fp); + + struct maat_options *opts = maat_options_new(); + maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO); + maat_options_set_iris(opts, "./", "./"); + maat_options_set_rule_effect_interval_ms(opts, 1000); + maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM); + _shared_maat_inst = maat_new(opts, table_info_path); + maat_options_free(opts); + } + + static void TearDownTestCase() { + maat_free(_shared_maat_inst); + log_handle_destroy(logger); + } + + static struct log_handle *logger; + static struct maat *_shared_maat_inst; +}; + +struct maat *IP1MBenchmarkGTest::_shared_maat_inst; +struct log_handle *IP1MBenchmarkGTest::logger; + +TEST_F(IP1MBenchmarkGTest, IPScan) { + const char *table_name = "IP_1M"; + struct maat *maat_inst = IP1MBenchmarkGTest::_shared_maat_inst; + + int table_id = maat_get_table_id(maat_inst, table_name); + ASSERT_GT(table_id, 0); + + pthread_t threads[PERF_THREAD_NUM + 1]; + struct thread_param thread_params[PERF_THREAD_NUM + 1]; + int i = 0; + int *is_all_hit = NULL; + + for (i = 0; i < PERF_THREAD_NUM + 1; i++) { + thread_params[i].maat_inst = maat_inst; + thread_params[i].thread_id = i; + thread_params[i].table_name = table_name; + thread_params[i].test_count = MAX_SCAN_COUNT; + thread_params[i].rule_count = 1000000; + thread_params[i].time_elapse_ms = 0; + thread_params[i].logger = logger; + + if (i < PERF_THREAD_NUM) { + pthread_create(&threads[i], NULL, perf_ip_scan_thread, thread_params+i); + } else { + thread_params[i].test_count = 0; + pthread_create(&threads[i], NULL, perf_ip_update_thread, thread_params+i); + } + } + + long long time_elapse_ms = 0; + long long scan_count = 0; + long long scan_per_second = 0; + for (i = 0; i < PERF_THREAD_NUM + 1; i++) { + pthread_join(threads[i], (void **)&is_all_hit); + time_elapse_ms += thread_params[i].time_elapse_ms; + scan_count += thread_params[i].test_count; + + EXPECT_EQ(*is_all_hit, 1); + *is_all_hit = 0; + free(is_all_hit); + } + scan_per_second = scan_count * 1000 / time_elapse_ms; + + log_info(maat_inst->logger, MODULE_BENCHMARK_GTEST, + "IP1MScan match rate on %d-threads speed %lld lookups/s/thread", + PERF_THREAD_NUM, scan_per_second); +} + +class IP5MBenchmarkGTest : public ::testing::Test +{ +protected: + static void SetUpTestCase() { + logger = log_handle_create("./benchmark_hs_gtest.log", 0); + generate_ip_sample("IP_5M", 5000000); + + FILE *fp = fopen("full_config_index.0000001", "w+"); + if (NULL == fp) { + log_error(g_logger, "open file %s failed", "full_config_index.0000001"); + return; + } + fprintf(fp, "IP_5M 5000000 ./IP_5M\n"); + fprintf(fp, "COMPILE_PERF 10 ./COMPILE_PERF\n"); + fprintf(fp, "GROUP2COMPILE_PERF 10 ./GROUP2COMPILE_PERF\n"); + fclose(fp); + + struct maat_options *opts = maat_options_new(); + maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO); + maat_options_set_iris(opts, "./", "./"); + maat_options_set_rule_effect_interval_ms(opts, 1000); + maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM); + _shared_maat_inst = maat_new(opts, table_info_path); + maat_options_free(opts); + } + + static void TearDownTestCase() { + maat_free(_shared_maat_inst); + log_handle_destroy(logger); + } + + static struct log_handle *logger; + static struct maat *_shared_maat_inst; +}; + +struct maat *IP5MBenchmarkGTest::_shared_maat_inst; +struct log_handle *IP5MBenchmarkGTest::logger; + +TEST_F(IP5MBenchmarkGTest, IPScan) { + const char *table_name = "IP_5M"; + struct maat *maat_inst = IP5MBenchmarkGTest::_shared_maat_inst; + + int table_id = maat_get_table_id(maat_inst, table_name); + ASSERT_GT(table_id, 0); + + pthread_t threads[PERF_THREAD_NUM + 1]; + struct thread_param thread_params[PERF_THREAD_NUM + 1]; + int i = 0; + int *is_all_hit = NULL; + + for (i = 0; i < PERF_THREAD_NUM + 1; i++) { + thread_params[i].maat_inst = maat_inst; + thread_params[i].thread_id = i; + thread_params[i].table_name = table_name; + thread_params[i].test_count = MAX_SCAN_COUNT; + thread_params[i].rule_count = 5000000; + thread_params[i].time_elapse_ms = 0; + thread_params[i].logger = logger; + + if (i < PERF_THREAD_NUM) { + pthread_create(&threads[i], NULL, perf_ip_scan_thread, thread_params+i); + } else { + thread_params[i].test_count = 0; + pthread_create(&threads[i], NULL, perf_ip_update_thread, thread_params+i); + } + } + + long long time_elapse_ms = 0; + long long scan_count = 0; + long long scan_per_second = 0; + for (i = 0; i < PERF_THREAD_NUM + 1; i++) { + pthread_join(threads[i], (void **)&is_all_hit); + time_elapse_ms += thread_params[i].time_elapse_ms; + scan_count += thread_params[i].test_count; + + EXPECT_EQ(*is_all_hit, 1); + *is_all_hit = 0; + free(is_all_hit); + } + scan_per_second = scan_count * 1000 / time_elapse_ms; + + log_info(maat_inst->logger, MODULE_BENCHMARK_GTEST, + "IP5MScan match rate on %d-threads speed %lld lookups/s/thread", + PERF_THREAD_NUM, scan_per_second); +} + +class IP10MBenchmarkGTest : public ::testing::Test +{ +protected: + static void SetUpTestCase() { + logger = log_handle_create("./benchmark_hs_gtest.log", 0); + generate_ip_sample("IP_10M", 10000000); + + FILE *fp = fopen("full_config_index.0000001", "w+"); + if (NULL == fp) { + log_error(g_logger, "open file %s failed", "full_config_index.0000001"); + return; + } + fprintf(fp, "IP_10M 10000000 ./IP_10M\n"); + fprintf(fp, "COMPILE_PERF 10 ./COMPILE_PERF\n"); + fprintf(fp, "GROUP2COMPILE_PERF 10 ./GROUP2COMPILE_PERF\n"); + fclose(fp); + + struct maat_options *opts = maat_options_new(); + maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO); + maat_options_set_iris(opts, "./", "./"); + maat_options_set_rule_effect_interval_ms(opts, 1000); + maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM); + _shared_maat_inst = maat_new(opts, table_info_path); + maat_options_free(opts); + } + + static void TearDownTestCase() { + maat_free(_shared_maat_inst); + log_handle_destroy(logger); + } + + static struct log_handle *logger; + static struct maat *_shared_maat_inst; +}; + +struct maat *IP10MBenchmarkGTest::_shared_maat_inst; +struct log_handle *IP10MBenchmarkGTest::logger; + +TEST_F(IP10MBenchmarkGTest, IPScan) { + const char *table_name = "IP_10M"; + struct maat *maat_inst = IP10MBenchmarkGTest::_shared_maat_inst; + + int table_id = maat_get_table_id(maat_inst, table_name); + ASSERT_GT(table_id, 0); + + pthread_t threads[PERF_THREAD_NUM + 1]; + struct thread_param thread_params[PERF_THREAD_NUM + 1]; + int i = 0; + int *is_all_hit = NULL; + + for (i = 0; i < PERF_THREAD_NUM + 1; i++) { + thread_params[i].maat_inst = maat_inst; + thread_params[i].thread_id = i; + thread_params[i].table_name = table_name; + thread_params[i].test_count = MAX_SCAN_COUNT; + thread_params[i].rule_count = 10000000; + thread_params[i].time_elapse_ms = 0; + thread_params[i].logger = logger; + + if (i < PERF_THREAD_NUM) { + pthread_create(&threads[i], NULL, perf_ip_scan_thread, thread_params+i); + } else { + thread_params[i].test_count = 0; + pthread_create(&threads[i], NULL, perf_ip_update_thread, thread_params+i); + } + } + + long long time_elapse_ms = 0; + long long scan_count = 0; + long long scan_per_second = 0; + for (i = 0; i < PERF_THREAD_NUM + 1; i++) { + pthread_join(threads[i], (void **)&is_all_hit); + time_elapse_ms += thread_params[i].time_elapse_ms; + scan_count += thread_params[i].test_count; + + EXPECT_EQ(*is_all_hit, 1); + *is_all_hit = 0; + free(is_all_hit); + } + scan_per_second = scan_count * 1000 / time_elapse_ms; + + log_info(maat_inst->logger, MODULE_BENCHMARK_GTEST, + "IP10MScan match rate on %d-threads speed %lld lookups/s/thread", + PERF_THREAD_NUM, scan_per_second); +} + +class Integer1KBenchmarkGTest : public ::testing::Test +{ +protected: + static void SetUpTestCase() { + logger = log_handle_create("./benchmark_hs_gtest.log", 0); + generate_integer_sample("INTEGER_1K", 1000); + + FILE *fp = fopen("full_config_index.0000001", "w+"); + if (NULL == fp) { + log_error(g_logger, "open file %s failed", "full_config_index.0000001"); + return; + } + fprintf(fp, "INTEGER_1K 1000 ./INTEGER_1K\n"); + fprintf(fp, "COMPILE_PERF 10 ./COMPILE_PERF\n"); + fprintf(fp, "GROUP2COMPILE_PERF 10 ./GROUP2COMPILE_PERF\n"); + fclose(fp); + + struct maat_options *opts = maat_options_new(); + maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO); + maat_options_set_iris(opts, "./", "./"); + maat_options_set_rule_effect_interval_ms(opts, 1000); + maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM); + _shared_maat_inst = maat_new(opts, table_info_path); + maat_options_free(opts); + } + + static void TearDownTestCase() { + maat_free(_shared_maat_inst); + log_handle_destroy(logger); + } + + static struct log_handle *logger; + static struct maat *_shared_maat_inst; +}; + +struct maat *Integer1KBenchmarkGTest::_shared_maat_inst; +struct log_handle *Integer1KBenchmarkGTest::logger; + +TEST_F(Integer1KBenchmarkGTest, IntegerScan) { + const char *table_name = "INTEGER_1K"; + struct maat *maat_inst = Integer1KBenchmarkGTest::_shared_maat_inst; + + int table_id = maat_get_table_id(maat_inst, table_name); + ASSERT_GT(table_id, 0); + + pthread_t threads[PERF_THREAD_NUM + 1]; + struct thread_param thread_params[PERF_THREAD_NUM + 1]; + int i = 0; + int *is_all_hit = NULL; + + for (i = 0; i < PERF_THREAD_NUM + 1; i++) { + thread_params[i].maat_inst = maat_inst; + thread_params[i].thread_id = i; + thread_params[i].table_name = table_name; + thread_params[i].test_count = MAX_SCAN_COUNT; + thread_params[i].rule_count = 1000; + thread_params[i].time_elapse_ms = 0; + thread_params[i].logger = logger; + + if (i < PERF_THREAD_NUM) { + pthread_create(&threads[i], NULL, perf_integer_scan_thread, thread_params+i); + } else { + thread_params[i].test_count = 0; + pthread_create(&threads[i], NULL, perf_integer_update_thread, thread_params+i); + } + } + + long long time_elapse_ms = 0; + long long scan_count = 0; + long long scan_per_second = 0; + for (i = 0; i < PERF_THREAD_NUM + 1; i++) { + pthread_join(threads[i], (void **)&is_all_hit); + time_elapse_ms += thread_params[i].time_elapse_ms; + scan_count += thread_params[i].test_count; + + EXPECT_EQ(*is_all_hit, 1); + *is_all_hit = 0; + free(is_all_hit); + } + scan_per_second = scan_count * 1000 / time_elapse_ms; + + log_info(maat_inst->logger, MODULE_BENCHMARK_GTEST, + "Integer1KScan match rate on %d-threads speed %lld lookups/s/thread", + PERF_THREAD_NUM, scan_per_second); +} + +class Integer5KBenchmarkGTest : public ::testing::Test +{ +protected: + static void SetUpTestCase() { + logger = log_handle_create("./benchmark_hs_gtest.log", 0); + generate_integer_sample("INTEGER_5K", 5000); + + FILE *fp = fopen("full_config_index.0000001", "w+"); + if (NULL == fp) { + log_error(g_logger, "open file %s failed", "full_config_index.0000001"); + return; + } + fprintf(fp, "INTEGER_5K 5000 ./INTEGER_5K\n"); + fprintf(fp, "COMPILE_PERF 10 ./COMPILE_PERF\n"); + fprintf(fp, "GROUP2COMPILE_PERF 10 ./GROUP2COMPILE_PERF\n"); + fclose(fp); + + struct maat_options *opts = maat_options_new(); + maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO); + maat_options_set_iris(opts, "./", "./"); + maat_options_set_rule_effect_interval_ms(opts, 1000); + maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM); + _shared_maat_inst = maat_new(opts, table_info_path); + maat_options_free(opts); + } + + static void TearDownTestCase() { + maat_free(_shared_maat_inst); + log_handle_destroy(logger); + } + + static struct log_handle *logger; + static struct maat *_shared_maat_inst; +}; + +struct maat *Integer5KBenchmarkGTest::_shared_maat_inst; +struct log_handle *Integer5KBenchmarkGTest::logger; + +TEST_F(Integer5KBenchmarkGTest, IntegerScan) { + const char *table_name = "INTEGER_5K"; + struct maat *maat_inst = Integer5KBenchmarkGTest::_shared_maat_inst; + + int table_id = maat_get_table_id(maat_inst, table_name); + ASSERT_GT(table_id, 0); + + pthread_t threads[PERF_THREAD_NUM + 1]; + struct thread_param thread_params[PERF_THREAD_NUM + 1]; + int i = 0; + int *is_all_hit = NULL; + + for (i = 0; i < PERF_THREAD_NUM + 1; i++) { + thread_params[i].maat_inst = maat_inst; + thread_params[i].thread_id = i; + thread_params[i].table_name = table_name; + thread_params[i].test_count = MAX_SCAN_COUNT; + thread_params[i].rule_count = 5000; + thread_params[i].time_elapse_ms = 0; + thread_params[i].logger = logger; + + if (i < PERF_THREAD_NUM) { + pthread_create(&threads[i], NULL, perf_integer_scan_thread, thread_params+i); + } else { + thread_params[i].test_count = 0; + pthread_create(&threads[i], NULL, perf_integer_update_thread, thread_params+i); + } + } + + long long time_elapse_ms = 0; + long long scan_count = 0; + long long scan_per_second = 0; + for (i = 0; i < PERF_THREAD_NUM + 1; i++) { + pthread_join(threads[i], (void **)&is_all_hit); + time_elapse_ms += thread_params[i].time_elapse_ms; + scan_count += thread_params[i].test_count; + + EXPECT_EQ(*is_all_hit, 1); + *is_all_hit = 0; + free(is_all_hit); + } + scan_per_second = scan_count * 1000 / time_elapse_ms; + + log_info(maat_inst->logger, MODULE_BENCHMARK_GTEST, + "Integer5KScan match rate on %d-threads speed %lld lookups/s/thread", + PERF_THREAD_NUM, scan_per_second); +} + +class Integer10KBenchmarkGTest : public ::testing::Test +{ +protected: + static void SetUpTestCase() { + logger = log_handle_create("./benchmark_hs_gtest.log", 0); + generate_integer_sample("INTEGER_10K", 10000); + + FILE *fp = fopen("full_config_index.0000001", "w+"); + if (NULL == fp) { + log_error(g_logger, "open file %s failed", "full_config_index.0000001"); + return; + } + fprintf(fp, "INTEGER_10K 10000 ./INTEGER_10K\n"); + fprintf(fp, "COMPILE_PERF 10 ./COMPILE_PERF\n"); + fprintf(fp, "GROUP2COMPILE_PERF 10 ./GROUP2COMPILE_PERF\n"); + fclose(fp); + + struct maat_options *opts = maat_options_new(); + maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO); + maat_options_set_iris(opts, "./", "./"); + maat_options_set_rule_effect_interval_ms(opts, 1000); + maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM); + _shared_maat_inst = maat_new(opts, table_info_path); + maat_options_free(opts); + } + + static void TearDownTestCase() { + maat_free(_shared_maat_inst); + log_handle_destroy(logger); + } + + static struct log_handle *logger; + static struct maat *_shared_maat_inst; +}; + +struct maat *Integer10KBenchmarkGTest::_shared_maat_inst; +struct log_handle *Integer10KBenchmarkGTest::logger; + +TEST_F(Integer10KBenchmarkGTest, IntegerScan) { + const char *table_name = "INTEGER_10K"; + struct maat *maat_inst = Integer10KBenchmarkGTest::_shared_maat_inst; + + int table_id = maat_get_table_id(maat_inst, table_name); + ASSERT_GT(table_id, 0); + + pthread_t threads[PERF_THREAD_NUM + 1]; + struct thread_param thread_params[PERF_THREAD_NUM + 1]; + int i = 0; + int *is_all_hit = NULL; + + for (i = 0; i < PERF_THREAD_NUM + 1; i++) { + thread_params[i].maat_inst = maat_inst; + thread_params[i].thread_id = i; + thread_params[i].table_name = table_name; + thread_params[i].test_count = MAX_SCAN_COUNT; + thread_params[i].rule_count = 10000; + thread_params[i].time_elapse_ms = 0; + thread_params[i].logger = logger; + + if (i < PERF_THREAD_NUM) { + pthread_create(&threads[i], NULL, perf_integer_scan_thread, thread_params+i); + } else { + thread_params[i].test_count = 0; + pthread_create(&threads[i], NULL, perf_integer_update_thread, thread_params+i); + } + } + + long long time_elapse_ms = 0; + long long scan_count = 0; + long long scan_per_second = 0; + for (i = 0; i < PERF_THREAD_NUM + 1; i++) { + pthread_join(threads[i], (void **)&is_all_hit); + time_elapse_ms += thread_params[i].time_elapse_ms; + scan_count += thread_params[i].test_count; + + EXPECT_EQ(*is_all_hit, 1); + *is_all_hit = 0; + free(is_all_hit); + } + scan_per_second = scan_count * 1000 / time_elapse_ms; + + log_info(maat_inst->logger, MODULE_BENCHMARK_GTEST, + "Integer10KScan match rate on %d-threads speed %lld lookups/s/thread", + PERF_THREAD_NUM, scan_per_second); +} + +class Flag1KBenchmarkGTest : public ::testing::Test +{ +protected: + static void SetUpTestCase() { + logger = log_handle_create("./benchmark_hs_gtest.log", 0); + generate_flag_sample("FLAG_1K", 1000); + + FILE *fp = fopen("full_config_index.0000001", "w+"); + if (NULL == fp) { + log_error(g_logger, "open file %s failed", "full_config_index.0000001"); + return; + } + fprintf(fp, "FLAG_1K 1000 ./FLAG_1K\n"); + fprintf(fp, "COMPILE_PERF 10 ./COMPILE_PERF\n"); + fprintf(fp, "GROUP2COMPILE_PERF 10 ./GROUP2COMPILE_PERF\n"); + fclose(fp); + + struct maat_options *opts = maat_options_new(); + maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO); + maat_options_set_iris(opts, "./", "./"); + maat_options_set_rule_effect_interval_ms(opts, 1000); + maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM); + _shared_maat_inst = maat_new(opts, table_info_path); + maat_options_free(opts); + } + + static void TearDownTestCase() { + maat_free(_shared_maat_inst); + log_handle_destroy(logger); + } + + static struct log_handle *logger; + static struct maat *_shared_maat_inst; +}; + +struct maat *Flag1KBenchmarkGTest::_shared_maat_inst; +struct log_handle *Flag1KBenchmarkGTest::logger; + +TEST_F(Flag1KBenchmarkGTest, FlagScan) { + const char *table_name = "FLAG_1K"; + struct maat *maat_inst = Flag1KBenchmarkGTest::_shared_maat_inst; + + int table_id = maat_get_table_id(maat_inst, table_name); + ASSERT_GT(table_id, 0); + + pthread_t threads[PERF_THREAD_NUM + 1]; + struct thread_param thread_params[PERF_THREAD_NUM + 1]; + int i = 0; + int *is_all_hit = NULL; + + for (i = 0; i < PERF_THREAD_NUM + 1; i++) { + thread_params[i].maat_inst = maat_inst; + thread_params[i].thread_id = i; + thread_params[i].table_name = table_name; + thread_params[i].test_count = MAX_SCAN_COUNT; + thread_params[i].rule_count = 1000; + thread_params[i].time_elapse_ms = 0; + thread_params[i].logger = logger; + + if (i < PERF_THREAD_NUM) { + pthread_create(&threads[i], NULL, perf_flag_scan_thread, thread_params+i); + } else { + thread_params[i].test_count = 0; + pthread_create(&threads[i], NULL, perf_flag_update_thread, thread_params+i); + } + } + + long long time_elapse_ms = 0; + long long scan_count = 0; + long long scan_per_second = 0; + for (i = 0; i < PERF_THREAD_NUM + 1; i++) { + pthread_join(threads[i], (void **)&is_all_hit); + time_elapse_ms += thread_params[i].time_elapse_ms; + scan_count += thread_params[i].test_count; + + EXPECT_EQ(*is_all_hit, 1); + *is_all_hit = 0; + free(is_all_hit); + } + scan_per_second = scan_count * 1000 / time_elapse_ms; + + log_info(maat_inst->logger, MODULE_BENCHMARK_GTEST, + "Flag1KScan match rate on %d-threads speed %lld lookups/s/thread", + PERF_THREAD_NUM, scan_per_second); +} + +class Flag5KBenchmarkGTest : public ::testing::Test +{ +protected: + static void SetUpTestCase() { + logger = log_handle_create("./benchmark_hs_gtest.log", 0); + generate_flag_sample("FLAG_5K", 5000); + + FILE *fp = fopen("full_config_index.0000001", "w+"); + if (NULL == fp) { + log_error(g_logger, "open file %s failed", "full_config_index.0000001"); + return; + } + fprintf(fp, "FLAG_5K 5000 ./FLAG_5K\n"); + fprintf(fp, "COMPILE_PERF 10 ./COMPILE_PERF\n"); + fprintf(fp, "GROUP2COMPILE_PERF 10 ./GROUP2COMPILE_PERF\n"); + fclose(fp); + + struct maat_options *opts = maat_options_new(); + maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO); + maat_options_set_iris(opts, "./", "./"); + maat_options_set_rule_effect_interval_ms(opts, 1000); + maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM); + _shared_maat_inst = maat_new(opts, table_info_path); + maat_options_free(opts); + } + + static void TearDownTestCase() { + maat_free(_shared_maat_inst); + log_handle_destroy(logger); + } + + static struct log_handle *logger; + static struct maat *_shared_maat_inst; +}; + +struct maat *Flag5KBenchmarkGTest::_shared_maat_inst; +struct log_handle *Flag5KBenchmarkGTest::logger; + +TEST_F(Flag5KBenchmarkGTest, FlagScan) { + const char *table_name = "FLAG_5K"; + struct maat *maat_inst = Flag5KBenchmarkGTest::_shared_maat_inst; + + int table_id = maat_get_table_id(maat_inst, table_name); + ASSERT_GT(table_id, 0); + + pthread_t threads[PERF_THREAD_NUM + 1]; + struct thread_param thread_params[PERF_THREAD_NUM + 1]; + int i = 0; + int *is_all_hit = NULL; + + for (i = 0; i < PERF_THREAD_NUM + 1; i++) { + thread_params[i].maat_inst = maat_inst; + thread_params[i].thread_id = i; + thread_params[i].table_name = table_name; + thread_params[i].test_count = MAX_SCAN_COUNT; + thread_params[i].rule_count = 5000; + thread_params[i].time_elapse_ms = 0; + thread_params[i].logger = logger; + + if (i < PERF_THREAD_NUM) { + pthread_create(&threads[i], NULL, perf_flag_scan_thread, thread_params+i); + } else { + thread_params[i].test_count = 0; + pthread_create(&threads[i], NULL, perf_flag_update_thread, thread_params+i); + } + } + + long long time_elapse_ms = 0; + long long scan_count = 0; + long long scan_per_second = 0; + for (i = 0; i < PERF_THREAD_NUM + 1; i++) { + pthread_join(threads[i], (void **)&is_all_hit); + time_elapse_ms += thread_params[i].time_elapse_ms; + scan_count += thread_params[i].test_count; + + EXPECT_EQ(*is_all_hit, 1); + *is_all_hit = 0; + free(is_all_hit); + } + scan_per_second = scan_count * 1000 / time_elapse_ms; + + log_info(maat_inst->logger, MODULE_BENCHMARK_GTEST, + "Flag5KScan match rate on %d-threads speed %lld lookups/s/thread", + PERF_THREAD_NUM, scan_per_second); +} + +class Flag10KBenchmarkGTest : public ::testing::Test +{ +protected: + static void SetUpTestCase() { + logger = log_handle_create("./benchmark_hs_gtest.log", 0); + generate_flag_sample("FLAG_10K", 10000); + + FILE *fp = fopen("full_config_index.0000001", "w+"); + if (NULL == fp) { + log_error(g_logger, "open file %s failed", "full_config_index.0000001"); + return; + } + fprintf(fp, "FLAG_10K 10000 ./FLAG_10K\n"); + fprintf(fp, "COMPILE_PERF 10 ./COMPILE_PERF\n"); + fprintf(fp, "GROUP2COMPILE_PERF 10 ./GROUP2COMPILE_PERF\n"); + fclose(fp); + + struct maat_options *opts = maat_options_new(); + maat_options_set_logger(opts, "./benchmark_hs_gtest.log", LOG_LEVEL_INFO); + maat_options_set_iris(opts, "./", "./"); + maat_options_set_rule_effect_interval_ms(opts, 1000); + maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM); + _shared_maat_inst = maat_new(opts, table_info_path); + maat_options_free(opts); + } + + static void TearDownTestCase() { + maat_free(_shared_maat_inst); + log_handle_destroy(logger); + } + + static struct log_handle *logger; + static struct maat *_shared_maat_inst; +}; + +struct maat *Flag10KBenchmarkGTest::_shared_maat_inst; +struct log_handle *Flag10KBenchmarkGTest::logger; + +TEST_F(Flag10KBenchmarkGTest, FlagScan) { + const char *table_name = "FLAG_10K"; + struct maat *maat_inst = Flag10KBenchmarkGTest::_shared_maat_inst; + + int table_id = maat_get_table_id(maat_inst, table_name); + ASSERT_GT(table_id, 0); + + pthread_t threads[PERF_THREAD_NUM + 1]; + struct thread_param thread_params[PERF_THREAD_NUM + 1]; + int i = 0; + int *is_all_hit = NULL; + + for (i = 0; i < PERF_THREAD_NUM + 1; i++) { + thread_params[i].maat_inst = maat_inst; + thread_params[i].thread_id = i; + thread_params[i].table_name = table_name; + thread_params[i].test_count = MAX_SCAN_COUNT; + thread_params[i].rule_count = 10000; + thread_params[i].time_elapse_ms = 0; + thread_params[i].logger = logger; + + if (i < PERF_THREAD_NUM) { + pthread_create(&threads[i], NULL, perf_flag_scan_thread, thread_params+i); + } else { + thread_params[i].test_count = 0; + pthread_create(&threads[i], NULL, perf_flag_update_thread, thread_params+i); + } + } + + long long time_elapse_ms = 0; + long long scan_count = 0; + long long scan_per_second = 0; + for (i = 0; i < PERF_THREAD_NUM + 1; i++) { + pthread_join(threads[i], (void **)&is_all_hit); + time_elapse_ms += thread_params[i].time_elapse_ms; + scan_count += thread_params[i].test_count; + + EXPECT_EQ(*is_all_hit, 1); + *is_all_hit = 0; + free(is_all_hit); + } + scan_per_second = scan_count * 1000 / time_elapse_ms; + + log_info(maat_inst->logger, MODULE_BENCHMARK_GTEST, + "Flag10KScan match rate on %d-threads speed %lld lookups/s/thread", + PERF_THREAD_NUM, scan_per_second); +} + +int main(int argc, char ** argv) +{ + int ret=0; + ::testing::InitGoogleTest(&argc, argv); + g_logger = log_handle_create("./benchmark_hs_gtest.log", 0); + + generate_compile_sample("COMPILE_PERF", 10); + generate_group2compile_sample("GROUP2COMPILE_PERF", 10); + + ret=RUN_ALL_TESTS(); + + log_handle_destroy(g_logger); + return ret; +} diff --git a/test/benchmark/benchmark_rs_gtest.cpp b/test/benchmark/benchmark_rs_gtest.cpp new file mode 100644 index 0000000..8f5e3c7 --- /dev/null +++ b/test/benchmark/benchmark_rs_gtest.cpp @@ -0,0 +1,3153 @@ +#include "maat.h" +#include "log/log.h" +#include "maat_utils.h" +#include "maat_rule.h" +#include "json2iris.h" +#include "ip_matcher.h" +#include "maat_table.h" +#include "maat_config_monitor.h" + +#include + +#define MODULE_BENCHMARK_GTEST module_name_str("maat.benchmark_gtest") + +#define MAX_EXPR_RULE_NUM 2000000 +#define MID_EXPR_RULE_NUM 1000000 + +#define MAX_IP_RULE_NUM 8000000 +#define MID_IP_RULE_NUM 4000000 + +#define MAX_INTEGER_RULE_NUM 10000 +#define MID_INTEGER_RULE_NUM 5000 + +#define MAX_FLAG_RULE_NUM 10000 +#define MID_FLAG_RULE_NUM 5000 + +#define ARRAY_SIZE 10 +#define PERF_THREAD_NUM 5 +#define MAX_SCAN_COUNT 1000000 + +const char *table_info_path = "./benchmark_table_info.conf"; +struct log_handle *g_logger = NULL; + +struct thread_param { + int thread_id; + int test_count; + int rule_count; + struct maat *maat_inst; + const char *table_name; + long long time_elapse_ms; + struct log_handle *logger; +}; + +static void random_keyword_generate(char *keyword_buf, size_t sz) +{ +#define MIN_KEYWORD_LEN 4 + size_t i = 0, len = 0; + len = random() % (sz - 1 - MIN_KEYWORD_LEN) + MIN_KEYWORD_LEN; + + for (i = 0; i < len; i++) { + keyword_buf[i] = 'a' + random() % ('z' - 'a'); + } + keyword_buf[i] = '\0'; +} + +void generate_expr_sample(const char *table_name, int sample_count) +{ + FILE *fp = fopen(table_name, "w+"); + if (NULL == fp) { + log_error(g_logger, "open file %s failed", table_name); + return; + } + + fprintf(fp, "%d\n", sample_count); + fprintf(fp, "1\t1\t%s\t1\t0\t0\t1\n", "the souls of the departed"); + + for (int i = 2; i <= sample_count; i++) { + char keyword_buf[64] = {0}; + random_keyword_generate(keyword_buf, sizeof(keyword_buf)); + fprintf(fp, "%d\t%d\t%s\t1\t0\t0\t1\n", i, i, keyword_buf); + } + + fclose(fp); +} + +void generate_ip_sample(const char *table_name, int sample_count) +{ + FILE *fp = fopen(table_name, "w+"); + if (NULL == fp) { + log_error(g_logger, "open file %s failed", table_name); + return; + } + + fprintf(fp, "%d\n", sample_count); + fprintf(fp, "1\t1\t4\t%s\t%s\t%s\t%s\t%d\t%d\t-1\t1\n", "range", + "100.64.1.1", "100.64.1.1", "range", 20000, 20000); + + for (int i = 2; i <= sample_count-1; i++) { + char ip_buf[64] = {0}; + sprintf(ip_buf, "%d.%d.%d.%d", (int)(random() % 256), (int)(random() % 256), + (int)(random() % 256), (int)(random() % 256)); + fprintf(fp, "%d\t%d\t4\t%s\t%s\t%s\t%s\t%d\t%d\t-1\t1\n", + i+1, i+1, "range", ip_buf, ip_buf, "range", 20000, 20000); + } + + fclose(fp); +} + +void generate_integer_sample(const char *table_name, int sample_count) +{ + FILE *fp = fopen(table_name, "w+"); + if (NULL == fp) { + log_error(g_logger, "open file %s failed", table_name); + return; + } + + fprintf(fp, "%d\n", sample_count); + fprintf(fp, "1\t1\t%d\t%d\t1\n", 1000000, 1000000); + + for (int i = 2; i <= sample_count-1; i++) { + fprintf(fp, "%d\t%d\t%d\t%d\t1\n", i+1, i+1, i+1, i+1); + } + + fclose(fp); +} + +void generate_flag_sample(const char *table_name, int sample_count) +{ + FILE *fp = fopen(table_name, "w+"); + if (NULL == fp) { + log_error(g_logger, "open file %s failed", table_name); + return; + } + + fprintf(fp, "%d\n", sample_count); + fprintf(fp, "1\t1\t%d\t%d\t1\n", 1000000, 1111111); + + for (int i = 2; i <= sample_count-1; i++) { + fprintf(fp, "%d\t%d\t%d\t%d\t1\n", i+1, i+1, i+1, i+1); + } + + fclose(fp); +} + +void generate_compile_sample(const char *table_name, int sample_count) +{ + FILE *fp = fopen(table_name, "w+"); + if (NULL == fp) { + log_error(g_logger, "open file %s failed", table_name); + return; + } + + fprintf(fp, "%d\n", sample_count); + + for (int i = 0; i < sample_count; i++) { + fprintf(fp, "%d\t1\t1\t1\t1\t0\t%s\t1\t1\n", 100+i, "null"); + } + + fclose(fp); +} + +void generate_group2compile_sample(const char *table_name, int sample_count) +{ + FILE *fp = fopen(table_name, "w+"); + if (NULL == fp) { + log_error(g_logger, "open file %s failed", table_name); + return; + } + + fprintf(fp, "%d\n", sample_count); + + for (int i = 0; i < sample_count; i++) { + fprintf(fp, "%d\t%d\t1\t0\t%s\t1\n", i+1, 100+i, "null"); + } + + fclose(fp); +} + +void *perf_literal_scan_thread(void *arg) +{ + struct thread_param *param = (struct thread_param *)arg; + struct maat *maat_inst = param->maat_inst; + const char *table_name = param->table_name; + struct timespec start, end; + const char *scan_data = "Maat was the goddness of harmony, justice, and truth in ancient Egyptian." + " Her feather was the measure that determined whether the souls of the departed " + "would reach the paradise of the afterlife successfully"; + long long results[ARRAY_SIZE] = {0}; + int hit_times = 0; + size_t n_hit_result = 0; + struct maat_state *state = maat_state_new(maat_inst, param->thread_id); + + int table_id = maat_get_table_id(maat_inst, table_name); + + clock_gettime(CLOCK_MONOTONIC, &start); + for (int i = 0; i < param->test_count; i++) { + int ret = maat_scan_string(maat_inst, table_id, scan_data, strlen(scan_data), + results, ARRAY_SIZE, &n_hit_result, state); + if (ret == MAAT_SCAN_HIT) { + hit_times++; + } + maat_state_reset(state); + } + clock_gettime(CLOCK_MONOTONIC, &end); + + param->time_elapse_ms = (end.tv_sec - start.tv_sec) * 1000 + + (end.tv_nsec - start.tv_nsec) / 1000000; + int *is_all_hit = ALLOC(int, 1); + *is_all_hit = (hit_times == param->test_count ? 1 : 0); + log_info(param->logger, MODULE_BENCHMARK_GTEST, + "thread_id:%d rule_count:%d literal_scan time_elapse:%lldms hit_times:%d", + param->thread_id, param->rule_count, param->time_elapse_ms, hit_times); + + return is_all_hit; +} + +void *perf_literal_update_thread(void *arg) +{ + struct thread_param *param = (struct thread_param *)arg; + const char *table_name = param->table_name; + const int CMD_EXPR_NUM = 10; + char keyword_buf[128]; + + for (int i = 0; i < CMD_EXPR_NUM; i++) { + random_keyword_generate(keyword_buf, sizeof(keyword_buf)); + FILE *fp = fopen(table_name, "a+"); + if (NULL == fp) { + continue; + } + + fprintf(fp, "%d\t%d\t%s\t1\t0\t0\t1\n", 2000001+i, 2000001+i, keyword_buf); + fclose(fp); + + sleep(1); + } + + int *is_all_hit = ALLOC(int, 1); + *is_all_hit = 1; + + return is_all_hit; +} + +void *perf_stream_scan_thread(void *arg) +{ + struct thread_param *param = (struct thread_param *)arg; + struct maat *maat_inst = param->maat_inst; + const char *table_name = param->table_name; + struct timespec start, end; + const char *scan_data = "Maat was the goddness of harmony, justice, and truth in ancient Egyptian." + " Her feather was the measure that determined whether the souls of the departed " + "would reach the paradise of the afterlife successfully"; + long long results[ARRAY_SIZE] = {0}; + int ret = 0, hit_times = 0; + size_t n_hit_result = 0; + + int table_id = maat_get_table_id(maat_inst, table_name); + struct maat_state *state = maat_state_new(maat_inst, param->thread_id); + struct maat_stream *sp = maat_stream_new(maat_inst, table_id, state); + + clock_gettime(CLOCK_MONOTONIC, &start); + for (int i = 0; i < param->test_count; i++) { + ret = maat_stream_scan(sp, scan_data, strlen(scan_data), results, ARRAY_SIZE, + &n_hit_result, state); + if (ret == MAAT_SCAN_HIT) { + hit_times++; + } + maat_state_reset(state); + } + clock_gettime(CLOCK_MONOTONIC, &end); + maat_stream_free(sp); + maat_state_free(state); + + param->time_elapse_ms = (end.tv_sec - start.tv_sec) * 1000 + + (end.tv_nsec - start.tv_nsec) / 1000000; + int *is_all_hit = ALLOC(int, 1); + *is_all_hit = ((hit_times == param->test_count) ? 1 : 0); + + log_info(param->logger, MODULE_BENCHMARK_GTEST, + "thread_id:%d rule_count:%d stream_scan time_elapse:%lldms hit_times:%d", + param->thread_id, param->rule_count, param->time_elapse_ms, hit_times); + return is_all_hit; +} + +void *perf_ip_scan_thread(void *arg) +{ + struct thread_param *param = (struct thread_param *)arg; + struct maat *maat_inst = param->maat_inst; + const char *table_name = param->table_name; + struct timespec start, end; + long long results[ARRAY_SIZE] = {0}; + int hit_times = 0; + size_t n_hit_result = 0; + struct maat_state *state = maat_state_new(maat_inst, param->thread_id); + + int table_id = maat_get_table_id(maat_inst, table_name); + EXPECT_GT(table_id, 0); + + uint32_t ip_addr; + inet_pton(AF_INET, "100.64.1.1", &ip_addr); + uint16_t port = htons(20000); + int proto = 6; + + clock_gettime(CLOCK_MONOTONIC, &start); + for (int i = 0; i < param->test_count; i++) { + int ret = maat_scan_ipv4(maat_inst, table_id, ip_addr, port, proto, + results, ARRAY_SIZE, &n_hit_result, state); + if (ret == MAAT_SCAN_HIT) { + hit_times++; + } + maat_state_reset(state); + } + clock_gettime(CLOCK_MONOTONIC, &end); + + param->time_elapse_ms = (end.tv_sec - start.tv_sec) * 1000 + + (end.tv_nsec - start.tv_nsec) / 1000000; + int *is_all_hit = ALLOC(int, 1); + *is_all_hit = (hit_times == param->test_count ? 1 : 0); + log_info(param->logger, MODULE_BENCHMARK_GTEST, + "thread_id:%d rule_count:%d ip_scan time_elapse:%lldms hit_times:%d", + param->thread_id, param->rule_count, param->time_elapse_ms, hit_times); + + return is_all_hit; +} + +void *perf_ip_update_thread(void *arg) +{ + struct thread_param *param = (struct thread_param *)arg; + const char *table_name = param->table_name; + const int CMD_EXPR_NUM = 10; + + for (int i = 0; i < CMD_EXPR_NUM; i++) { + FILE *fp = fopen(table_name, "a+"); + if (NULL == fp) { + continue; + } + + char ip_buf[64] = {0}; + sprintf(ip_buf, "%d.%d.%d.%d", (int)(random() % 256), (int)(random() % 256), + (int)(random() % 256), (int)(random() % 256)); + fprintf(fp, "%d\t%d\t4\t%s\t%s\t%s\t%s\t%d\t%d\t-1\t1\n", + 8000001+i, 8000001+i, "range", ip_buf, ip_buf, "range", 20000, 20000); + fclose(fp); + + sleep(1); + } + + int *is_all_hit = ALLOC(int, 1); + *is_all_hit = 1; + + return is_all_hit; +} + +void *perf_integer_scan_thread(void *arg) +{ + struct thread_param *param = (struct thread_param *)arg; + struct maat *maat_inst = param->maat_inst; + const char *table_name = param->table_name; + struct timespec start, end; + long long results[ARRAY_SIZE] = {0}; + int hit_times = 0; + size_t n_hit_result = 0; + struct maat_state *state = maat_state_new(maat_inst, param->thread_id); + + int table_id = maat_get_table_id(maat_inst, table_name); + EXPECT_GT(table_id, 0); + + long long scan_data = 1000000; + + clock_gettime(CLOCK_MONOTONIC, &start); + for (int i = 0; i < param->test_count; i++) { + int ret = maat_scan_integer(maat_inst, table_id, scan_data, results, + ARRAY_SIZE, &n_hit_result, state); + if (ret == MAAT_SCAN_HIT) { + hit_times++; + } + maat_state_reset(state); + } + clock_gettime(CLOCK_MONOTONIC, &end); + + param->time_elapse_ms = (end.tv_sec - start.tv_sec) * 1000 + + (end.tv_nsec - start.tv_nsec) / 1000000; + int *is_all_hit = ALLOC(int, 1); + *is_all_hit = (hit_times == param->test_count ? 1 : 0); + log_info(param->logger, MODULE_BENCHMARK_GTEST, + "thread_id:%d rule_count:%d integer_scan time_elapse:%lldms hit_times:%d", + param->thread_id, param->rule_count, param->time_elapse_ms, hit_times); + + return is_all_hit; +} + +void *perf_integer_update_thread(void *arg) +{ + struct thread_param *param = (struct thread_param *)arg; + const char *table_name = param->table_name; + const int CMD_EXPR_NUM = 10; + + for (int i = 0; i < CMD_EXPR_NUM; i++) { + FILE *fp = fopen(table_name, "a+"); + if (NULL == fp) { + continue; + } + + fprintf(fp, "%d\t%d\t%d\t%d\t1\n", 10001+i, 10001+i, 10001+i, 10001+i); + fclose(fp); + + sleep(1); + } + + int *is_all_hit = ALLOC(int, 1); + *is_all_hit = 1; + + return is_all_hit; +} + +void *perf_flag_scan_thread(void *arg) +{ + struct thread_param *param = (struct thread_param *)arg; + struct maat *maat_inst = param->maat_inst; + const char *table_name = param->table_name; + struct timespec start, end; + long long results[ARRAY_SIZE] = {0}; + int hit_times = 0; + size_t n_hit_result = 0; + struct maat_state *state = maat_state_new(maat_inst, param->thread_id); + + int table_id = maat_get_table_id(maat_inst, table_name); + EXPECT_GT(table_id, 0); + + long long scan_data = 1000000; + + clock_gettime(CLOCK_MONOTONIC, &start); + for (int i = 0; i < param->test_count; i++) { + int ret = maat_scan_flag(maat_inst, table_id, scan_data, results, + ARRAY_SIZE, &n_hit_result, state); + if (ret == MAAT_SCAN_HIT) { + hit_times++; + } + maat_state_reset(state); + } + clock_gettime(CLOCK_MONOTONIC, &end); + + param->time_elapse_ms = (end.tv_sec - start.tv_sec) * 1000 + + (end.tv_nsec - start.tv_nsec) / 1000000; + int *is_all_hit = ALLOC(int, 1); + *is_all_hit = (hit_times == param->test_count ? 1 : 0); + log_info(param->logger, MODULE_BENCHMARK_GTEST, + "thread_id:%d rule_count:%d flag_scan time_elapse:%lldms hit_times:%d", + param->thread_id, param->rule_count, param->time_elapse_ms, hit_times); + + return is_all_hit; +} + +void *perf_flag_update_thread(void *arg) +{ + struct thread_param *param = (struct thread_param *)arg; + const char *table_name = param->table_name; + const int CMD_EXPR_NUM = 10; + + for (int i = 0; i < CMD_EXPR_NUM; i++) { + FILE *fp = fopen(table_name, "a+"); + if (NULL == fp) { + continue; + } + + fprintf(fp, "%d\t%d\t%d\t%d\t1\n", 10001+i, 10001+i, 10001+i, 10001+i); + fclose(fp); + + sleep(1); + } + + int *is_all_hit = ALLOC(int, 1); + *is_all_hit = 1; + + return is_all_hit; +} + +class Expr1KBenchmarkGTest : public ::testing::Test +{ +protected: + static void SetUpTestCase() { + logger = log_handle_create("./benchmark_rs_gtest.log", 0); + ///printf("Start to generate test sample......\n"); + generate_expr_sample("EXPR_LITERAL_1K", 1000); + + FILE *fp = fopen("full_config_index.0000001", "w+"); + if (NULL == fp) { + log_error(g_logger, "open file %s failed", "full_config_index.0000001"); + return; + } + fprintf(fp, "EXPR_LITERAL_1K 1000 ./EXPR_LITERAL_1K\n"); + fprintf(fp, "COMPILE_PERF 10 ./COMPILE_PERF\n"); + fprintf(fp, "GROUP2COMPILE_PERF 10 ./GROUP2COMPILE_PERF\n"); + fclose(fp); + + struct maat_options *opts = maat_options_new(); + maat_options_set_logger(opts, "./benchmark_rs_gtest.log", LOG_LEVEL_INFO); + maat_options_set_iris(opts, "./", "./"); + maat_options_set_rule_effect_interval_ms(opts, 1000); + maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM); + maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_RS); + _shared_maat_inst = maat_new(opts, table_info_path); + maat_options_free(opts); + } + + static void TearDownTestCase() { + maat_free(_shared_maat_inst); + log_handle_destroy(logger); + } + + static struct log_handle *logger; + static struct maat *_shared_maat_inst; +}; + +struct maat *Expr1KBenchmarkGTest::_shared_maat_inst; +struct log_handle *Expr1KBenchmarkGTest::logger; + +TEST_F(Expr1KBenchmarkGTest, LiteralScan) { + const char *table_name = "EXPR_LITERAL_1K"; + struct maat *maat_inst = Expr1KBenchmarkGTest::_shared_maat_inst; + + int table_id = maat_get_table_id(maat_inst, table_name); + ASSERT_GT(table_id, 0); + + pthread_t threads[PERF_THREAD_NUM + 1]; + struct thread_param thread_params[PERF_THREAD_NUM + 1]; + int i = 0; + int *is_all_hit = NULL; + + for (i = 0; i < PERF_THREAD_NUM + 1; i++) { + thread_params[i].maat_inst = maat_inst; + thread_params[i].thread_id = i; + thread_params[i].table_name = table_name; + thread_params[i].test_count = MAX_SCAN_COUNT; + thread_params[i].rule_count = 1000; + thread_params[i].time_elapse_ms = 0; + thread_params[i].logger = logger; + + if (i < PERF_THREAD_NUM) { + pthread_create(&threads[i], NULL, perf_literal_scan_thread, thread_params+i); + } else { + thread_params[i].test_count = 0; + pthread_create(&threads[i], NULL, perf_literal_update_thread, thread_params+i); + } + } + + long long time_elapse_ms = 0; + long long scan_count = 0; + long long scan_per_second = 0; + for (i = 0; i < PERF_THREAD_NUM + 1; i++) { + pthread_join(threads[i], (void **)&is_all_hit); + time_elapse_ms += thread_params[i].time_elapse_ms; + scan_count += thread_params[i].test_count; + + EXPECT_EQ(*is_all_hit, 1); + *is_all_hit = 0; + free(is_all_hit); + } + scan_per_second = scan_count * 1000 / time_elapse_ms; + + log_info(maat_inst->logger, MODULE_BENCHMARK_GTEST, + "Expr1KLiteralScan match rate on %d-threads speed %lld lookups/s/thread", + PERF_THREAD_NUM, scan_per_second); +} + +class Expr5KBenchmarkGTest : public ::testing::Test +{ +protected: + static void SetUpTestCase() { + logger = log_handle_create("./benchmark_rs_gtest.log", 0); + generate_expr_sample("EXPR_LITERAL_5K", 5000); + + FILE *fp = fopen("full_config_index.0000001", "w+"); + if (NULL == fp) { + log_error(g_logger, "open file %s failed", "full_config_index.0000001"); + return; + } + fprintf(fp, "EXPR_LITERAL_5K 5000 ./EXPR_LITERAL_5K\n"); + fprintf(fp, "COMPILE_PERF 10 ./COMPILE_PERF\n"); + fprintf(fp, "GROUP2COMPILE_PERF 10 ./GROUP2COMPILE_PERF\n"); + fclose(fp); + + struct maat_options *opts = maat_options_new(); + maat_options_set_logger(opts, "./benchmark_rs_gtest.log", LOG_LEVEL_INFO); + maat_options_set_iris(opts, "./", "./"); + maat_options_set_rule_effect_interval_ms(opts, 1000); + maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM); + maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_RS); + _shared_maat_inst = maat_new(opts, table_info_path); + maat_options_free(opts); + } + + static void TearDownTestCase() { + maat_free(_shared_maat_inst); + log_handle_destroy(logger); + } + + static struct log_handle *logger; + static struct maat *_shared_maat_inst; +}; + +struct maat *Expr5KBenchmarkGTest::_shared_maat_inst; +struct log_handle *Expr5KBenchmarkGTest::logger; + +TEST_F(Expr5KBenchmarkGTest, LiteralScan) { + const char *table_name = "EXPR_LITERAL_5K"; + struct maat *maat_inst = Expr5KBenchmarkGTest::_shared_maat_inst; + + int table_id = maat_get_table_id(maat_inst, table_name); + ASSERT_GT(table_id, 0); + + pthread_t threads[PERF_THREAD_NUM + 1]; + struct thread_param thread_params[PERF_THREAD_NUM + 1]; + int i = 0; + int *is_all_hit = NULL; + + for (i = 0; i < PERF_THREAD_NUM + 1; i++) { + thread_params[i].maat_inst = maat_inst; + thread_params[i].thread_id = i; + thread_params[i].table_name = table_name; + thread_params[i].test_count = MAX_SCAN_COUNT; + thread_params[i].rule_count = 5000; + thread_params[i].time_elapse_ms = 0; + thread_params[i].logger = logger; + + if (i < PERF_THREAD_NUM) { + pthread_create(&threads[i], NULL, perf_literal_scan_thread, thread_params+i); + } else { + thread_params[i].test_count = 0; + pthread_create(&threads[i], NULL, perf_literal_update_thread, thread_params+i); + } + } + + long long time_elapse_ms = 0; + long long scan_count = 0; + long long scan_per_second = 0; + for (i = 0; i < PERF_THREAD_NUM + 1; i++) { + pthread_join(threads[i], (void **)&is_all_hit); + time_elapse_ms += thread_params[i].time_elapse_ms; + scan_count += thread_params[i].test_count; + + EXPECT_EQ(*is_all_hit, 1); + *is_all_hit = 0; + free(is_all_hit); + } + scan_per_second = scan_count * 1000 / time_elapse_ms; + + log_info(maat_inst->logger, MODULE_BENCHMARK_GTEST, + "Expr5KLiteralScan match rate on %d-threads speed %lld lookups/s/thread", + PERF_THREAD_NUM, scan_per_second); +} + +class Expr10KBenchmarkGTest : public ::testing::Test +{ +protected: + static void SetUpTestCase() { + logger = log_handle_create("./benchmark_rs_gtest.log", 0); + generate_expr_sample("EXPR_LITERAL_10K", 10000); + + FILE *fp = fopen("full_config_index.0000001", "w+"); + if (NULL == fp) { + log_error(g_logger, "open file %s failed", "full_config_index.0000001"); + return; + } + fprintf(fp, "EXPR_LITERAL_10K 10000 ./EXPR_LITERAL_10K\n"); + fprintf(fp, "COMPILE_PERF 10 ./COMPILE_PERF\n"); + fprintf(fp, "GROUP2COMPILE_PERF 10 ./GROUP2COMPILE_PERF\n"); + fclose(fp); + + struct maat_options *opts = maat_options_new(); + maat_options_set_logger(opts, "./benchmark_rs_gtest.log", LOG_LEVEL_INFO); + maat_options_set_iris(opts, "./", "./"); + maat_options_set_rule_effect_interval_ms(opts, 1000); + maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM); + maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_RS); + _shared_maat_inst = maat_new(opts, table_info_path); + maat_options_free(opts); + } + + static void TearDownTestCase() { + maat_free(_shared_maat_inst); + log_handle_destroy(logger); + } + + static struct log_handle *logger; + static struct maat *_shared_maat_inst; +}; + +struct maat *Expr10KBenchmarkGTest::_shared_maat_inst; +struct log_handle *Expr10KBenchmarkGTest::logger; + +TEST_F(Expr10KBenchmarkGTest, LiteralScan) { + const char *table_name = "EXPR_LITERAL_10K"; + struct maat *maat_inst = Expr10KBenchmarkGTest::_shared_maat_inst; + + int table_id = maat_get_table_id(maat_inst, table_name); + ASSERT_GT(table_id, 0); + + pthread_t threads[PERF_THREAD_NUM + 1]; + struct thread_param thread_params[PERF_THREAD_NUM + 1]; + int i = 0; + int *is_all_hit = NULL; + + for (i = 0; i < PERF_THREAD_NUM + 1; i++) { + thread_params[i].maat_inst = maat_inst; + thread_params[i].thread_id = i; + thread_params[i].table_name = table_name; + thread_params[i].test_count = MAX_SCAN_COUNT; + thread_params[i].rule_count = 10000; + thread_params[i].time_elapse_ms = 0; + thread_params[i].logger = logger; + + if (i < PERF_THREAD_NUM) { + pthread_create(&threads[i], NULL, perf_literal_scan_thread, thread_params+i); + } else { + thread_params[i].test_count = 0; + pthread_create(&threads[i], NULL, perf_literal_update_thread, thread_params+i); + } + } + + long long time_elapse_ms = 0; + long long scan_count = 0; + long long scan_per_second = 0; + for (i = 0; i < PERF_THREAD_NUM + 1; i++) { + pthread_join(threads[i], (void **)&is_all_hit); + time_elapse_ms += thread_params[i].time_elapse_ms; + scan_count += thread_params[i].test_count; + + EXPECT_EQ(*is_all_hit, 1); + *is_all_hit = 0; + free(is_all_hit); + } + scan_per_second = scan_count * 1000 / time_elapse_ms; + + log_info(maat_inst->logger, MODULE_BENCHMARK_GTEST, + "Expr10KLiteralScan match rate on %d-threads speed %lld lookups/s/thread", + PERF_THREAD_NUM, scan_per_second); +} + +class Expr50KBenchmarkGTest : public ::testing::Test +{ +protected: + static void SetUpTestCase() { + logger = log_handle_create("./benchmark_rs_gtest.log", 0); + generate_expr_sample("EXPR_LITERAL_50K", 50000); + + FILE *fp = fopen("full_config_index.0000001", "w+"); + if (NULL == fp) { + log_error(g_logger, "open file %s failed", "full_config_index.0000001"); + return; + } + fprintf(fp, "EXPR_LITERAL_50K 50000 ./EXPR_LITERAL_50K\n"); + fprintf(fp, "COMPILE_PERF 10 ./COMPILE_PERF\n"); + fprintf(fp, "GROUP2COMPILE_PERF 10 ./GROUP2COMPILE_PERF\n"); + fclose(fp); + + struct maat_options *opts = maat_options_new(); + maat_options_set_logger(opts, "./benchmark_rs_gtest.log", LOG_LEVEL_INFO); + maat_options_set_iris(opts, "./", "./"); + maat_options_set_rule_effect_interval_ms(opts, 1000); + maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM); + maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_RS); + _shared_maat_inst = maat_new(opts, table_info_path); + maat_options_free(opts); + } + + static void TearDownTestCase() { + maat_free(_shared_maat_inst); + log_handle_destroy(logger); + } + + static struct log_handle *logger; + static struct maat *_shared_maat_inst; +}; + +struct maat *Expr50KBenchmarkGTest::_shared_maat_inst; +struct log_handle *Expr50KBenchmarkGTest::logger; + +TEST_F(Expr50KBenchmarkGTest, LiteralScan) { + const char *table_name = "EXPR_LITERAL_50K"; + struct maat *maat_inst = Expr50KBenchmarkGTest::_shared_maat_inst; + + int table_id = maat_get_table_id(maat_inst, table_name); + ASSERT_GT(table_id, 0); + + pthread_t threads[PERF_THREAD_NUM + 1]; + struct thread_param thread_params[PERF_THREAD_NUM + 1]; + int i = 0; + int *is_all_hit = NULL; + + for (i = 0; i < PERF_THREAD_NUM + 1; i++) { + thread_params[i].maat_inst = maat_inst; + thread_params[i].thread_id = i; + thread_params[i].table_name = table_name; + thread_params[i].test_count = MAX_SCAN_COUNT; + thread_params[i].rule_count = 50000; + thread_params[i].time_elapse_ms = 0; + thread_params[i].logger = logger; + + if (i < PERF_THREAD_NUM) { + pthread_create(&threads[i], NULL, perf_literal_scan_thread, thread_params+i); + } else { + thread_params[i].test_count = 0; + pthread_create(&threads[i], NULL, perf_literal_update_thread, thread_params+i); + } + } + + long long time_elapse_ms = 0; + long long scan_count = 0; + long long scan_per_second = 0; + for (i = 0; i < PERF_THREAD_NUM + 1; i++) { + pthread_join(threads[i], (void **)&is_all_hit); + time_elapse_ms += thread_params[i].time_elapse_ms; + scan_count += thread_params[i].test_count; + + EXPECT_EQ(*is_all_hit, 1); + *is_all_hit = 0; + free(is_all_hit); + } + scan_per_second = scan_count * 1000 / time_elapse_ms; + + log_info(maat_inst->logger, MODULE_BENCHMARK_GTEST, + "Expr50KLiteralScan match rate on %d-threads speed %lld lookups/s/thread", + PERF_THREAD_NUM, scan_per_second); +} + +class Expr100KBenchmarkGTest : public ::testing::Test +{ +protected: + static void SetUpTestCase() { + logger = log_handle_create("./benchmark_rs_gtest.log", 0); + generate_expr_sample("EXPR_LITERAL_100K", 100000); + + FILE *fp = fopen("full_config_index.0000001", "w+"); + if (NULL == fp) { + log_error(g_logger, "open file %s failed", "full_config_index.0000001"); + return; + } + fprintf(fp, "EXPR_LITERAL_100K 100000 ./EXPR_LITERAL_100K\n"); + fprintf(fp, "COMPILE_PERF 10 ./COMPILE_PERF\n"); + fprintf(fp, "GROUP2COMPILE_PERF 10 ./GROUP2COMPILE_PERF\n"); + fclose(fp); + + struct maat_options *opts = maat_options_new(); + maat_options_set_logger(opts, "./benchmark_rs_gtest.log", LOG_LEVEL_INFO); + maat_options_set_iris(opts, "./", "./"); + maat_options_set_rule_effect_interval_ms(opts, 1000); + maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM); + maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_RS); + _shared_maat_inst = maat_new(opts, table_info_path); + maat_options_free(opts); + } + + static void TearDownTestCase() { + maat_free(_shared_maat_inst); + log_handle_destroy(logger); + } + + static struct log_handle *logger; + static struct maat *_shared_maat_inst; +}; + +struct maat *Expr100KBenchmarkGTest::_shared_maat_inst; +struct log_handle *Expr100KBenchmarkGTest::logger; + +TEST_F(Expr100KBenchmarkGTest, LiteralScan) { + const char *table_name = "EXPR_LITERAL_100K"; + struct maat *maat_inst = Expr100KBenchmarkGTest::_shared_maat_inst; + + int table_id = maat_get_table_id(maat_inst, table_name); + ASSERT_GT(table_id, 0); + + pthread_t threads[PERF_THREAD_NUM + 1]; + struct thread_param thread_params[PERF_THREAD_NUM + 1]; + int i = 0; + int *is_all_hit = NULL; + + for (i = 0; i < PERF_THREAD_NUM + 1; i++) { + thread_params[i].maat_inst = maat_inst; + thread_params[i].thread_id = i; + thread_params[i].table_name = table_name; + thread_params[i].test_count = MAX_SCAN_COUNT; + thread_params[i].rule_count = 100000; + thread_params[i].time_elapse_ms = 0; + thread_params[i].logger = logger; + + if (i < PERF_THREAD_NUM) { + pthread_create(&threads[i], NULL, perf_literal_scan_thread, thread_params+i); + } else { + thread_params[i].test_count = 0; + pthread_create(&threads[i], NULL, perf_literal_update_thread, thread_params+i); + } + } + + long long time_elapse_ms = 0; + long long scan_count = 0; + long long scan_per_second = 0; + for (i = 0; i < PERF_THREAD_NUM + 1; i++) { + pthread_join(threads[i], (void **)&is_all_hit); + time_elapse_ms += thread_params[i].time_elapse_ms; + scan_count += thread_params[i].test_count; + + EXPECT_EQ(*is_all_hit, 1); + *is_all_hit = 0; + free(is_all_hit); + } + scan_per_second = scan_count * 1000 / time_elapse_ms; + + log_info(maat_inst->logger, MODULE_BENCHMARK_GTEST, + "Expr100KLiteralScan match rate on %d-threads speed %lld lookups/s/thread", + PERF_THREAD_NUM, scan_per_second); +} + +class Expr500KBenchmarkGTest : public ::testing::Test +{ +protected: + static void SetUpTestCase() { + logger = log_handle_create("./benchmark_rs_gtest.log", 0); + generate_expr_sample("EXPR_LITERAL_500K", 500000); + + FILE *fp = fopen("full_config_index.0000001", "w+"); + if (NULL == fp) { + log_error(g_logger, "open file %s failed", "full_config_index.0000001"); + return; + } + fprintf(fp, "EXPR_LITERAL_500K 500000 ./EXPR_LITERAL_500K\n"); + fprintf(fp, "COMPILE_PERF 10 ./COMPILE_PERF\n"); + fprintf(fp, "GROUP2COMPILE_PERF 10 ./GROUP2COMPILE_PERF\n"); + fclose(fp); + + struct maat_options *opts = maat_options_new(); + maat_options_set_logger(opts, "./benchmark_rs_gtest.log", LOG_LEVEL_INFO); + maat_options_set_iris(opts, "./", "./"); + maat_options_set_rule_effect_interval_ms(opts, 1000); + maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM); + maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_RS); + _shared_maat_inst = maat_new(opts, table_info_path); + maat_options_free(opts); + } + + static void TearDownTestCase() { + maat_free(_shared_maat_inst); + log_handle_destroy(logger); + } + + static struct log_handle *logger; + static struct maat *_shared_maat_inst; +}; + +struct maat *Expr500KBenchmarkGTest::_shared_maat_inst; +struct log_handle *Expr500KBenchmarkGTest::logger; + +TEST_F(Expr500KBenchmarkGTest, LiteralScan) { + const char *table_name = "EXPR_LITERAL_500K"; + struct maat *maat_inst = Expr500KBenchmarkGTest::_shared_maat_inst; + + int table_id = maat_get_table_id(maat_inst, table_name); + ASSERT_GT(table_id, 0); + + pthread_t threads[PERF_THREAD_NUM + 1]; + struct thread_param thread_params[PERF_THREAD_NUM + 1]; + int i = 0; + int *is_all_hit = NULL; + + for (i = 0; i < PERF_THREAD_NUM + 1; i++) { + thread_params[i].maat_inst = maat_inst; + thread_params[i].thread_id = i; + thread_params[i].table_name = table_name; + thread_params[i].test_count = MAX_SCAN_COUNT; + thread_params[i].rule_count = 500000; + thread_params[i].time_elapse_ms = 0; + thread_params[i].logger = logger; + + if (i < PERF_THREAD_NUM) { + pthread_create(&threads[i], NULL, perf_literal_scan_thread, thread_params+i); + } else { + thread_params[i].test_count = 0; + pthread_create(&threads[i], NULL, perf_literal_update_thread, thread_params+i); + } + } + + long long time_elapse_ms = 0; + long long scan_count = 0; + long long scan_per_second = 0; + for (i = 0; i < PERF_THREAD_NUM + 1; i++) { + pthread_join(threads[i], (void **)&is_all_hit); + time_elapse_ms += thread_params[i].time_elapse_ms; + scan_count += thread_params[i].test_count; + + EXPECT_EQ(*is_all_hit, 1); + *is_all_hit = 0; + free(is_all_hit); + } + scan_per_second = scan_count * 1000 / time_elapse_ms; + + log_info(maat_inst->logger, MODULE_BENCHMARK_GTEST, + "Expr500KLiteralScan match rate on %d-threads speed %lld lookups/s/thread", + PERF_THREAD_NUM, scan_per_second); +} + +class Expr1MBenchmarkGTest : public ::testing::Test +{ +protected: + static void SetUpTestCase() { + logger = log_handle_create("./benchmark_rs_gtest.log", 0); + generate_expr_sample("EXPR_LITERAL_1M", 1000000); + + FILE *fp = fopen("full_config_index.0000001", "w+"); + if (NULL == fp) { + log_error(g_logger, "open file %s failed", "full_config_index.0000001"); + return; + } + fprintf(fp, "EXPR_LITERAL_1M 1000000 ./EXPR_LITERAL_1M\n"); + fprintf(fp, "COMPILE_PERF 10 ./COMPILE_PERF\n"); + fprintf(fp, "GROUP2COMPILE_PERF 10 ./GROUP2COMPILE_PERF\n"); + fclose(fp); + + struct maat_options *opts = maat_options_new(); + maat_options_set_logger(opts, "./benchmark_rs_gtest.log", LOG_LEVEL_INFO); + maat_options_set_iris(opts, "./", "./"); + maat_options_set_rule_effect_interval_ms(opts, 1000); + maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM); + maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_RS); + _shared_maat_inst = maat_new(opts, table_info_path); + maat_options_free(opts); + } + + static void TearDownTestCase() { + maat_free(_shared_maat_inst); + log_handle_destroy(logger); + } + + static struct log_handle *logger; + static struct maat *_shared_maat_inst; +}; + +struct maat *Expr1MBenchmarkGTest::_shared_maat_inst; +struct log_handle *Expr1MBenchmarkGTest::logger; + +TEST_F(Expr1MBenchmarkGTest, LiteralScan) { + const char *table_name = "EXPR_LITERAL_1M"; + struct maat *maat_inst = Expr1MBenchmarkGTest::_shared_maat_inst; + + int table_id = maat_get_table_id(maat_inst, table_name); + ASSERT_GT(table_id, 0); + + pthread_t threads[PERF_THREAD_NUM + 1]; + struct thread_param thread_params[PERF_THREAD_NUM + 1]; + int i = 0; + int *is_all_hit = NULL; + + for (i = 0; i < PERF_THREAD_NUM + 1; i++) { + thread_params[i].maat_inst = maat_inst; + thread_params[i].thread_id = i; + thread_params[i].table_name = table_name; + thread_params[i].test_count = MAX_SCAN_COUNT; + thread_params[i].rule_count = 1000000; + thread_params[i].time_elapse_ms = 0; + thread_params[i].logger = logger; + + if (i < PERF_THREAD_NUM) { + pthread_create(&threads[i], NULL, perf_literal_scan_thread, thread_params+i); + } else { + thread_params[i].test_count = 0; + pthread_create(&threads[i], NULL, perf_literal_update_thread, thread_params+i); + } + } + + long long time_elapse_ms = 0; + long long scan_count = 0; + long long scan_per_second = 0; + for (i = 0; i < PERF_THREAD_NUM + 1; i++) { + pthread_join(threads[i], (void **)&is_all_hit); + time_elapse_ms += thread_params[i].time_elapse_ms; + scan_count += thread_params[i].test_count; + + EXPECT_EQ(*is_all_hit, 1); + *is_all_hit = 0; + free(is_all_hit); + } + scan_per_second = scan_count * 1000 / time_elapse_ms; + + log_info(maat_inst->logger, MODULE_BENCHMARK_GTEST, + "Expr1MLiteralScan match rate on %d-threads speed %lld lookups/s/thread", + PERF_THREAD_NUM, scan_per_second); +} + +class Expr2MBenchmarkGTest : public ::testing::Test +{ +protected: + static void SetUpTestCase() { + logger = log_handle_create("./benchmark_rs_gtest.log", 0); + generate_expr_sample("EXPR_LITERAL_2M", 2000000); + + FILE *fp = fopen("full_config_index.0000001", "w+"); + if (NULL == fp) { + log_error(g_logger, "open file %s failed", "full_config_index.0000001"); + return; + } + fprintf(fp, "EXPR_LITERAL_2M 2000000 ./EXPR_LITERAL_2M\n"); + fprintf(fp, "COMPILE_PERF 10 ./COMPILE_PERF\n"); + fprintf(fp, "GROUP2COMPILE_PERF 10 ./GROUP2COMPILE_PERF\n"); + fclose(fp); + + struct maat_options *opts = maat_options_new(); + maat_options_set_logger(opts, "./benchmark_rs_gtest.log", LOG_LEVEL_INFO); + maat_options_set_iris(opts, "./", "./"); + maat_options_set_rule_effect_interval_ms(opts, 1000); + maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM); + maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_RS); + _shared_maat_inst = maat_new(opts, table_info_path); + maat_options_free(opts); + } + + static void TearDownTestCase() { + maat_free(_shared_maat_inst); + log_handle_destroy(logger); + } + + static struct log_handle *logger; + static struct maat *_shared_maat_inst; +}; + +struct maat *Expr2MBenchmarkGTest::_shared_maat_inst; +struct log_handle *Expr2MBenchmarkGTest::logger; + +TEST_F(Expr2MBenchmarkGTest, LiteralScan) { + const char *table_name = "EXPR_LITERAL_2M"; + struct maat *maat_inst = Expr2MBenchmarkGTest::_shared_maat_inst; + + int table_id = maat_get_table_id(maat_inst, table_name); + ASSERT_GT(table_id, 0); + + pthread_t threads[PERF_THREAD_NUM + 1]; + struct thread_param thread_params[PERF_THREAD_NUM + 1]; + int i = 0; + int *is_all_hit = NULL; + + for (i = 0; i < PERF_THREAD_NUM + 1; i++) { + thread_params[i].maat_inst = maat_inst; + thread_params[i].thread_id = i; + thread_params[i].table_name = table_name; + thread_params[i].test_count = MAX_SCAN_COUNT; + thread_params[i].rule_count = 2000000; + thread_params[i].time_elapse_ms = 0; + thread_params[i].logger = logger; + + if (i < PERF_THREAD_NUM) { + pthread_create(&threads[i], NULL, perf_literal_scan_thread, thread_params+i); + } else { + thread_params[i].test_count = 0; + pthread_create(&threads[i], NULL, perf_literal_update_thread, thread_params+i); + } + } + + long long time_elapse_ms = 0; + long long scan_count = 0; + long long scan_per_second = 0; + for (i = 0; i < PERF_THREAD_NUM + 1; i++) { + pthread_join(threads[i], (void **)&is_all_hit); + time_elapse_ms += thread_params[i].time_elapse_ms; + scan_count += thread_params[i].test_count; + + EXPECT_EQ(*is_all_hit, 1); + *is_all_hit = 0; + free(is_all_hit); + } + scan_per_second = scan_count * 1000 / time_elapse_ms; + + log_info(maat_inst->logger, MODULE_BENCHMARK_GTEST, + "Expr2MLiteralScan match rate on %d-threads speed %lld lookups/s/thread", + PERF_THREAD_NUM, scan_per_second); +} + +class Stream1KBenchmarkGTest : public ::testing::Test +{ +protected: + static void SetUpTestCase() { + logger = log_handle_create("./benchmark_rs_gtest.log", 0); + generate_expr_sample("STREAM_1K", 1000); + + FILE *fp = fopen("full_config_index.0000001", "w+"); + if (NULL == fp) { + log_error(g_logger, "open file %s failed", "full_config_index.0000001"); + return; + } + fprintf(fp, "STREAM_1K 1000 ./STREAM_1K\n"); + fprintf(fp, "COMPILE_PERF 10 ./COMPILE_PERF\n"); + fprintf(fp, "GROUP2COMPILE_PERF 10 ./GROUP2COMPILE_PERF\n"); + fclose(fp); + + struct maat_options *opts = maat_options_new(); + maat_options_set_logger(opts, "./benchmark_rs_gtest.log", LOG_LEVEL_INFO); + maat_options_set_iris(opts, "./", "./"); + maat_options_set_rule_effect_interval_ms(opts, 1000); + maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM); + maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_RS); + _shared_maat_inst = maat_new(opts, table_info_path); + maat_options_free(opts); + } + + static void TearDownTestCase() { + maat_free(_shared_maat_inst); + log_handle_destroy(logger); + } + + static struct log_handle *logger; + static struct maat *_shared_maat_inst; +}; + +struct maat *Stream1KBenchmarkGTest::_shared_maat_inst; +struct log_handle *Stream1KBenchmarkGTest::logger; + +TEST_F(Stream1KBenchmarkGTest, LiteralScan) { + const char *table_name = "STREAM_1K"; + struct maat *maat_inst = Stream1KBenchmarkGTest::_shared_maat_inst; + + int table_id = maat_get_table_id(maat_inst, table_name); + ASSERT_GT(table_id, 0); + + pthread_t threads[PERF_THREAD_NUM]; + struct thread_param thread_params[PERF_THREAD_NUM]; + int i = 0; + int *is_all_hit = NULL; + + for (i = 0; i < PERF_THREAD_NUM; i++) { + thread_params[i].maat_inst = maat_inst; + thread_params[i].thread_id = i; + thread_params[i].table_name = table_name; + thread_params[i].test_count = MAX_SCAN_COUNT; + thread_params[i].rule_count = 1000; + thread_params[i].time_elapse_ms = 0; + thread_params[i].logger = logger; + + if (i < PERF_THREAD_NUM) { + pthread_create(&threads[i], NULL, perf_stream_scan_thread, thread_params+i); + } + } + + long long time_elapse_ms = 0; + long long scan_count = 0; + long long scan_per_second = 0; + for (i = 0; i < PERF_THREAD_NUM; i++) { + pthread_join(threads[i], (void **)&is_all_hit); + time_elapse_ms += thread_params[i].time_elapse_ms; + scan_count += thread_params[i].test_count; + + EXPECT_EQ(*is_all_hit, 1); + *is_all_hit = 0; + free(is_all_hit); + } + scan_per_second = scan_count * 1000 / time_elapse_ms; + + log_info(maat_inst->logger, MODULE_BENCHMARK_GTEST, + "Stream1KScan match rate on %d-threads speed %lld lookups/s/thread", + PERF_THREAD_NUM, scan_per_second); +} + +class Stream5KBenchmarkGTest : public ::testing::Test +{ +protected: + static void SetUpTestCase() { + logger = log_handle_create("./benchmark_rs_gtest.log", 0); + generate_expr_sample("STREAM_5K", 5000); + + FILE *fp = fopen("full_config_index.0000001", "w+"); + if (NULL == fp) { + log_error(g_logger, "open file %s failed", "full_config_index.0000001"); + return; + } + fprintf(fp, "STREAM_5K 5000 ./STREAM_5K\n"); + fprintf(fp, "COMPILE_PERF 10 ./COMPILE_PERF\n"); + fprintf(fp, "GROUP2COMPILE_PERF 10 ./GROUP2COMPILE_PERF\n"); + fclose(fp); + + struct maat_options *opts = maat_options_new(); + maat_options_set_logger(opts, "./benchmark_rs_gtest.log", LOG_LEVEL_INFO); + maat_options_set_iris(opts, "./", "./"); + maat_options_set_rule_effect_interval_ms(opts, 1000); + maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM); + maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_RS); + _shared_maat_inst = maat_new(opts, table_info_path); + maat_options_free(opts); + } + + static void TearDownTestCase() { + maat_free(_shared_maat_inst); + log_handle_destroy(logger); + } + + static struct log_handle *logger; + static struct maat *_shared_maat_inst; +}; + +struct maat *Stream5KBenchmarkGTest::_shared_maat_inst; +struct log_handle *Stream5KBenchmarkGTest::logger; + +TEST_F(Stream5KBenchmarkGTest, LiteralScan) { + const char *table_name = "STREAM_5K"; + struct maat *maat_inst = Stream5KBenchmarkGTest::_shared_maat_inst; + + int table_id = maat_get_table_id(maat_inst, table_name); + ASSERT_GT(table_id, 0); + + pthread_t threads[PERF_THREAD_NUM]; + struct thread_param thread_params[PERF_THREAD_NUM]; + int i = 0; + int *is_all_hit = NULL; + + for (i = 0; i < PERF_THREAD_NUM; i++) { + thread_params[i].maat_inst = maat_inst; + thread_params[i].thread_id = i; + thread_params[i].table_name = table_name; + thread_params[i].test_count = MAX_SCAN_COUNT; + thread_params[i].rule_count = 5000; + thread_params[i].time_elapse_ms = 0; + thread_params[i].logger = logger; + + if (i < PERF_THREAD_NUM) { + pthread_create(&threads[i], NULL, perf_stream_scan_thread, thread_params+i); + } + } + + long long time_elapse_ms = 0; + long long scan_count = 0; + long long scan_per_second = 0; + for (i = 0; i < PERF_THREAD_NUM; i++) { + pthread_join(threads[i], (void **)&is_all_hit); + time_elapse_ms += thread_params[i].time_elapse_ms; + scan_count += thread_params[i].test_count; + + EXPECT_EQ(*is_all_hit, 1); + *is_all_hit = 0; + free(is_all_hit); + } + scan_per_second = scan_count * 1000 / time_elapse_ms; + + log_info(maat_inst->logger, MODULE_BENCHMARK_GTEST, + "Stream5KScan match rate on %d-threads speed %lld lookups/s/thread", + PERF_THREAD_NUM, scan_per_second); +} + +class Stream10KBenchmarkGTest : public ::testing::Test +{ +protected: + static void SetUpTestCase() { + logger = log_handle_create("./benchmark_rs_gtest.log", 0); + generate_expr_sample("STREAM_10K", 10000); + + FILE *fp = fopen("full_config_index.0000001", "w+"); + if (NULL == fp) { + log_error(g_logger, "open file %s failed", "full_config_index.0000001"); + return; + } + fprintf(fp, "STREAM_10K 10000 ./STREAM_10K\n"); + fprintf(fp, "COMPILE_PERF 10 ./COMPILE_PERF\n"); + fprintf(fp, "GROUP2COMPILE_PERF 10 ./GROUP2COMPILE_PERF\n"); + fclose(fp); + + struct maat_options *opts = maat_options_new(); + maat_options_set_logger(opts, "./benchmark_rs_gtest.log", LOG_LEVEL_INFO); + maat_options_set_iris(opts, "./", "./"); + maat_options_set_rule_effect_interval_ms(opts, 1000); + maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM); + maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_RS); + _shared_maat_inst = maat_new(opts, table_info_path); + maat_options_free(opts); + } + + static void TearDownTestCase() { + maat_free(_shared_maat_inst); + log_handle_destroy(logger); + } + + static struct log_handle *logger; + static struct maat *_shared_maat_inst; +}; + +struct maat *Stream10KBenchmarkGTest::_shared_maat_inst; +struct log_handle *Stream10KBenchmarkGTest::logger; + +TEST_F(Stream10KBenchmarkGTest, LiteralScan) { + const char *table_name = "STREAM_10K"; + struct maat *maat_inst = Stream10KBenchmarkGTest::_shared_maat_inst; + + int table_id = maat_get_table_id(maat_inst, table_name); + ASSERT_GT(table_id, 0); + + pthread_t threads[PERF_THREAD_NUM]; + struct thread_param thread_params[PERF_THREAD_NUM]; + int i = 0; + int *is_all_hit = NULL; + + for (i = 0; i < PERF_THREAD_NUM; i++) { + thread_params[i].maat_inst = maat_inst; + thread_params[i].thread_id = i; + thread_params[i].table_name = table_name; + thread_params[i].test_count = MAX_SCAN_COUNT; + thread_params[i].rule_count = 10000; + thread_params[i].time_elapse_ms = 0; + thread_params[i].logger = logger; + + if (i < PERF_THREAD_NUM) { + pthread_create(&threads[i], NULL, perf_stream_scan_thread, thread_params+i); + } + } + + long long time_elapse_ms = 0; + long long scan_count = 0; + long long scan_per_second = 0; + for (i = 0; i < PERF_THREAD_NUM; i++) { + pthread_join(threads[i], (void **)&is_all_hit); + time_elapse_ms += thread_params[i].time_elapse_ms; + scan_count += thread_params[i].test_count; + + EXPECT_EQ(*is_all_hit, 1); + *is_all_hit = 0; + free(is_all_hit); + } + scan_per_second = scan_count * 1000 / time_elapse_ms; + + log_info(maat_inst->logger, MODULE_BENCHMARK_GTEST, + "Stream10KScan match rate on %d-threads speed %lld lookups/s/thread", + PERF_THREAD_NUM, scan_per_second); +} + +class Stream50KBenchmarkGTest : public ::testing::Test +{ +protected: + static void SetUpTestCase() { + logger = log_handle_create("./benchmark_rs_gtest.log", 0); + generate_expr_sample("STREAM_50K", 50000); + + FILE *fp = fopen("full_config_index.0000001", "w+"); + if (NULL == fp) { + log_error(g_logger, "open file %s failed", "full_config_index.0000001"); + return; + } + fprintf(fp, "STREAM_50K 50000 ./STREAM_50K\n"); + fprintf(fp, "COMPILE_PERF 10 ./COMPILE_PERF\n"); + fprintf(fp, "GROUP2COMPILE_PERF 10 ./GROUP2COMPILE_PERF\n"); + fclose(fp); + + struct maat_options *opts = maat_options_new(); + maat_options_set_logger(opts, "./benchmark_rs_gtest.log", LOG_LEVEL_INFO); + maat_options_set_iris(opts, "./", "./"); + maat_options_set_rule_effect_interval_ms(opts, 1000); + maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM); + maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_RS); + _shared_maat_inst = maat_new(opts, table_info_path); + maat_options_free(opts); + } + + static void TearDownTestCase() { + maat_free(_shared_maat_inst); + log_handle_destroy(logger); + } + + static struct log_handle *logger; + static struct maat *_shared_maat_inst; +}; + +struct maat *Stream50KBenchmarkGTest::_shared_maat_inst; +struct log_handle *Stream50KBenchmarkGTest::logger; + +TEST_F(Stream50KBenchmarkGTest, LiteralScan) { + const char *table_name = "STREAM_50K"; + struct maat *maat_inst = Stream50KBenchmarkGTest::_shared_maat_inst; + + int table_id = maat_get_table_id(maat_inst, table_name); + ASSERT_GT(table_id, 0); + + pthread_t threads[PERF_THREAD_NUM]; + struct thread_param thread_params[PERF_THREAD_NUM]; + int i = 0; + int *is_all_hit = NULL; + + for (i = 0; i < PERF_THREAD_NUM; i++) { + thread_params[i].maat_inst = maat_inst; + thread_params[i].thread_id = i; + thread_params[i].table_name = table_name; + thread_params[i].test_count = MAX_SCAN_COUNT; + thread_params[i].rule_count = 50000; + thread_params[i].time_elapse_ms = 0; + thread_params[i].logger = logger; + + if (i < PERF_THREAD_NUM) { + pthread_create(&threads[i], NULL, perf_stream_scan_thread, thread_params+i); + } + } + + long long time_elapse_ms = 0; + long long scan_count = 0; + long long scan_per_second = 0; + for (i = 0; i < PERF_THREAD_NUM; i++) { + pthread_join(threads[i], (void **)&is_all_hit); + time_elapse_ms += thread_params[i].time_elapse_ms; + scan_count += thread_params[i].test_count; + + EXPECT_EQ(*is_all_hit, 1); + *is_all_hit = 0; + free(is_all_hit); + } + scan_per_second = scan_count * 1000 / time_elapse_ms; + + log_info(maat_inst->logger, MODULE_BENCHMARK_GTEST, + "Stream50KScan match rate on %d-threads speed %lld lookups/s/thread", + PERF_THREAD_NUM, scan_per_second); +} + +class Stream100KBenchmarkGTest : public ::testing::Test +{ +protected: + static void SetUpTestCase() { + logger = log_handle_create("./benchmark_rs_gtest.log", 0); + generate_expr_sample("STREAM_100K", 100000); + + FILE *fp = fopen("full_config_index.0000001", "w+"); + if (NULL == fp) { + log_error(g_logger, "open file %s failed", "full_config_index.0000001"); + return; + } + fprintf(fp, "STREAM_100K 100000 ./STREAM_100K\n"); + fprintf(fp, "COMPILE_PERF 10 ./COMPILE_PERF\n"); + fprintf(fp, "GROUP2COMPILE_PERF 10 ./GROUP2COMPILE_PERF\n"); + fclose(fp); + + struct maat_options *opts = maat_options_new(); + maat_options_set_logger(opts, "./benchmark_rs_gtest.log", LOG_LEVEL_INFO); + maat_options_set_iris(opts, "./", "./"); + maat_options_set_rule_effect_interval_ms(opts, 1000); + maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM); + maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_RS); + _shared_maat_inst = maat_new(opts, table_info_path); + maat_options_free(opts); + } + + static void TearDownTestCase() { + maat_free(_shared_maat_inst); + log_handle_destroy(logger); + } + + static struct log_handle *logger; + static struct maat *_shared_maat_inst; +}; + +struct maat *Stream100KBenchmarkGTest::_shared_maat_inst; +struct log_handle *Stream100KBenchmarkGTest::logger; + +TEST_F(Stream100KBenchmarkGTest, LiteralScan) { + const char *table_name = "STREAM_100K"; + struct maat *maat_inst = Stream100KBenchmarkGTest::_shared_maat_inst; + + int table_id = maat_get_table_id(maat_inst, table_name); + ASSERT_GT(table_id, 0); + + pthread_t threads[PERF_THREAD_NUM]; + struct thread_param thread_params[PERF_THREAD_NUM]; + int i = 0; + int *is_all_hit = NULL; + + for (i = 0; i < PERF_THREAD_NUM; i++) { + thread_params[i].maat_inst = maat_inst; + thread_params[i].thread_id = i; + thread_params[i].table_name = table_name; + thread_params[i].test_count = MAX_SCAN_COUNT; + thread_params[i].rule_count = 100000; + thread_params[i].time_elapse_ms = 0; + thread_params[i].logger = logger; + + if (i < PERF_THREAD_NUM) { + pthread_create(&threads[i], NULL, perf_stream_scan_thread, thread_params+i); + } + } + + long long time_elapse_ms = 0; + long long scan_count = 0; + long long scan_per_second = 0; + for (i = 0; i < PERF_THREAD_NUM; i++) { + pthread_join(threads[i], (void **)&is_all_hit); + time_elapse_ms += thread_params[i].time_elapse_ms; + scan_count += thread_params[i].test_count; + + EXPECT_EQ(*is_all_hit, 1); + *is_all_hit = 0; + free(is_all_hit); + } + scan_per_second = scan_count * 1000 / time_elapse_ms; + + log_info(maat_inst->logger, MODULE_BENCHMARK_GTEST, + "Stream100KScan match rate on %d-threads speed %lld lookups/s/thread", + PERF_THREAD_NUM, scan_per_second); +} + +class Stream500KBenchmarkGTest : public ::testing::Test +{ +protected: + static void SetUpTestCase() { + logger = log_handle_create("./benchmark_rs_gtest.log", 0); + generate_expr_sample("STREAM_500K", 500000); + + FILE *fp = fopen("full_config_index.0000001", "w+"); + if (NULL == fp) { + log_error(g_logger, "open file %s failed", "full_config_index.0000001"); + return; + } + fprintf(fp, "STREAM_500K 500000 ./STREAM_500K\n"); + fprintf(fp, "COMPILE_PERF 10 ./COMPILE_PERF\n"); + fprintf(fp, "GROUP2COMPILE_PERF 10 ./GROUP2COMPILE_PERF\n"); + fclose(fp); + + struct maat_options *opts = maat_options_new(); + maat_options_set_logger(opts, "./benchmark_rs_gtest.log", LOG_LEVEL_INFO); + maat_options_set_iris(opts, "./", "./"); + maat_options_set_rule_effect_interval_ms(opts, 1000); + maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM); + maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_RS); + _shared_maat_inst = maat_new(opts, table_info_path); + maat_options_free(opts); + } + + static void TearDownTestCase() { + maat_free(_shared_maat_inst); + log_handle_destroy(logger); + } + + static struct log_handle *logger; + static struct maat *_shared_maat_inst; +}; + +struct maat *Stream500KBenchmarkGTest::_shared_maat_inst; +struct log_handle *Stream500KBenchmarkGTest::logger; + +TEST_F(Stream500KBenchmarkGTest, LiteralScan) { + const char *table_name = "STREAM_500K"; + struct maat *maat_inst = Stream500KBenchmarkGTest::_shared_maat_inst; + + int table_id = maat_get_table_id(maat_inst, table_name); + ASSERT_GT(table_id, 0); + + pthread_t threads[PERF_THREAD_NUM]; + struct thread_param thread_params[PERF_THREAD_NUM]; + int i = 0; + int *is_all_hit = NULL; + + for (i = 0; i < PERF_THREAD_NUM; i++) { + thread_params[i].maat_inst = maat_inst; + thread_params[i].thread_id = i; + thread_params[i].table_name = table_name; + thread_params[i].test_count = MAX_SCAN_COUNT; + thread_params[i].rule_count = 500000; + thread_params[i].time_elapse_ms = 0; + thread_params[i].logger = logger; + + if (i < PERF_THREAD_NUM) { + pthread_create(&threads[i], NULL, perf_stream_scan_thread, thread_params+i); + } + } + + long long time_elapse_ms = 0; + long long scan_count = 0; + long long scan_per_second = 0; + for (i = 0; i < PERF_THREAD_NUM; i++) { + pthread_join(threads[i], (void **)&is_all_hit); + time_elapse_ms += thread_params[i].time_elapse_ms; + scan_count += thread_params[i].test_count; + + EXPECT_EQ(*is_all_hit, 1); + *is_all_hit = 0; + free(is_all_hit); + } + scan_per_second = scan_count * 1000 / time_elapse_ms; + + log_info(maat_inst->logger, MODULE_BENCHMARK_GTEST, + "Stream500KScan match rate on %d-threads speed %lld lookups/s/thread", + PERF_THREAD_NUM, scan_per_second); +} + +class Stream1MBenchmarkGTest : public ::testing::Test +{ +protected: + static void SetUpTestCase() { + logger = log_handle_create("./benchmark_rs_gtest.log", 0); + generate_expr_sample("STREAM_1M", 1000000); + + FILE *fp = fopen("full_config_index.0000001", "w+"); + if (NULL == fp) { + log_error(g_logger, "open file %s failed", "full_config_index.0000001"); + return; + } + fprintf(fp, "STREAM_1M 1000000 ./STREAM_1M\n"); + fprintf(fp, "COMPILE_PERF 10 ./COMPILE_PERF\n"); + fprintf(fp, "GROUP2COMPILE_PERF 10 ./GROUP2COMPILE_PERF\n"); + fclose(fp); + + struct maat_options *opts = maat_options_new(); + maat_options_set_logger(opts, "./benchmark_rs_gtest.log", LOG_LEVEL_INFO); + maat_options_set_iris(opts, "./", "./"); + maat_options_set_rule_effect_interval_ms(opts, 1000); + maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM); + maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_RS); + _shared_maat_inst = maat_new(opts, table_info_path); + maat_options_free(opts); + } + + static void TearDownTestCase() { + maat_free(_shared_maat_inst); + log_handle_destroy(logger); + } + + static struct log_handle *logger; + static struct maat *_shared_maat_inst; +}; + +struct maat *Stream1MBenchmarkGTest::_shared_maat_inst; +struct log_handle *Stream1MBenchmarkGTest::logger; + +TEST_F(Stream1MBenchmarkGTest, LiteralScan) { + const char *table_name = "STREAM_1M"; + struct maat *maat_inst = Stream1MBenchmarkGTest::_shared_maat_inst; + + int table_id = maat_get_table_id(maat_inst, table_name); + ASSERT_GT(table_id, 0); + + pthread_t threads[PERF_THREAD_NUM]; + struct thread_param thread_params[PERF_THREAD_NUM]; + int i = 0; + int *is_all_hit = NULL; + + for (i = 0; i < PERF_THREAD_NUM; i++) { + thread_params[i].maat_inst = maat_inst; + thread_params[i].thread_id = i; + thread_params[i].table_name = table_name; + thread_params[i].test_count = MAX_SCAN_COUNT; + thread_params[i].rule_count = 1000000; + thread_params[i].time_elapse_ms = 0; + thread_params[i].logger = logger; + + if (i < PERF_THREAD_NUM) { + pthread_create(&threads[i], NULL, perf_stream_scan_thread, thread_params+i); + } + } + + long long time_elapse_ms = 0; + long long scan_count = 0; + long long scan_per_second = 0; + for (i = 0; i < PERF_THREAD_NUM; i++) { + pthread_join(threads[i], (void **)&is_all_hit); + time_elapse_ms += thread_params[i].time_elapse_ms; + scan_count += thread_params[i].test_count; + + EXPECT_EQ(*is_all_hit, 1); + *is_all_hit = 0; + free(is_all_hit); + } + scan_per_second = scan_count * 1000 / time_elapse_ms; + + log_info(maat_inst->logger, MODULE_BENCHMARK_GTEST, + "Stream1MScan match rate on %d-threads speed %lld lookups/s/thread", + PERF_THREAD_NUM, scan_per_second); +} + +class Stream2MBenchmarkGTest : public ::testing::Test +{ +protected: + static void SetUpTestCase() { + logger = log_handle_create("./benchmark_rs_gtest.log", 0); + generate_expr_sample("STREAM_2M", 2000000); + + FILE *fp = fopen("full_config_index.0000001", "w+"); + if (NULL == fp) { + log_error(g_logger, "open file %s failed", "full_config_index.0000001"); + return; + } + fprintf(fp, "STREAM_2M 2000000 ./STREAM_2M\n"); + fprintf(fp, "COMPILE_PERF 10 ./COMPILE_PERF\n"); + fprintf(fp, "GROUP2COMPILE_PERF 10 ./GROUP2COMPILE_PERF\n"); + fclose(fp); + + struct maat_options *opts = maat_options_new(); + maat_options_set_logger(opts, "./benchmark_rs_gtest.log", LOG_LEVEL_INFO); + maat_options_set_iris(opts, "./", "./"); + maat_options_set_rule_effect_interval_ms(opts, 1000); + maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM); + maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_RS); + _shared_maat_inst = maat_new(opts, table_info_path); + maat_options_free(opts); + } + + static void TearDownTestCase() { + maat_free(_shared_maat_inst); + log_handle_destroy(logger); + } + + static struct log_handle *logger; + static struct maat *_shared_maat_inst; +}; + +struct maat *Stream2MBenchmarkGTest::_shared_maat_inst; +struct log_handle *Stream2MBenchmarkGTest::logger; + +TEST_F(Stream2MBenchmarkGTest, LiteralScan) { + const char *table_name = "STREAM_2M"; + struct maat *maat_inst = Stream2MBenchmarkGTest::_shared_maat_inst; + + int table_id = maat_get_table_id(maat_inst, table_name); + ASSERT_GT(table_id, 0); + + pthread_t threads[PERF_THREAD_NUM]; + struct thread_param thread_params[PERF_THREAD_NUM]; + int i = 0; + int *is_all_hit = NULL; + + for (i = 0; i < PERF_THREAD_NUM; i++) { + thread_params[i].maat_inst = maat_inst; + thread_params[i].thread_id = i; + thread_params[i].table_name = table_name; + thread_params[i].test_count = MAX_SCAN_COUNT; + thread_params[i].rule_count = 2000000; + thread_params[i].time_elapse_ms = 0; + thread_params[i].logger = logger; + + if (i < PERF_THREAD_NUM) { + pthread_create(&threads[i], NULL, perf_stream_scan_thread, thread_params+i); + } + } + + long long time_elapse_ms = 0; + long long scan_count = 0; + long long scan_per_second = 0; + for (i = 0; i < PERF_THREAD_NUM; i++) { + pthread_join(threads[i], (void **)&is_all_hit); + time_elapse_ms += thread_params[i].time_elapse_ms; + scan_count += thread_params[i].test_count; + + EXPECT_EQ(*is_all_hit, 1); + *is_all_hit = 0; + free(is_all_hit); + } + scan_per_second = scan_count * 1000 / time_elapse_ms; + + log_info(maat_inst->logger, MODULE_BENCHMARK_GTEST, + "Stream2MScan match rate on %d-threads speed %lld lookups/s/thread", + PERF_THREAD_NUM, scan_per_second); +} + +class IP1KBenchmarkGTest : public ::testing::Test +{ +protected: + static void SetUpTestCase() { + logger = log_handle_create("./benchmark_rs_gtest.log", 0); + generate_ip_sample("IP_1K", 1000); + + FILE *fp = fopen("full_config_index.0000001", "w+"); + if (NULL == fp) { + log_error(g_logger, "open file %s failed", "full_config_index.0000001"); + return; + } + fprintf(fp, "IP_1K 1000 ./IP_1K\n"); + fprintf(fp, "COMPILE_PERF 10 ./COMPILE_PERF\n"); + fprintf(fp, "GROUP2COMPILE_PERF 10 ./GROUP2COMPILE_PERF\n"); + fclose(fp); + + struct maat_options *opts = maat_options_new(); + maat_options_set_logger(opts, "./benchmark_rs_gtest.log", LOG_LEVEL_INFO); + maat_options_set_iris(opts, "./", "./"); + maat_options_set_rule_effect_interval_ms(opts, 1000); + maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM); + maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_RS); + _shared_maat_inst = maat_new(opts, table_info_path); + maat_options_free(opts); + } + + static void TearDownTestCase() { + maat_free(_shared_maat_inst); + log_handle_destroy(logger); + } + + static struct log_handle *logger; + static struct maat *_shared_maat_inst; +}; + +struct maat *IP1KBenchmarkGTest::_shared_maat_inst; +struct log_handle *IP1KBenchmarkGTest::logger; + +TEST_F(IP1KBenchmarkGTest, IPScan) { + const char *table_name = "IP_1K"; + struct maat *maat_inst = IP1KBenchmarkGTest::_shared_maat_inst; + + int table_id = maat_get_table_id(maat_inst, table_name); + ASSERT_GT(table_id, 0); + + pthread_t threads[PERF_THREAD_NUM + 1]; + struct thread_param thread_params[PERF_THREAD_NUM + 1]; + int i = 0; + int *is_all_hit = NULL; + + for (i = 0; i < PERF_THREAD_NUM + 1; i++) { + thread_params[i].maat_inst = maat_inst; + thread_params[i].thread_id = i; + thread_params[i].table_name = table_name; + thread_params[i].test_count = MAX_SCAN_COUNT; + thread_params[i].rule_count = 1000; + thread_params[i].time_elapse_ms = 0; + thread_params[i].logger = logger; + + if (i < PERF_THREAD_NUM) { + pthread_create(&threads[i], NULL, perf_ip_scan_thread, thread_params+i); + } else { + thread_params[i].test_count = 0; + pthread_create(&threads[i], NULL, perf_ip_update_thread, thread_params+i); + } + } + + long long time_elapse_ms = 0; + long long scan_count = 0; + long long scan_per_second = 0; + for (i = 0; i < PERF_THREAD_NUM + 1; i++) { + pthread_join(threads[i], (void **)&is_all_hit); + time_elapse_ms += thread_params[i].time_elapse_ms; + scan_count += thread_params[i].test_count; + + EXPECT_EQ(*is_all_hit, 1); + *is_all_hit = 0; + free(is_all_hit); + } + scan_per_second = scan_count * 1000 / time_elapse_ms; + + log_info(maat_inst->logger, MODULE_BENCHMARK_GTEST, + "IP1KScan match rate on %d-threads speed %lld lookups/s/thread", + PERF_THREAD_NUM, scan_per_second); +} + +class IP5KBenchmarkGTest : public ::testing::Test +{ +protected: + static void SetUpTestCase() { + logger = log_handle_create("./benchmark_rs_gtest.log", 0); + generate_ip_sample("IP_5K", 5000); + + FILE *fp = fopen("full_config_index.0000001", "w+"); + if (NULL == fp) { + log_error(g_logger, "open file %s failed", "full_config_index.0000001"); + return; + } + fprintf(fp, "IP_5K 5000 ./IP_5K\n"); + fprintf(fp, "COMPILE_PERF 10 ./COMPILE_PERF\n"); + fprintf(fp, "GROUP2COMPILE_PERF 10 ./GROUP2COMPILE_PERF\n"); + fclose(fp); + + struct maat_options *opts = maat_options_new(); + maat_options_set_logger(opts, "./benchmark_rs_gtest.log", LOG_LEVEL_INFO); + maat_options_set_iris(opts, "./", "./"); + maat_options_set_rule_effect_interval_ms(opts, 1000); + maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM); + maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_RS); + _shared_maat_inst = maat_new(opts, table_info_path); + maat_options_free(opts); + } + + static void TearDownTestCase() { + maat_free(_shared_maat_inst); + log_handle_destroy(logger); + } + + static struct log_handle *logger; + static struct maat *_shared_maat_inst; +}; + +struct maat *IP5KBenchmarkGTest::_shared_maat_inst; +struct log_handle *IP5KBenchmarkGTest::logger; + +TEST_F(IP5KBenchmarkGTest, IPScan) { + const char *table_name = "IP_5K"; + struct maat *maat_inst = IP5KBenchmarkGTest::_shared_maat_inst; + + int table_id = maat_get_table_id(maat_inst, table_name); + ASSERT_GT(table_id, 0); + + pthread_t threads[PERF_THREAD_NUM + 1]; + struct thread_param thread_params[PERF_THREAD_NUM + 1]; + int i = 0; + int *is_all_hit = NULL; + + for (i = 0; i < PERF_THREAD_NUM + 1; i++) { + thread_params[i].maat_inst = maat_inst; + thread_params[i].thread_id = i; + thread_params[i].table_name = table_name; + thread_params[i].test_count = MAX_SCAN_COUNT; + thread_params[i].rule_count = 5000; + thread_params[i].time_elapse_ms = 0; + thread_params[i].logger = logger; + + if (i < PERF_THREAD_NUM) { + pthread_create(&threads[i], NULL, perf_ip_scan_thread, thread_params+i); + } else { + thread_params[i].test_count = 0; + pthread_create(&threads[i], NULL, perf_ip_update_thread, thread_params+i); + } + } + + long long time_elapse_ms = 0; + long long scan_count = 0; + long long scan_per_second = 0; + for (i = 0; i < PERF_THREAD_NUM + 1; i++) { + pthread_join(threads[i], (void **)&is_all_hit); + time_elapse_ms += thread_params[i].time_elapse_ms; + scan_count += thread_params[i].test_count; + + EXPECT_EQ(*is_all_hit, 1); + *is_all_hit = 0; + free(is_all_hit); + } + scan_per_second = scan_count * 1000 / time_elapse_ms; + + log_info(maat_inst->logger, MODULE_BENCHMARK_GTEST, + "IP5KScan match rate on %d-threads speed %lld lookups/s/thread", + PERF_THREAD_NUM, scan_per_second); +} + +class IP10KBenchmarkGTest : public ::testing::Test +{ +protected: + static void SetUpTestCase() { + logger = log_handle_create("./benchmark_rs_gtest.log", 0); + generate_ip_sample("IP_10K", 10000); + + FILE *fp = fopen("full_config_index.0000001", "w+"); + if (NULL == fp) { + log_error(g_logger, "open file %s failed", "full_config_index.0000001"); + return; + } + fprintf(fp, "IP_10K 10000 ./IP_10K\n"); + fprintf(fp, "COMPILE_PERF 10 ./COMPILE_PERF\n"); + fprintf(fp, "GROUP2COMPILE_PERF 10 ./GROUP2COMPILE_PERF\n"); + fclose(fp); + + struct maat_options *opts = maat_options_new(); + maat_options_set_logger(opts, "./benchmark_rs_gtest.log", LOG_LEVEL_INFO); + maat_options_set_iris(opts, "./", "./"); + maat_options_set_rule_effect_interval_ms(opts, 1000); + maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM); + maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_RS); + _shared_maat_inst = maat_new(opts, table_info_path); + maat_options_free(opts); + } + + static void TearDownTestCase() { + maat_free(_shared_maat_inst); + log_handle_destroy(logger); + } + + static struct log_handle *logger; + static struct maat *_shared_maat_inst; +}; + +struct maat *IP10KBenchmarkGTest::_shared_maat_inst; +struct log_handle *IP10KBenchmarkGTest::logger; + +TEST_F(IP10KBenchmarkGTest, IPScan) { + const char *table_name = "IP_10K"; + struct maat *maat_inst = IP10KBenchmarkGTest::_shared_maat_inst; + + int table_id = maat_get_table_id(maat_inst, table_name); + ASSERT_GT(table_id, 0); + + pthread_t threads[PERF_THREAD_NUM + 1]; + struct thread_param thread_params[PERF_THREAD_NUM + 1]; + int i = 0; + int *is_all_hit = NULL; + + for (i = 0; i < PERF_THREAD_NUM + 1; i++) { + thread_params[i].maat_inst = maat_inst; + thread_params[i].thread_id = i; + thread_params[i].table_name = table_name; + thread_params[i].test_count = MAX_SCAN_COUNT; + thread_params[i].rule_count = 10000; + thread_params[i].time_elapse_ms = 0; + thread_params[i].logger = logger; + + if (i < PERF_THREAD_NUM) { + pthread_create(&threads[i], NULL, perf_ip_scan_thread, thread_params+i); + } else { + thread_params[i].test_count = 0; + pthread_create(&threads[i], NULL, perf_ip_update_thread, thread_params+i); + } + } + + long long time_elapse_ms = 0; + long long scan_count = 0; + long long scan_per_second = 0; + for (i = 0; i < PERF_THREAD_NUM + 1; i++) { + pthread_join(threads[i], (void **)&is_all_hit); + time_elapse_ms += thread_params[i].time_elapse_ms; + scan_count += thread_params[i].test_count; + + EXPECT_EQ(*is_all_hit, 1); + *is_all_hit = 0; + free(is_all_hit); + } + scan_per_second = scan_count * 1000 / time_elapse_ms; + + log_info(maat_inst->logger, MODULE_BENCHMARK_GTEST, + "IP10KScan match rate on %d-threads speed %lld lookups/s/thread", + PERF_THREAD_NUM, scan_per_second); +} + +class IP50KBenchmarkGTest : public ::testing::Test +{ +protected: + static void SetUpTestCase() { + logger = log_handle_create("./benchmark_rs_gtest.log", 0); + generate_ip_sample("IP_50K", 50000); + + FILE *fp = fopen("full_config_index.0000001", "w+"); + if (NULL == fp) { + log_error(g_logger, "open file %s failed", "full_config_index.0000001"); + return; + } + fprintf(fp, "IP_50K 50000 ./IP_50K\n"); + fprintf(fp, "COMPILE_PERF 10 ./COMPILE_PERF\n"); + fprintf(fp, "GROUP2COMPILE_PERF 10 ./GROUP2COMPILE_PERF\n"); + fclose(fp); + + struct maat_options *opts = maat_options_new(); + maat_options_set_logger(opts, "./benchmark_rs_gtest.log", LOG_LEVEL_INFO); + maat_options_set_iris(opts, "./", "./"); + maat_options_set_rule_effect_interval_ms(opts, 1000); + maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM); + maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_RS); + _shared_maat_inst = maat_new(opts, table_info_path); + maat_options_free(opts); + } + + static void TearDownTestCase() { + maat_free(_shared_maat_inst); + log_handle_destroy(logger); + } + + static struct log_handle *logger; + static struct maat *_shared_maat_inst; +}; + +struct maat *IP50KBenchmarkGTest::_shared_maat_inst; +struct log_handle *IP50KBenchmarkGTest::logger; + +TEST_F(IP50KBenchmarkGTest, IPScan) { + const char *table_name = "IP_50K"; + struct maat *maat_inst = IP50KBenchmarkGTest::_shared_maat_inst; + + int table_id = maat_get_table_id(maat_inst, table_name); + ASSERT_GT(table_id, 0); + + pthread_t threads[PERF_THREAD_NUM + 1]; + struct thread_param thread_params[PERF_THREAD_NUM + 1]; + int i = 0; + int *is_all_hit = NULL; + + for (i = 0; i < PERF_THREAD_NUM + 1; i++) { + thread_params[i].maat_inst = maat_inst; + thread_params[i].thread_id = i; + thread_params[i].table_name = table_name; + thread_params[i].test_count = MAX_SCAN_COUNT; + thread_params[i].rule_count = 50000; + thread_params[i].time_elapse_ms = 0; + thread_params[i].logger = logger; + + if (i < PERF_THREAD_NUM) { + pthread_create(&threads[i], NULL, perf_ip_scan_thread, thread_params+i); + } else { + thread_params[i].test_count = 0; + pthread_create(&threads[i], NULL, perf_ip_update_thread, thread_params+i); + } + } + + long long time_elapse_ms = 0; + long long scan_count = 0; + long long scan_per_second = 0; + for (i = 0; i < PERF_THREAD_NUM + 1; i++) { + pthread_join(threads[i], (void **)&is_all_hit); + time_elapse_ms += thread_params[i].time_elapse_ms; + scan_count += thread_params[i].test_count; + + EXPECT_EQ(*is_all_hit, 1); + *is_all_hit = 0; + free(is_all_hit); + } + scan_per_second = scan_count * 1000 / time_elapse_ms; + + log_info(maat_inst->logger, MODULE_BENCHMARK_GTEST, + "IP50KScan match rate on %d-threads speed %lld lookups/s/thread", + PERF_THREAD_NUM, scan_per_second); +} + +class IP100KBenchmarkGTest : public ::testing::Test +{ +protected: + static void SetUpTestCase() { + logger = log_handle_create("./benchmark_rs_gtest.log", 0); + generate_ip_sample("IP_100K", 100000); + + FILE *fp = fopen("full_config_index.0000001", "w+"); + if (NULL == fp) { + log_error(g_logger, "open file %s failed", "full_config_index.0000001"); + return; + } + fprintf(fp, "IP_100K 100000 ./IP_100K\n"); + fprintf(fp, "COMPILE_PERF 10 ./COMPILE_PERF\n"); + fprintf(fp, "GROUP2COMPILE_PERF 10 ./GROUP2COMPILE_PERF\n"); + fclose(fp); + + struct maat_options *opts = maat_options_new(); + maat_options_set_logger(opts, "./benchmark_rs_gtest.log", LOG_LEVEL_INFO); + maat_options_set_iris(opts, "./", "./"); + maat_options_set_rule_effect_interval_ms(opts, 1000); + maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM); + maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_RS); + _shared_maat_inst = maat_new(opts, table_info_path); + maat_options_free(opts); + } + + static void TearDownTestCase() { + maat_free(_shared_maat_inst); + log_handle_destroy(logger); + } + + static struct log_handle *logger; + static struct maat *_shared_maat_inst; +}; + +struct maat *IP100KBenchmarkGTest::_shared_maat_inst; +struct log_handle *IP100KBenchmarkGTest::logger; + +TEST_F(IP100KBenchmarkGTest, IPScan) { + const char *table_name = "IP_100K"; + struct maat *maat_inst = IP100KBenchmarkGTest::_shared_maat_inst; + + int table_id = maat_get_table_id(maat_inst, table_name); + ASSERT_GT(table_id, 0); + + pthread_t threads[PERF_THREAD_NUM + 1]; + struct thread_param thread_params[PERF_THREAD_NUM + 1]; + int i = 0; + int *is_all_hit = NULL; + + for (i = 0; i < PERF_THREAD_NUM + 1; i++) { + thread_params[i].maat_inst = maat_inst; + thread_params[i].thread_id = i; + thread_params[i].table_name = table_name; + thread_params[i].test_count = MAX_SCAN_COUNT; + thread_params[i].rule_count = 100000; + thread_params[i].time_elapse_ms = 0; + thread_params[i].logger = logger; + + if (i < PERF_THREAD_NUM) { + pthread_create(&threads[i], NULL, perf_ip_scan_thread, thread_params+i); + } else { + thread_params[i].test_count = 0; + pthread_create(&threads[i], NULL, perf_ip_update_thread, thread_params+i); + } + } + + long long time_elapse_ms = 0; + long long scan_count = 0; + long long scan_per_second = 0; + for (i = 0; i < PERF_THREAD_NUM + 1; i++) { + pthread_join(threads[i], (void **)&is_all_hit); + time_elapse_ms += thread_params[i].time_elapse_ms; + scan_count += thread_params[i].test_count; + + EXPECT_EQ(*is_all_hit, 1); + *is_all_hit = 0; + free(is_all_hit); + } + scan_per_second = scan_count * 1000 / time_elapse_ms; + + log_info(maat_inst->logger, MODULE_BENCHMARK_GTEST, + "IP100KScan match rate on %d-threads speed %lld lookups/s/thread", + PERF_THREAD_NUM, scan_per_second); +} + +class IP500KBenchmarkGTest : public ::testing::Test +{ +protected: + static void SetUpTestCase() { + logger = log_handle_create("./benchmark_rs_gtest.log", 0); + generate_ip_sample("IP_500K", 500000); + + FILE *fp = fopen("full_config_index.0000001", "w+"); + if (NULL == fp) { + log_error(g_logger, "open file %s failed", "full_config_index.0000001"); + return; + } + fprintf(fp, "IP_500K 500000 ./IP_500K\n"); + fprintf(fp, "COMPILE_PERF 10 ./COMPILE_PERF\n"); + fprintf(fp, "GROUP2COMPILE_PERF 10 ./GROUP2COMPILE_PERF\n"); + fclose(fp); + + struct maat_options *opts = maat_options_new(); + maat_options_set_logger(opts, "./benchmark_rs_gtest.log", LOG_LEVEL_INFO); + maat_options_set_iris(opts, "./", "./"); + maat_options_set_rule_effect_interval_ms(opts, 1000); + maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM); + maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_RS); + _shared_maat_inst = maat_new(opts, table_info_path); + maat_options_free(opts); + } + + static void TearDownTestCase() { + maat_free(_shared_maat_inst); + log_handle_destroy(logger); + } + + static struct log_handle *logger; + static struct maat *_shared_maat_inst; +}; + +struct maat *IP500KBenchmarkGTest::_shared_maat_inst; +struct log_handle *IP500KBenchmarkGTest::logger; + +TEST_F(IP500KBenchmarkGTest, IPScan) { + const char *table_name = "IP_500K"; + struct maat *maat_inst = IP500KBenchmarkGTest::_shared_maat_inst; + + int table_id = maat_get_table_id(maat_inst, table_name); + ASSERT_GT(table_id, 0); + + pthread_t threads[PERF_THREAD_NUM + 1]; + struct thread_param thread_params[PERF_THREAD_NUM + 1]; + int i = 0; + int *is_all_hit = NULL; + + for (i = 0; i < PERF_THREAD_NUM + 1; i++) { + thread_params[i].maat_inst = maat_inst; + thread_params[i].thread_id = i; + thread_params[i].table_name = table_name; + thread_params[i].test_count = MAX_SCAN_COUNT; + thread_params[i].rule_count = 500000; + thread_params[i].time_elapse_ms = 0; + thread_params[i].logger = logger; + + if (i < PERF_THREAD_NUM) { + pthread_create(&threads[i], NULL, perf_ip_scan_thread, thread_params+i); + } else { + thread_params[i].test_count = 0; + pthread_create(&threads[i], NULL, perf_ip_update_thread, thread_params+i); + } + } + + long long time_elapse_ms = 0; + long long scan_count = 0; + long long scan_per_second = 0; + for (i = 0; i < PERF_THREAD_NUM + 1; i++) { + pthread_join(threads[i], (void **)&is_all_hit); + time_elapse_ms += thread_params[i].time_elapse_ms; + scan_count += thread_params[i].test_count; + + EXPECT_EQ(*is_all_hit, 1); + *is_all_hit = 0; + free(is_all_hit); + } + scan_per_second = scan_count * 1000 / time_elapse_ms; + + log_info(maat_inst->logger, MODULE_BENCHMARK_GTEST, + "IP500KScan match rate on %d-threads speed %lld lookups/s/thread", + PERF_THREAD_NUM, scan_per_second); +} + +class IP1MBenchmarkGTest : public ::testing::Test +{ +protected: + static void SetUpTestCase() { + logger = log_handle_create("./benchmark_rs_gtest.log", 0); + generate_ip_sample("IP_1M", 1000000); + + FILE *fp = fopen("full_config_index.0000001", "w+"); + if (NULL == fp) { + log_error(g_logger, "open file %s failed", "full_config_index.0000001"); + return; + } + fprintf(fp, "IP_1M 1000000 ./IP_1M\n"); + fprintf(fp, "COMPILE_PERF 10 ./COMPILE_PERF\n"); + fprintf(fp, "GROUP2COMPILE_PERF 10 ./GROUP2COMPILE_PERF\n"); + fclose(fp); + + struct maat_options *opts = maat_options_new(); + maat_options_set_logger(opts, "./benchmark_rs_gtest.log", LOG_LEVEL_INFO); + maat_options_set_iris(opts, "./", "./"); + maat_options_set_rule_effect_interval_ms(opts, 1000); + maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM); + maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_RS); + _shared_maat_inst = maat_new(opts, table_info_path); + maat_options_free(opts); + } + + static void TearDownTestCase() { + maat_free(_shared_maat_inst); + log_handle_destroy(logger); + } + + static struct log_handle *logger; + static struct maat *_shared_maat_inst; +}; + +struct maat *IP1MBenchmarkGTest::_shared_maat_inst; +struct log_handle *IP1MBenchmarkGTest::logger; + +TEST_F(IP1MBenchmarkGTest, IPScan) { + const char *table_name = "IP_1M"; + struct maat *maat_inst = IP1MBenchmarkGTest::_shared_maat_inst; + + int table_id = maat_get_table_id(maat_inst, table_name); + ASSERT_GT(table_id, 0); + + pthread_t threads[PERF_THREAD_NUM + 1]; + struct thread_param thread_params[PERF_THREAD_NUM + 1]; + int i = 0; + int *is_all_hit = NULL; + + for (i = 0; i < PERF_THREAD_NUM + 1; i++) { + thread_params[i].maat_inst = maat_inst; + thread_params[i].thread_id = i; + thread_params[i].table_name = table_name; + thread_params[i].test_count = MAX_SCAN_COUNT; + thread_params[i].rule_count = 1000000; + thread_params[i].time_elapse_ms = 0; + thread_params[i].logger = logger; + + if (i < PERF_THREAD_NUM) { + pthread_create(&threads[i], NULL, perf_ip_scan_thread, thread_params+i); + } else { + thread_params[i].test_count = 0; + pthread_create(&threads[i], NULL, perf_ip_update_thread, thread_params+i); + } + } + + long long time_elapse_ms = 0; + long long scan_count = 0; + long long scan_per_second = 0; + for (i = 0; i < PERF_THREAD_NUM + 1; i++) { + pthread_join(threads[i], (void **)&is_all_hit); + time_elapse_ms += thread_params[i].time_elapse_ms; + scan_count += thread_params[i].test_count; + + EXPECT_EQ(*is_all_hit, 1); + *is_all_hit = 0; + free(is_all_hit); + } + scan_per_second = scan_count * 1000 / time_elapse_ms; + + log_info(maat_inst->logger, MODULE_BENCHMARK_GTEST, + "IP1MScan match rate on %d-threads speed %lld lookups/s/thread", + PERF_THREAD_NUM, scan_per_second); +} + +class IP5MBenchmarkGTest : public ::testing::Test +{ +protected: + static void SetUpTestCase() { + logger = log_handle_create("./benchmark_rs_gtest.log", 0); + generate_ip_sample("IP_5M", 5000000); + + FILE *fp = fopen("full_config_index.0000001", "w+"); + if (NULL == fp) { + log_error(g_logger, "open file %s failed", "full_config_index.0000001"); + return; + } + fprintf(fp, "IP_5M 5000000 ./IP_5M\n"); + fprintf(fp, "COMPILE_PERF 10 ./COMPILE_PERF\n"); + fprintf(fp, "GROUP2COMPILE_PERF 10 ./GROUP2COMPILE_PERF\n"); + fclose(fp); + + struct maat_options *opts = maat_options_new(); + maat_options_set_logger(opts, "./benchmark_rs_gtest.log", LOG_LEVEL_INFO); + maat_options_set_iris(opts, "./", "./"); + maat_options_set_rule_effect_interval_ms(opts, 1000); + maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM); + maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_RS); + _shared_maat_inst = maat_new(opts, table_info_path); + maat_options_free(opts); + } + + static void TearDownTestCase() { + maat_free(_shared_maat_inst); + log_handle_destroy(logger); + } + + static struct log_handle *logger; + static struct maat *_shared_maat_inst; +}; + +struct maat *IP5MBenchmarkGTest::_shared_maat_inst; +struct log_handle *IP5MBenchmarkGTest::logger; + +TEST_F(IP5MBenchmarkGTest, IPScan) { + const char *table_name = "IP_5M"; + struct maat *maat_inst = IP5MBenchmarkGTest::_shared_maat_inst; + + int table_id = maat_get_table_id(maat_inst, table_name); + ASSERT_GT(table_id, 0); + + pthread_t threads[PERF_THREAD_NUM + 1]; + struct thread_param thread_params[PERF_THREAD_NUM + 1]; + int i = 0; + int *is_all_hit = NULL; + + for (i = 0; i < PERF_THREAD_NUM + 1; i++) { + thread_params[i].maat_inst = maat_inst; + thread_params[i].thread_id = i; + thread_params[i].table_name = table_name; + thread_params[i].test_count = MAX_SCAN_COUNT; + thread_params[i].rule_count = 5000000; + thread_params[i].time_elapse_ms = 0; + thread_params[i].logger = logger; + + if (i < PERF_THREAD_NUM) { + pthread_create(&threads[i], NULL, perf_ip_scan_thread, thread_params+i); + } else { + thread_params[i].test_count = 0; + pthread_create(&threads[i], NULL, perf_ip_update_thread, thread_params+i); + } + } + + long long time_elapse_ms = 0; + long long scan_count = 0; + long long scan_per_second = 0; + for (i = 0; i < PERF_THREAD_NUM + 1; i++) { + pthread_join(threads[i], (void **)&is_all_hit); + time_elapse_ms += thread_params[i].time_elapse_ms; + scan_count += thread_params[i].test_count; + + EXPECT_EQ(*is_all_hit, 1); + *is_all_hit = 0; + free(is_all_hit); + } + scan_per_second = scan_count * 1000 / time_elapse_ms; + + log_info(maat_inst->logger, MODULE_BENCHMARK_GTEST, + "IP5MScan match rate on %d-threads speed %lld lookups/s/thread", + PERF_THREAD_NUM, scan_per_second); +} + +class IP10MBenchmarkGTest : public ::testing::Test +{ +protected: + static void SetUpTestCase() { + logger = log_handle_create("./benchmark_rs_gtest.log", 0); + generate_ip_sample("IP_10M", 10000000); + + FILE *fp = fopen("full_config_index.0000001", "w+"); + if (NULL == fp) { + log_error(g_logger, "open file %s failed", "full_config_index.0000001"); + return; + } + fprintf(fp, "IP_10M 10000000 ./IP_10M\n"); + fprintf(fp, "COMPILE_PERF 10 ./COMPILE_PERF\n"); + fprintf(fp, "GROUP2COMPILE_PERF 10 ./GROUP2COMPILE_PERF\n"); + fclose(fp); + + struct maat_options *opts = maat_options_new(); + maat_options_set_logger(opts, "./benchmark_rs_gtest.log", LOG_LEVEL_INFO); + maat_options_set_iris(opts, "./", "./"); + maat_options_set_rule_effect_interval_ms(opts, 1000); + maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM); + maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_RS); + _shared_maat_inst = maat_new(opts, table_info_path); + maat_options_free(opts); + } + + static void TearDownTestCase() { + maat_free(_shared_maat_inst); + log_handle_destroy(logger); + } + + static struct log_handle *logger; + static struct maat *_shared_maat_inst; +}; + +struct maat *IP10MBenchmarkGTest::_shared_maat_inst; +struct log_handle *IP10MBenchmarkGTest::logger; + +TEST_F(IP10MBenchmarkGTest, IPScan) { + const char *table_name = "IP_10M"; + struct maat *maat_inst = IP10MBenchmarkGTest::_shared_maat_inst; + + int table_id = maat_get_table_id(maat_inst, table_name); + ASSERT_GT(table_id, 0); + + pthread_t threads[PERF_THREAD_NUM + 1]; + struct thread_param thread_params[PERF_THREAD_NUM + 1]; + int i = 0; + int *is_all_hit = NULL; + + for (i = 0; i < PERF_THREAD_NUM + 1; i++) { + thread_params[i].maat_inst = maat_inst; + thread_params[i].thread_id = i; + thread_params[i].table_name = table_name; + thread_params[i].test_count = MAX_SCAN_COUNT; + thread_params[i].rule_count = 10000000; + thread_params[i].time_elapse_ms = 0; + thread_params[i].logger = logger; + + if (i < PERF_THREAD_NUM) { + pthread_create(&threads[i], NULL, perf_ip_scan_thread, thread_params+i); + } else { + thread_params[i].test_count = 0; + pthread_create(&threads[i], NULL, perf_ip_update_thread, thread_params+i); + } + } + + long long time_elapse_ms = 0; + long long scan_count = 0; + long long scan_per_second = 0; + for (i = 0; i < PERF_THREAD_NUM + 1; i++) { + pthread_join(threads[i], (void **)&is_all_hit); + time_elapse_ms += thread_params[i].time_elapse_ms; + scan_count += thread_params[i].test_count; + + EXPECT_EQ(*is_all_hit, 1); + *is_all_hit = 0; + free(is_all_hit); + } + scan_per_second = scan_count * 1000 / time_elapse_ms; + + log_info(maat_inst->logger, MODULE_BENCHMARK_GTEST, + "IP10MScan match rate on %d-threads speed %lld lookups/s/thread", + PERF_THREAD_NUM, scan_per_second); +} + +class Integer1KBenchmarkGTest : public ::testing::Test +{ +protected: + static void SetUpTestCase() { + logger = log_handle_create("./benchmark_rs_gtest.log", 0); + generate_integer_sample("INTEGER_1K", 1000); + + FILE *fp = fopen("full_config_index.0000001", "w+"); + if (NULL == fp) { + log_error(g_logger, "open file %s failed", "full_config_index.0000001"); + return; + } + fprintf(fp, "INTEGER_1K 1000 ./INTEGER_1K\n"); + fprintf(fp, "COMPILE_PERF 10 ./COMPILE_PERF\n"); + fprintf(fp, "GROUP2COMPILE_PERF 10 ./GROUP2COMPILE_PERF\n"); + fclose(fp); + + struct maat_options *opts = maat_options_new(); + maat_options_set_logger(opts, "./benchmark_rs_gtest.log", LOG_LEVEL_INFO); + maat_options_set_iris(opts, "./", "./"); + maat_options_set_rule_effect_interval_ms(opts, 1000); + maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM); + maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_RS); + _shared_maat_inst = maat_new(opts, table_info_path); + maat_options_free(opts); + } + + static void TearDownTestCase() { + maat_free(_shared_maat_inst); + log_handle_destroy(logger); + } + + static struct log_handle *logger; + static struct maat *_shared_maat_inst; +}; + +struct maat *Integer1KBenchmarkGTest::_shared_maat_inst; +struct log_handle *Integer1KBenchmarkGTest::logger; + +TEST_F(Integer1KBenchmarkGTest, IntegerScan) { + const char *table_name = "INTEGER_1K"; + struct maat *maat_inst = Integer1KBenchmarkGTest::_shared_maat_inst; + + int table_id = maat_get_table_id(maat_inst, table_name); + ASSERT_GT(table_id, 0); + + pthread_t threads[PERF_THREAD_NUM + 1]; + struct thread_param thread_params[PERF_THREAD_NUM + 1]; + int i = 0; + int *is_all_hit = NULL; + + for (i = 0; i < PERF_THREAD_NUM + 1; i++) { + thread_params[i].maat_inst = maat_inst; + thread_params[i].thread_id = i; + thread_params[i].table_name = table_name; + thread_params[i].test_count = MAX_SCAN_COUNT; + thread_params[i].rule_count = 1000; + thread_params[i].time_elapse_ms = 0; + thread_params[i].logger = logger; + + if (i < PERF_THREAD_NUM) { + pthread_create(&threads[i], NULL, perf_integer_scan_thread, thread_params+i); + } else { + thread_params[i].test_count = 0; + pthread_create(&threads[i], NULL, perf_integer_update_thread, thread_params+i); + } + } + + long long time_elapse_ms = 0; + long long scan_count = 0; + long long scan_per_second = 0; + for (i = 0; i < PERF_THREAD_NUM + 1; i++) { + pthread_join(threads[i], (void **)&is_all_hit); + time_elapse_ms += thread_params[i].time_elapse_ms; + scan_count += thread_params[i].test_count; + + EXPECT_EQ(*is_all_hit, 1); + *is_all_hit = 0; + free(is_all_hit); + } + scan_per_second = scan_count * 1000 / time_elapse_ms; + + log_info(maat_inst->logger, MODULE_BENCHMARK_GTEST, + "Integer1KScan match rate on %d-threads speed %lld lookups/s/thread", + PERF_THREAD_NUM, scan_per_second); +} + +class Integer5KBenchmarkGTest : public ::testing::Test +{ +protected: + static void SetUpTestCase() { + logger = log_handle_create("./benchmark_rs_gtest.log", 0); + generate_integer_sample("INTEGER_5K", 5000); + + FILE *fp = fopen("full_config_index.0000001", "w+"); + if (NULL == fp) { + log_error(g_logger, "open file %s failed", "full_config_index.0000001"); + return; + } + fprintf(fp, "INTEGER_5K 5000 ./INTEGER_5K\n"); + fprintf(fp, "COMPILE_PERF 10 ./COMPILE_PERF\n"); + fprintf(fp, "GROUP2COMPILE_PERF 10 ./GROUP2COMPILE_PERF\n"); + fclose(fp); + + struct maat_options *opts = maat_options_new(); + maat_options_set_logger(opts, "./benchmark_rs_gtest.log", LOG_LEVEL_INFO); + maat_options_set_iris(opts, "./", "./"); + maat_options_set_rule_effect_interval_ms(opts, 1000); + maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM); + maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_RS); + _shared_maat_inst = maat_new(opts, table_info_path); + maat_options_free(opts); + } + + static void TearDownTestCase() { + maat_free(_shared_maat_inst); + log_handle_destroy(logger); + } + + static struct log_handle *logger; + static struct maat *_shared_maat_inst; +}; + +struct maat *Integer5KBenchmarkGTest::_shared_maat_inst; +struct log_handle *Integer5KBenchmarkGTest::logger; + +TEST_F(Integer5KBenchmarkGTest, IntegerScan) { + const char *table_name = "INTEGER_5K"; + struct maat *maat_inst = Integer5KBenchmarkGTest::_shared_maat_inst; + + int table_id = maat_get_table_id(maat_inst, table_name); + ASSERT_GT(table_id, 0); + + pthread_t threads[PERF_THREAD_NUM + 1]; + struct thread_param thread_params[PERF_THREAD_NUM + 1]; + int i = 0; + int *is_all_hit = NULL; + + for (i = 0; i < PERF_THREAD_NUM + 1; i++) { + thread_params[i].maat_inst = maat_inst; + thread_params[i].thread_id = i; + thread_params[i].table_name = table_name; + thread_params[i].test_count = MAX_SCAN_COUNT; + thread_params[i].rule_count = 5000; + thread_params[i].time_elapse_ms = 0; + thread_params[i].logger = logger; + + if (i < PERF_THREAD_NUM) { + pthread_create(&threads[i], NULL, perf_integer_scan_thread, thread_params+i); + } else { + thread_params[i].test_count = 0; + pthread_create(&threads[i], NULL, perf_integer_update_thread, thread_params+i); + } + } + + long long time_elapse_ms = 0; + long long scan_count = 0; + long long scan_per_second = 0; + for (i = 0; i < PERF_THREAD_NUM + 1; i++) { + pthread_join(threads[i], (void **)&is_all_hit); + time_elapse_ms += thread_params[i].time_elapse_ms; + scan_count += thread_params[i].test_count; + + EXPECT_EQ(*is_all_hit, 1); + *is_all_hit = 0; + free(is_all_hit); + } + scan_per_second = scan_count * 1000 / time_elapse_ms; + + log_info(maat_inst->logger, MODULE_BENCHMARK_GTEST, + "Integer5KScan match rate on %d-threads speed %lld lookups/s/thread", + PERF_THREAD_NUM, scan_per_second); +} + +class Integer10KBenchmarkGTest : public ::testing::Test +{ +protected: + static void SetUpTestCase() { + logger = log_handle_create("./benchmark_rs_gtest.log", 0); + generate_integer_sample("INTEGER_10K", 10000); + + FILE *fp = fopen("full_config_index.0000001", "w+"); + if (NULL == fp) { + log_error(g_logger, "open file %s failed", "full_config_index.0000001"); + return; + } + fprintf(fp, "INTEGER_10K 10000 ./INTEGER_10K\n"); + fprintf(fp, "COMPILE_PERF 10 ./COMPILE_PERF\n"); + fprintf(fp, "GROUP2COMPILE_PERF 10 ./GROUP2COMPILE_PERF\n"); + fclose(fp); + + struct maat_options *opts = maat_options_new(); + maat_options_set_logger(opts, "./benchmark_rs_gtest.log", LOG_LEVEL_INFO); + maat_options_set_iris(opts, "./", "./"); + maat_options_set_rule_effect_interval_ms(opts, 1000); + maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM); + maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_RS); + _shared_maat_inst = maat_new(opts, table_info_path); + maat_options_free(opts); + } + + static void TearDownTestCase() { + maat_free(_shared_maat_inst); + log_handle_destroy(logger); + } + + static struct log_handle *logger; + static struct maat *_shared_maat_inst; +}; + +struct maat *Integer10KBenchmarkGTest::_shared_maat_inst; +struct log_handle *Integer10KBenchmarkGTest::logger; + +TEST_F(Integer10KBenchmarkGTest, IntegerScan) { + const char *table_name = "INTEGER_10K"; + struct maat *maat_inst = Integer10KBenchmarkGTest::_shared_maat_inst; + + int table_id = maat_get_table_id(maat_inst, table_name); + ASSERT_GT(table_id, 0); + + pthread_t threads[PERF_THREAD_NUM + 1]; + struct thread_param thread_params[PERF_THREAD_NUM + 1]; + int i = 0; + int *is_all_hit = NULL; + + for (i = 0; i < PERF_THREAD_NUM + 1; i++) { + thread_params[i].maat_inst = maat_inst; + thread_params[i].thread_id = i; + thread_params[i].table_name = table_name; + thread_params[i].test_count = MAX_SCAN_COUNT; + thread_params[i].rule_count = 10000; + thread_params[i].time_elapse_ms = 0; + thread_params[i].logger = logger; + + if (i < PERF_THREAD_NUM) { + pthread_create(&threads[i], NULL, perf_integer_scan_thread, thread_params+i); + } else { + thread_params[i].test_count = 0; + pthread_create(&threads[i], NULL, perf_integer_update_thread, thread_params+i); + } + } + + long long time_elapse_ms = 0; + long long scan_count = 0; + long long scan_per_second = 0; + for (i = 0; i < PERF_THREAD_NUM + 1; i++) { + pthread_join(threads[i], (void **)&is_all_hit); + time_elapse_ms += thread_params[i].time_elapse_ms; + scan_count += thread_params[i].test_count; + + EXPECT_EQ(*is_all_hit, 1); + *is_all_hit = 0; + free(is_all_hit); + } + scan_per_second = scan_count * 1000 / time_elapse_ms; + + log_info(maat_inst->logger, MODULE_BENCHMARK_GTEST, + "Integer10KScan match rate on %d-threads speed %lld lookups/s/thread", + PERF_THREAD_NUM, scan_per_second); +} + +class Flag1KBenchmarkGTest : public ::testing::Test +{ +protected: + static void SetUpTestCase() { + logger = log_handle_create("./benchmark_rs_gtest.log", 0); + generate_flag_sample("FLAG_1K", 1000); + + FILE *fp = fopen("full_config_index.0000001", "w+"); + if (NULL == fp) { + log_error(g_logger, "open file %s failed", "full_config_index.0000001"); + return; + } + fprintf(fp, "FLAG_1K 1000 ./FLAG_1K\n"); + fprintf(fp, "COMPILE_PERF 10 ./COMPILE_PERF\n"); + fprintf(fp, "GROUP2COMPILE_PERF 10 ./GROUP2COMPILE_PERF\n"); + fclose(fp); + + struct maat_options *opts = maat_options_new(); + maat_options_set_logger(opts, "./benchmark_rs_gtest.log", LOG_LEVEL_INFO); + maat_options_set_iris(opts, "./", "./"); + maat_options_set_rule_effect_interval_ms(opts, 1000); + maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM); + maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_RS); + _shared_maat_inst = maat_new(opts, table_info_path); + maat_options_free(opts); + } + + static void TearDownTestCase() { + maat_free(_shared_maat_inst); + log_handle_destroy(logger); + } + + static struct log_handle *logger; + static struct maat *_shared_maat_inst; +}; + +struct maat *Flag1KBenchmarkGTest::_shared_maat_inst; +struct log_handle *Flag1KBenchmarkGTest::logger; + +TEST_F(Flag1KBenchmarkGTest, FlagScan) { + const char *table_name = "FLAG_1K"; + struct maat *maat_inst = Flag1KBenchmarkGTest::_shared_maat_inst; + + int table_id = maat_get_table_id(maat_inst, table_name); + ASSERT_GT(table_id, 0); + + pthread_t threads[PERF_THREAD_NUM + 1]; + struct thread_param thread_params[PERF_THREAD_NUM + 1]; + int i = 0; + int *is_all_hit = NULL; + + for (i = 0; i < PERF_THREAD_NUM + 1; i++) { + thread_params[i].maat_inst = maat_inst; + thread_params[i].thread_id = i; + thread_params[i].table_name = table_name; + thread_params[i].test_count = MAX_SCAN_COUNT; + thread_params[i].rule_count = 1000; + thread_params[i].time_elapse_ms = 0; + thread_params[i].logger = logger; + + if (i < PERF_THREAD_NUM) { + pthread_create(&threads[i], NULL, perf_flag_scan_thread, thread_params+i); + } else { + thread_params[i].test_count = 0; + pthread_create(&threads[i], NULL, perf_flag_update_thread, thread_params+i); + } + } + + long long time_elapse_ms = 0; + long long scan_count = 0; + long long scan_per_second = 0; + for (i = 0; i < PERF_THREAD_NUM + 1; i++) { + pthread_join(threads[i], (void **)&is_all_hit); + time_elapse_ms += thread_params[i].time_elapse_ms; + scan_count += thread_params[i].test_count; + + EXPECT_EQ(*is_all_hit, 1); + *is_all_hit = 0; + free(is_all_hit); + } + scan_per_second = scan_count * 1000 / time_elapse_ms; + + log_info(maat_inst->logger, MODULE_BENCHMARK_GTEST, + "Flag1KScan match rate on %d-threads speed %lld lookups/s/thread", + PERF_THREAD_NUM, scan_per_second); +} + +class Flag5KBenchmarkGTest : public ::testing::Test +{ +protected: + static void SetUpTestCase() { + logger = log_handle_create("./benchmark_rs_gtest.log", 0); + generate_flag_sample("FLAG_5K", 5000); + + FILE *fp = fopen("full_config_index.0000001", "w+"); + if (NULL == fp) { + log_error(g_logger, "open file %s failed", "full_config_index.0000001"); + return; + } + fprintf(fp, "FLAG_5K 5000 ./FLAG_5K\n"); + fprintf(fp, "COMPILE_PERF 10 ./COMPILE_PERF\n"); + fprintf(fp, "GROUP2COMPILE_PERF 10 ./GROUP2COMPILE_PERF\n"); + fclose(fp); + + struct maat_options *opts = maat_options_new(); + maat_options_set_logger(opts, "./benchmark_rs_gtest.log", LOG_LEVEL_INFO); + maat_options_set_iris(opts, "./", "./"); + maat_options_set_rule_effect_interval_ms(opts, 1000); + maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM); + maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_RS); + _shared_maat_inst = maat_new(opts, table_info_path); + maat_options_free(opts); + } + + static void TearDownTestCase() { + maat_free(_shared_maat_inst); + log_handle_destroy(logger); + } + + static struct log_handle *logger; + static struct maat *_shared_maat_inst; +}; + +struct maat *Flag5KBenchmarkGTest::_shared_maat_inst; +struct log_handle *Flag5KBenchmarkGTest::logger; + +TEST_F(Flag5KBenchmarkGTest, FlagScan) { + const char *table_name = "FLAG_5K"; + struct maat *maat_inst = Flag5KBenchmarkGTest::_shared_maat_inst; + + int table_id = maat_get_table_id(maat_inst, table_name); + ASSERT_GT(table_id, 0); + + pthread_t threads[PERF_THREAD_NUM + 1]; + struct thread_param thread_params[PERF_THREAD_NUM + 1]; + int i = 0; + int *is_all_hit = NULL; + + for (i = 0; i < PERF_THREAD_NUM + 1; i++) { + thread_params[i].maat_inst = maat_inst; + thread_params[i].thread_id = i; + thread_params[i].table_name = table_name; + thread_params[i].test_count = MAX_SCAN_COUNT; + thread_params[i].rule_count = 5000; + thread_params[i].time_elapse_ms = 0; + thread_params[i].logger = logger; + + if (i < PERF_THREAD_NUM) { + pthread_create(&threads[i], NULL, perf_flag_scan_thread, thread_params+i); + } else { + thread_params[i].test_count = 0; + pthread_create(&threads[i], NULL, perf_flag_update_thread, thread_params+i); + } + } + + long long time_elapse_ms = 0; + long long scan_count = 0; + long long scan_per_second = 0; + for (i = 0; i < PERF_THREAD_NUM + 1; i++) { + pthread_join(threads[i], (void **)&is_all_hit); + time_elapse_ms += thread_params[i].time_elapse_ms; + scan_count += thread_params[i].test_count; + + EXPECT_EQ(*is_all_hit, 1); + *is_all_hit = 0; + free(is_all_hit); + } + scan_per_second = scan_count * 1000 / time_elapse_ms; + + log_info(maat_inst->logger, MODULE_BENCHMARK_GTEST, + "Flag5KScan match rate on %d-threads speed %lld lookups/s/thread", + PERF_THREAD_NUM, scan_per_second); +} + +class Flag10KBenchmarkGTest : public ::testing::Test +{ +protected: + static void SetUpTestCase() { + logger = log_handle_create("./benchmark_rs_gtest.log", 0); + generate_flag_sample("FLAG_10K", 10000); + + FILE *fp = fopen("full_config_index.0000001", "w+"); + if (NULL == fp) { + log_error(g_logger, "open file %s failed", "full_config_index.0000001"); + return; + } + fprintf(fp, "FLAG_10K 10000 ./FLAG_10K\n"); + fprintf(fp, "COMPILE_PERF 10 ./COMPILE_PERF\n"); + fprintf(fp, "GROUP2COMPILE_PERF 10 ./GROUP2COMPILE_PERF\n"); + fclose(fp); + + struct maat_options *opts = maat_options_new(); + maat_options_set_logger(opts, "./benchmark_rs_gtest.log", LOG_LEVEL_INFO); + maat_options_set_iris(opts, "./", "./"); + maat_options_set_rule_effect_interval_ms(opts, 1000); + maat_options_set_caller_thread_number(opts, PERF_THREAD_NUM); + maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_RS); + _shared_maat_inst = maat_new(opts, table_info_path); + maat_options_free(opts); + } + + static void TearDownTestCase() { + maat_free(_shared_maat_inst); + log_handle_destroy(logger); + } + + static struct log_handle *logger; + static struct maat *_shared_maat_inst; +}; + +struct maat *Flag10KBenchmarkGTest::_shared_maat_inst; +struct log_handle *Flag10KBenchmarkGTest::logger; + +TEST_F(Flag10KBenchmarkGTest, FlagScan) { + const char *table_name = "FLAG_10K"; + struct maat *maat_inst = Flag10KBenchmarkGTest::_shared_maat_inst; + + int table_id = maat_get_table_id(maat_inst, table_name); + ASSERT_GT(table_id, 0); + + pthread_t threads[PERF_THREAD_NUM + 1]; + struct thread_param thread_params[PERF_THREAD_NUM + 1]; + int i = 0; + int *is_all_hit = NULL; + + for (i = 0; i < PERF_THREAD_NUM + 1; i++) { + thread_params[i].maat_inst = maat_inst; + thread_params[i].thread_id = i; + thread_params[i].table_name = table_name; + thread_params[i].test_count = MAX_SCAN_COUNT; + thread_params[i].rule_count = 10000; + thread_params[i].time_elapse_ms = 0; + thread_params[i].logger = logger; + + if (i < PERF_THREAD_NUM) { + pthread_create(&threads[i], NULL, perf_flag_scan_thread, thread_params+i); + } else { + thread_params[i].test_count = 0; + pthread_create(&threads[i], NULL, perf_flag_update_thread, thread_params+i); + } + } + + long long time_elapse_ms = 0; + long long scan_count = 0; + long long scan_per_second = 0; + for (i = 0; i < PERF_THREAD_NUM + 1; i++) { + pthread_join(threads[i], (void **)&is_all_hit); + time_elapse_ms += thread_params[i].time_elapse_ms; + scan_count += thread_params[i].test_count; + + EXPECT_EQ(*is_all_hit, 1); + *is_all_hit = 0; + free(is_all_hit); + } + scan_per_second = scan_count * 1000 / time_elapse_ms; + + log_info(maat_inst->logger, MODULE_BENCHMARK_GTEST, + "Flag10KScan match rate on %d-threads speed %lld lookups/s/thread", + PERF_THREAD_NUM, scan_per_second); +} + +int main(int argc, char ** argv) +{ + int ret=0; + ::testing::InitGoogleTest(&argc, argv); + g_logger = log_handle_create("./benchmark_rs_gtest.log", 0); + + generate_compile_sample("COMPILE_PERF", 10); + generate_group2compile_sample("GROUP2COMPILE_PERF", 10); + + ret=RUN_ALL_TESTS(); + + log_handle_destroy(g_logger); + return ret; +} diff --git a/test/benchmark/benchmark_table_info.conf b/test/benchmark/benchmark_table_info.conf new file mode 100644 index 0000000..b01e64b --- /dev/null +++ b/test/benchmark/benchmark_table_info.conf @@ -0,0 +1,579 @@ +[ + { + "table_id":1, + "table_name":"EXPR_LITERAL_1K", + "table_type":"expr", + "valid_column":7, + "custom": { + "item_id":1, + "group_id":2, + "keywords":3, + "expr_type":4, + "match_method":5, + "is_hexbin":6 + } + }, + { + "table_id":2, + "table_name":"EXPR_LITERAL_5K", + "table_type":"expr", + "valid_column":7, + "custom": { + "item_id":1, + "group_id":2, + "keywords":3, + "expr_type":4, + "match_method":5, + "is_hexbin":6 + } + }, + { + "table_id":3, + "table_name":"EXPR_LITERAL_10K", + "table_type":"expr", + "valid_column":7, + "custom": { + "item_id":1, + "group_id":2, + "keywords":3, + "expr_type":4, + "match_method":5, + "is_hexbin":6 + } + }, + { + "table_id":4, + "table_name":"EXPR_LITERAL_50K", + "table_type":"expr", + "valid_column":7, + "custom": { + "item_id":1, + "group_id":2, + "keywords":3, + "expr_type":4, + "match_method":5, + "is_hexbin":6 + } + }, + { + "table_id":5, + "table_name":"EXPR_LITERAL_100K", + "table_type":"expr", + "valid_column":7, + "custom": { + "item_id":1, + "group_id":2, + "keywords":3, + "expr_type":4, + "match_method":5, + "is_hexbin":6 + } + }, + { + "table_id":6, + "table_name":"EXPR_LITERAL_500K", + "table_type":"expr", + "valid_column":7, + "custom": { + "item_id":1, + "group_id":2, + "keywords":3, + "expr_type":4, + "match_method":5, + "is_hexbin":6 + } + }, + { + "table_id":7, + "table_name":"EXPR_LITERAL_1M", + "table_type":"expr", + "valid_column":7, + "custom": { + "item_id":1, + "group_id":2, + "keywords":3, + "expr_type":4, + "match_method":5, + "is_hexbin":6 + } + }, + { + "table_id":8, + "table_name":"EXPR_LITERAL_2M", + "table_type":"expr", + "valid_column":7, + "custom": { + "item_id":1, + "group_id":2, + "keywords":3, + "expr_type":4, + "match_method":5, + "is_hexbin":6 + } + }, + { + "table_id":9, + "table_name":"EXPR_LITERAL_5M", + "table_type":"expr", + "valid_column":7, + "custom": { + "item_id":1, + "group_id":2, + "keywords":3, + "expr_type":4, + "match_method":5, + "is_hexbin":6 + } + }, + { + "table_id":10, + "table_name":"IP_1K", + "table_type":"ip_plus", + "valid_column":11, + "custom": { + "item_id":1, + "group_id":2, + "addr_type":3, + "addr_format":4, + "ip1":5, + "ip2":6, + "port_format":7, + "port1":8, + "port2":9, + "protocol":10 + } + }, + { + "table_id":11, + "table_name":"IP_5K", + "table_type":"ip_plus", + "valid_column":11, + "custom": { + "item_id":1, + "group_id":2, + "addr_type":3, + "addr_format":4, + "ip1":5, + "ip2":6, + "port_format":7, + "port1":8, + "port2":9, + "protocol":10 + } + }, + { + "table_id":12, + "table_name":"IP_10K", + "table_type":"ip_plus", + "valid_column":11, + "custom": { + "item_id":1, + "group_id":2, + "addr_type":3, + "addr_format":4, + "ip1":5, + "ip2":6, + "port_format":7, + "port1":8, + "port2":9, + "protocol":10 + } + }, + { + "table_id":13, + "table_name":"IP_50K", + "table_type":"ip_plus", + "valid_column":11, + "custom": { + "item_id":1, + "group_id":2, + "addr_type":3, + "addr_format":4, + "ip1":5, + "ip2":6, + "port_format":7, + "port1":8, + "port2":9, + "protocol":10 + } + }, + { + "table_id":14, + "table_name":"IP_100K", + "table_type":"ip_plus", + "valid_column":11, + "custom": { + "item_id":1, + "group_id":2, + "addr_type":3, + "addr_format":4, + "ip1":5, + "ip2":6, + "port_format":7, + "port1":8, + "port2":9, + "protocol":10 + } + }, + { + "table_id":15, + "table_name":"IP_500K", + "table_type":"ip_plus", + "valid_column":11, + "custom": { + "item_id":1, + "group_id":2, + "addr_type":3, + "addr_format":4, + "ip1":5, + "ip2":6, + "port_format":7, + "port1":8, + "port2":9, + "protocol":10 + } + }, + { + "table_id":16, + "table_name":"IP_1M", + "table_type":"ip_plus", + "valid_column":11, + "custom": { + "item_id":1, + "group_id":2, + "addr_type":3, + "addr_format":4, + "ip1":5, + "ip2":6, + "port_format":7, + "port1":8, + "port2":9, + "protocol":10 + } + }, + { + "table_id":17, + "table_name":"IP_2M", + "table_type":"ip_plus", + "valid_column":11, + "custom": { + "item_id":1, + "group_id":2, + "addr_type":3, + "addr_format":4, + "ip1":5, + "ip2":6, + "port_format":7, + "port1":8, + "port2":9, + "protocol":10 + } + }, + { + "table_id":18, + "table_name":"IP_5M", + "table_type":"ip_plus", + "valid_column":11, + "custom": { + "item_id":1, + "group_id":2, + "addr_type":3, + "addr_format":4, + "ip1":5, + "ip2":6, + "port_format":7, + "port1":8, + "port2":9, + "protocol":10 + } + }, + { + "table_id":19, + "table_name":"IP_10M", + "table_type":"ip_plus", + "valid_column":11, + "custom": { + "item_id":1, + "group_id":2, + "addr_type":3, + "addr_format":4, + "ip1":5, + "ip2":6, + "port_format":7, + "port1":8, + "port2":9, + "protocol":10 + } + }, + { + "table_id":20, + "table_name":"INTEGER_1K", + "table_type":"intval", + "valid_column":5, + "custom": { + "item_id":1, + "group_id":2, + "low_bound":3, + "up_bound":4 + } + }, + { + "table_id":21, + "table_name":"INTEGER_5K", + "table_type":"intval", + "valid_column":5, + "custom": { + "item_id":1, + "group_id":2, + "low_bound":3, + "up_bound":4 + } + }, + { + "table_id":22, + "table_name":"INTEGER_10K", + "table_type":"intval", + "valid_column":5, + "custom": { + "item_id":1, + "group_id":2, + "low_bound":3, + "up_bound":4 + } + }, + { + "table_id":23, + "table_name":"INTEGER_50K", + "table_type":"intval", + "valid_column":5, + "custom": { + "item_id":1, + "group_id":2, + "low_bound":3, + "up_bound":4 + } + }, + { + "table_id":24, + "table_name":"INTEGER_100K", + "table_type":"intval", + "valid_column":5, + "custom": { + "item_id":1, + "group_id":2, + "low_bound":3, + "up_bound":4 + } + }, + { + "table_id":25, + "table_name":"FLAG_1K", + "table_type":"flag", + "valid_column":5, + "custom": { + "item_id":1, + "group_id":2, + "flag":3, + "flag_mask":4 + } + }, + { + "table_id":26, + "table_name":"FLAG_5K", + "table_type":"flag", + "valid_column":5, + "custom": { + "item_id":1, + "group_id":2, + "flag":3, + "flag_mask":4 + } + }, + { + "table_id":27, + "table_name":"FLAG_10K", + "table_type":"flag", + "valid_column":5, + "custom": { + "item_id":1, + "group_id":2, + "flag":3, + "flag_mask":4 + } + }, + { + "table_id":28, + "table_name":"FLAG_50K", + "table_type":"flag", + "valid_column":5, + "custom": { + "item_id":1, + "group_id":2, + "flag":3, + "flag_mask":4 + } + }, + { + "table_id":29, + "table_name":"FLAG_100K", + "table_type":"flag", + "valid_column":5, + "custom": { + "item_id":1, + "group_id":2, + "flag":3, + "flag_mask":4 + } + }, + { + "table_id":30, + "table_name":"STREAM_1K", + "table_type":"expr", + "valid_column":7, + "custom": { + "item_id":1, + "group_id":2, + "keywords":3, + "expr_type":4, + "match_method":5, + "is_hexbin":6 + } + }, + { + "table_id":31, + "table_name":"STREAM_5K", + "table_type":"expr", + "valid_column":7, + "custom": { + "item_id":1, + "group_id":2, + "keywords":3, + "expr_type":4, + "match_method":5, + "is_hexbin":6 + } + }, + { + "table_id":32, + "table_name":"STREAM_10K", + "table_type":"expr", + "valid_column":7, + "custom": { + "item_id":1, + "group_id":2, + "keywords":3, + "expr_type":4, + "match_method":5, + "is_hexbin":6 + } + }, + { + "table_id":33, + "table_name":"STREAM_50K", + "table_type":"expr", + "valid_column":7, + "custom": { + "item_id":1, + "group_id":2, + "keywords":3, + "expr_type":4, + "match_method":5, + "is_hexbin":6 + } + }, + { + "table_id":34, + "table_name":"STREAM_100K", + "table_type":"expr", + "valid_column":7, + "custom": { + "item_id":1, + "group_id":2, + "keywords":3, + "expr_type":4, + "match_method":5, + "is_hexbin":6 + } + }, + { + "table_id":35, + "table_name":"STREAM_500K", + "table_type":"expr", + "valid_column":7, + "custom": { + "item_id":1, + "group_id":2, + "keywords":3, + "expr_type":4, + "match_method":5, + "is_hexbin":6 + } + }, + { + "table_id":36, + "table_name":"STREAM_1M", + "table_type":"expr", + "valid_column":7, + "custom": { + "item_id":1, + "group_id":2, + "keywords":3, + "expr_type":4, + "match_method":5, + "is_hexbin":6 + } + }, + { + "table_id":37, + "table_name":"STREAM_2M", + "table_type":"expr", + "valid_column":7, + "custom": { + "item_id":1, + "group_id":2, + "keywords":3, + "expr_type":4, + "match_method":5, + "is_hexbin":6 + } + }, + { + "table_id":38, + "table_name":"STREAM_5M", + "table_type":"expr", + "valid_column":7, + "custom": { + "item_id":1, + "group_id":2, + "keywords":3, + "expr_type":4, + "match_method":5, + "is_hexbin":6 + } + }, + { + "table_id":39, + "table_name":"COMPILE_PERF", + "table_type":"compile", + "valid_column":8, + "custom": { + "compile_id":1, + "tags":6, + "clause_num":9 + } + }, + { + "table_id":40, + "table_name":"GROUP2COMPILE_PERF", + "table_type":"group2compile", + "associated_compile_table_id":39, + "valid_column":3, + "custom": { + "group_id":1, + "compile_id":2, + "not_flag":4, + "virtual_table_name":5, + "clause_index":6 + } + } +] \ No newline at end of file diff --git a/test/maat_framework_gtest.cpp b/test/maat_framework_gtest.cpp index a0171e6..f5ebf66 100644 --- a/test/maat_framework_gtest.cpp +++ b/test/maat_framework_gtest.cpp @@ -767,7 +767,7 @@ protected: maat_options_set_stat_file(opts, "./stat.log"); maat_options_set_logger(opts, "./maat_framework_gtest.log", LOG_LEVEL_INFO); maat_options_set_accept_tags(opts, accept_tags); - maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_RS); + //maat_options_set_expr_engine(opts, MAAT_EXPR_ENGINE_HS); //default _shared_maat_inst = maat_new(opts, table_info_path); maat_options_free(opts); @@ -1952,7 +1952,7 @@ TEST_F(MaatRsStringScan, StreamScanUTF8) { long long results[ARRAY_SIZE] = {0}; size_t n_hit_result = 0; int thread_id = 0; - char scan_data[2048]; + char scan_data[1500]; struct maat *maat_inst = MaatRsStringScan::_shared_maat_inst; struct maat_state *state = maat_state_new(maat_inst, thread_id); @@ -1968,6 +1968,7 @@ TEST_F(MaatRsStringScan, StreamScanUTF8) { int pass_flag = 0; while (0 == feof(fp)) { size_t read_size = fread(scan_data, 1, sizeof(scan_data), fp); + //read_size can't exceed 1500 int ret = maat_stream_scan(sp, scan_data, read_size, results, ARRAY_SIZE, &n_hit_result, state); if (ret == MAAT_SCAN_HIT) { diff --git a/test/maat_framework_perf_gtest.cpp b/test/maat_framework_perf_gtest.cpp index 0f13a7f..f715181 100644 --- a/test/maat_framework_perf_gtest.cpp +++ b/test/maat_framework_perf_gtest.cpp @@ -256,8 +256,54 @@ static int ip_table_set_line(struct maat *maat_inst, const char *table_name, enu return maat_cmd_set_line(maat_inst, &line_rule); } -void test_add_expr_command(struct maat *maat_inst, const char *table_name, - const char *keywords) +static int integer_table_set_line(struct maat *maat_inst, const char *table_name, + enum maat_operation op, long long item_id, + long long group_id, int low_bound, int up_bound, + int expire_after) +{ + char table_line[1024] = {0}; + int table_id = maat_get_table_id(maat_inst, table_name); + if (table_id < 0) { + return 0; + } + + sprintf(table_line, "%lld\t%lld\t%d\t%d\t%d", + item_id, group_id, low_bound, up_bound, op); + struct maat_cmd_line line_rule; + + line_rule.rule_id = item_id; + line_rule.table_line = table_line; + line_rule.table_name = table_name; + line_rule.expire_after = expire_after; + + return maat_cmd_set_line(maat_inst, &line_rule); +} + +static int flag_table_set_line(struct maat *maat_inst, const char *table_name, + enum maat_operation op, long long item_id, + long long group_id, long long flag, + long long flag_mask, int expire_after) +{ + char table_line[1024] = {0}; + int table_id = maat_get_table_id(maat_inst, table_name); + if (table_id < 0) { + return 0; + } + + sprintf(table_line, "%lld\t%lld\t%lld\t%lld\t%d", + item_id, group_id, flag, flag_mask, op); + struct maat_cmd_line line_rule; + + line_rule.rule_id = item_id; + line_rule.table_line = table_line; + line_rule.table_name = table_name; + line_rule.expire_after = expire_after; + + return maat_cmd_set_line(maat_inst, &line_rule); +} + +static void test_add_expr_command(struct maat *maat_inst, const char *table_name, + const char *keywords) { long long compile_id = maat_cmd_incrby(maat_inst, "TEST_SEQ", 1); int ret = compile_table_set_line(maat_inst, "COMPILE", MAAT_OP_ADD, compile_id, "null", 1, 0); @@ -270,12 +316,12 @@ void test_add_expr_command(struct maat *maat_inst, const char *table_name, long long item_id = maat_cmd_incrby(maat_inst, "SEQUENCE_REGION", 1); ret = expr_table_set_line(maat_inst, table_name, MAAT_OP_ADD, item_id, group_id, - keywords, NULL, 1, 0, 0, 0); + keywords, "null", 1, 0, 0, 0); EXPECT_EQ(ret, 1); } -void test_add_ip_command(struct maat *maat_inst, const char *table_name, - const char *ip, uint16_t port) +static void test_add_ip_command(struct maat *maat_inst, const char *table_name, + const char *ip, uint16_t port) { long long compile_id = maat_cmd_incrby(maat_inst, "TEST_SEQ", 1); int ret = compile_table_set_line(maat_inst, "COMPILE", MAAT_OP_ADD, compile_id, "null", 1, 0); @@ -292,6 +338,42 @@ void test_add_ip_command(struct maat *maat_inst, const char *table_name, EXPECT_EQ(ret, 1); } +static void test_add_integer_command(struct maat *maat_inst, const char *table_name, + int low_bound, int up_bound) +{ + long long compile_id = maat_cmd_incrby(maat_inst, "TEST_SEQ", 1); + int ret = compile_table_set_line(maat_inst, "COMPILE", MAAT_OP_ADD, compile_id, "null", 1, 0); + EXPECT_EQ(ret, 1); + + long long group_id = maat_cmd_incrby(maat_inst, "SEQUENCE_GROUP", 1); + ret = group2compile_table_set_line(maat_inst, "GROUP2COMPILE", MAAT_OP_ADD, group_id, + compile_id, 0, "null", 1, 0); + EXPECT_EQ(ret, 1); + + long long item_id = maat_cmd_incrby(maat_inst, "SEQUENCE_REGION", 1); + ret = integer_table_set_line(maat_inst, table_name, MAAT_OP_ADD, item_id, group_id, + low_bound, up_bound, 0); + EXPECT_EQ(ret, 1); +} + +static void test_add_flag_command(struct maat *maat_inst, const char *table_name, + long long flag, long long flag_mask) +{ + long long compile_id = maat_cmd_incrby(maat_inst, "TEST_SEQ", 1); + int ret = compile_table_set_line(maat_inst, "COMPILE", MAAT_OP_ADD, compile_id, "null", 1, 0); + EXPECT_EQ(ret, 1); + + long long group_id = maat_cmd_incrby(maat_inst, "SEQUENCE_GROUP", 1); + ret = group2compile_table_set_line(maat_inst, "GROUP2COMPILE", MAAT_OP_ADD, group_id, + compile_id, 0, "null", 1, 0); + EXPECT_EQ(ret, 1); + + long long item_id = maat_cmd_incrby(maat_inst, "SEQUENCE_REGION", 1); + ret = flag_table_set_line(maat_inst, table_name, MAAT_OP_ADD, item_id, group_id, + flag, flag_mask, 0); + EXPECT_EQ(ret, 1); +} + class MaatPerfStringScan : public testing::Test { protected: @@ -344,7 +426,7 @@ void *perf_string_scan_thread(void *arg) struct maat *maat_inst = param->maat_inst; const char *table_name = param->table_name; struct timespec start, end; - const char *scan_data = "String TEST should hit"; + const char *scan_data = "today and yesterday should hit"; long long results[ARRAY_SIZE] = {0}; int hit_times = 0; size_t n_hit_result = 0; @@ -392,13 +474,67 @@ void *perf_string_update_thread(void *arg) return is_all_hit; } +void *perf_regex_scan_thread(void *arg) +{ + struct thread_param *param = (struct thread_param *)arg; + struct maat *maat_inst = param->maat_inst; + const char *table_name = param->table_name; + struct timespec start, end; + const char *scan_data = "http://www.cyberessays.com/search_results.php?action=search&query=username,abckkk,1234567"; + long long results[ARRAY_SIZE] = {0}; + int hit_times = 0; + size_t n_hit_result = 0; + struct maat_state *state = maat_state_new(maat_inst, param->thread_id); + + int table_id = maat_get_table_id(maat_inst, table_name); + + clock_gettime(CLOCK_MONOTONIC, &start); + for (int i = 0; i < param->test_count; i++) { + int ret = maat_scan_string(maat_inst, table_id, scan_data, strlen(scan_data), + results, ARRAY_SIZE, &n_hit_result, state); + if (ret == MAAT_SCAN_HIT) { + hit_times++; + } + maat_state_reset(state); + } + clock_gettime(CLOCK_MONOTONIC, &end); + + param->time_elapse_ms = (end.tv_sec - start.tv_sec) * 1000 + (end.tv_nsec - start.tv_nsec) / 1000000; + int *is_all_hit = ALLOC(int, 1); + *is_all_hit = (hit_times == param->test_count ? 1 : 0); + log_info(param->logger, MODULE_FRAMEWORK_PERF_GTEST, + "thread_id:%d regex_scan time_elapse:%lldms hit_times:%d", + param->thread_id, param->time_elapse_ms, hit_times); + return is_all_hit; +} + +void *perf_regex_update_thread(void *arg) +{ + struct thread_param *param = (struct thread_param *)arg; + struct maat *maat_inst = param->maat_inst; + const char *table_name = param->table_name; + const int CMD_EXPR_NUM = 10; + char keyword_buf[128]; + + for (int i = 0; i < CMD_EXPR_NUM; i++) { + random_keyword_generate(keyword_buf, sizeof(keyword_buf)); + test_add_expr_command(maat_inst, table_name, keyword_buf); + sleep(1); + } + + int *is_all_hit = ALLOC(int, 1); + *is_all_hit = 1; + + return is_all_hit; +} + void *perf_ip_scan_thread(void *arg) { struct thread_param *param = (struct thread_param *)arg; struct maat *maat_inst = param->maat_inst; const char *table_name = param->table_name; struct timespec start, end; - char ip_str[32] = "10.0.7.100"; + char ip_str[32] = "10.0.0.1"; uint32_t ip_addr; uint16_t port = htons(65530); @@ -461,8 +597,113 @@ void *perf_ip_update_thread(void *arg) return is_all_hit; } -TEST_F(MaatPerfStringScan, MultiThread) { - const char *table_name = "KEYWORDS_TABLE"; +void *perf_integer_scan_thread(void *arg) +{ + struct thread_param *param = (struct thread_param *)arg; + struct maat *maat_inst = param->maat_inst; + const char *table_name = param->table_name; + struct timespec start, end; + int hit_times = 0; + long long results[ARRAY_SIZE] = {0}; + size_t n_hit_result = 0; + + struct maat_state *state = maat_state_new(maat_inst, param->thread_id); + int table_id = maat_get_table_id(maat_inst, table_name); + + clock_gettime(CLOCK_MONOTONIC, &start); + for (int i = 0; i < param->test_count; i++) { + int ret = maat_scan_integer(maat_inst, table_id, 3000, results, + ARRAY_SIZE, &n_hit_result, state); + if (ret == MAAT_SCAN_HIT) { + hit_times++; + } + maat_state_reset(state); + } + clock_gettime(CLOCK_MONOTONIC, &end); + + param->time_elapse_ms = (end.tv_sec - start.tv_sec) * 1000 + + (end.tv_nsec - start.tv_nsec) / 1000000; + int *is_all_hit = ALLOC(int, 1); + *is_all_hit = (hit_times == param->test_count ? 1 : 0); + log_info(param->logger, MODULE_FRAMEWORK_PERF_GTEST, + "thread_id:%d integer_scan time_elapse:%lldms hit_times:%d", + param->thread_id, param->time_elapse_ms, hit_times); + return is_all_hit; +} + +void *perf_integer_update_thread(void *arg) +{ + struct thread_param *param = (struct thread_param *)arg; + struct maat *maat_inst = param->maat_inst; + const char *table_name = param->table_name; + const int CMD_EXPR_NUM = 10; + + for (int i = 0; i < CMD_EXPR_NUM; i++) { + test_add_integer_command(maat_inst, table_name, 3001+i, 3001+i); + sleep(1); + } + + int *is_all_hit = ALLOC(int, 1); + *is_all_hit = 1; + + return is_all_hit; +} + +void *perf_flag_scan_thread(void *arg) +{ + struct thread_param *param = (struct thread_param *)arg; + struct maat *maat_inst = param->maat_inst; + const char *table_name = param->table_name; + struct timespec start, end; + int hit_times = 0; + long long results[ARRAY_SIZE] = {0}; + size_t n_hit_result = 0; + long long scan_data = 15; + + struct maat_state *state = maat_state_new(maat_inst, param->thread_id); + int table_id = maat_get_table_id(maat_inst, table_name); + + clock_gettime(CLOCK_MONOTONIC, &start); + for (int i = 0; i < param->test_count; i++) { + int ret = maat_scan_flag(maat_inst, table_id, scan_data, results, + ARRAY_SIZE, &n_hit_result, state); + if (ret == MAAT_SCAN_HIT) { + hit_times++; + } + maat_state_reset(state); + } + clock_gettime(CLOCK_MONOTONIC, &end); + + param->time_elapse_ms = (end.tv_sec - start.tv_sec) * 1000 + + (end.tv_nsec - start.tv_nsec) / 1000000; + int *is_all_hit = ALLOC(int, 1); + *is_all_hit = (hit_times == param->test_count ? 1 : 0); + log_info(param->logger, MODULE_FRAMEWORK_PERF_GTEST, + "thread_id:%d flag_scan time_elapse:%lldms hit_times:%d", + param->thread_id, param->time_elapse_ms, hit_times); + return is_all_hit; +} + +void *perf_flag_update_thread(void *arg) +{ + struct thread_param *param = (struct thread_param *)arg; + struct maat *maat_inst = param->maat_inst; + const char *table_name = param->table_name; + const int CMD_EXPR_NUM = 10; + + for (int i = 0; i < CMD_EXPR_NUM; i++) { + test_add_flag_command(maat_inst, table_name, i, 15); + sleep(1); + } + + int *is_all_hit = ALLOC(int, 1); + *is_all_hit = 1; + + return is_all_hit; +} + +TEST_F(MaatPerfStringScan, LiteralMultiThread) { + const char *table_name = "EXPR_LITERAL_PERF_CONFIG"; struct maat *maat_inst = MaatPerfStringScan::_shared_maat_inst; int table_id = maat_get_table_id(maat_inst, table_name); @@ -502,12 +743,58 @@ TEST_F(MaatPerfStringScan, MultiThread) { free(is_all_hit); } scan_per_second = scan_count * 1000 / time_elapse_ms; - //EXPECT_GT(scan_per_second, 800 * 1000); log_info(maat_inst->logger, MODULE_FRAMEWORK_PERF_GTEST, "StringScan match rate on %d-threads speed %lld lookups/s/thread", PERF_THREAD_NUM, scan_per_second); } +TEST_F(MaatPerfStringScan, RegexMultiThread) { + const char *table_name = "EXPR_REGEX_PERF_CONFIG"; + struct maat *maat_inst = MaatPerfStringScan::_shared_maat_inst; + + int table_id = maat_get_table_id(maat_inst, table_name); + ASSERT_GT(table_id, 0); + + pthread_t threads[PERF_THREAD_NUM + 1]; + struct thread_param thread_params[PERF_THREAD_NUM + 1]; + int i = 0; + int *is_all_hit = NULL; + + for (i = 0; i < PERF_THREAD_NUM + 1; i++) { + thread_params[i].maat_inst = maat_inst; + thread_params[i].thread_id = i; + thread_params[i].table_name = table_name; + thread_params[i].test_count = PERF_SCAN_COUNT; + thread_params[i].time_elapse_ms = 0; + thread_params[i].logger = logger; + + if (i < PERF_THREAD_NUM) { + pthread_create(&threads[i], NULL, perf_regex_scan_thread, thread_params+i); + } else { + thread_params[i].test_count = 0; + pthread_create(&threads[i], NULL, perf_regex_update_thread, thread_params+i); + } + } + + long long time_elapse_ms = 0; + long long scan_count = 0; + long long scan_per_second = 0; + for (i = 0; i < PERF_THREAD_NUM + 1; i++) { + pthread_join(threads[i], (void **)&is_all_hit); + time_elapse_ms += thread_params[i].time_elapse_ms; + scan_count += thread_params[i].test_count; + + EXPECT_EQ(*is_all_hit, 1); + *is_all_hit = 0; + free(is_all_hit); + } + scan_per_second = scan_count * 1000 / time_elapse_ms; + + log_info(maat_inst->logger, MODULE_FRAMEWORK_PERF_GTEST, + "RegexScan match rate on %d-threads speed %lld lookups/s/thread", + PERF_THREAD_NUM, scan_per_second); +} + class MaatPerfStreamScan : public testing::Test { protected: @@ -560,34 +847,31 @@ void *perf_stream_scan_thread(void *arg) struct maat *maat_inst = param->maat_inst; const char *table_name = param->table_name; struct timespec start, end; - const char *scan_data = "http://www.cyberessays.com/search_results.php?action=search&query=yulingjing,abckkk,1234567"; + const char *scan_data = "http://www.cyberessays.com/search_results.php?today and yesterday"; long long results[ARRAY_SIZE] = {0}; int ret = 0, hit_times = 0; size_t n_hit_result = 0; - struct maat_state *state_array[ARRAY_SIZE]; - struct maat_stream *sp[ARRAY_SIZE]; + int table_id = maat_get_table_id(maat_inst, table_name); - + struct maat_state *state = maat_state_new(maat_inst, param->thread_id); + struct maat_stream *sp = maat_stream_new(maat_inst, table_id, state); + clock_gettime(CLOCK_MONOTONIC, &start); for (int i = 0; i < param->test_count; i++) { - for (int j = 0; j < ARRAY_SIZE; j++) { - state_array[j] = maat_state_new(maat_inst, param->thread_id); - sp[j] = maat_stream_new(maat_inst, table_id, state_array[j]); - - ret = maat_stream_scan(sp[j], scan_data, strlen(scan_data), results, ARRAY_SIZE, - &n_hit_result, state_array[j]); - if (ret == MAAT_SCAN_HIT) { - hit_times++; - } - maat_stream_free(sp[j]); - maat_state_free(state_array[j]); + ret = maat_stream_scan(sp, scan_data, strlen(scan_data), results, ARRAY_SIZE, + &n_hit_result, state); + if (ret == MAAT_SCAN_HIT) { + hit_times++; } + maat_state_reset(state); } clock_gettime(CLOCK_MONOTONIC, &end); + maat_stream_free(sp); + maat_state_free(state); param->time_elapse_ms = (end.tv_sec - start.tv_sec) * 1000 + (end.tv_nsec - start.tv_nsec) / 1000000; int *is_all_hit = ALLOC(int, 1); - *is_all_hit = ((hit_times == param->test_count*ARRAY_SIZE) ? 1 : 0); + *is_all_hit = ((hit_times == param->test_count) ? 1 : 0); log_info(param->logger, MODULE_FRAMEWORK_PERF_GTEST, "thread_id:%d stream_scan time_elapse:%lldms hit_times:%d", @@ -595,64 +879,40 @@ void *perf_stream_scan_thread(void *arg) return is_all_hit; } -void *perf_stream_update_thread(void *arg) -{ - struct thread_param *param = (struct thread_param *)arg; - struct maat *maat_inst = param->maat_inst; - const char *table_name = param->table_name; - const int CMD_EXPR_NUM = 10; - char keyword_buf[128]; - - for (int i = 0; i < CMD_EXPR_NUM; i++) { - random_keyword_generate(keyword_buf, sizeof(keyword_buf)); - test_add_expr_command(maat_inst, table_name, keyword_buf); - sleep(1); - } - - int *is_all_hit = ALLOC(int, 1); - *is_all_hit = 1; - - return is_all_hit; -} - TEST_F(MaatPerfStreamScan, MultiThread) { - const char *table_name = "HTTP_URL"; + const char *table_name = "EXPR_LITERAL_PERF_CONFIG"; struct maat *maat_inst = MaatPerfStreamScan::_shared_maat_inst; int table_id = maat_get_table_id(maat_inst, table_name); ASSERT_GT(table_id, 0); - pthread_t threads[PERF_THREAD_NUM + 1]; - struct thread_param thread_params[PERF_THREAD_NUM + 1]; + pthread_t threads[PERF_THREAD_NUM]; + struct thread_param thread_params[PERF_THREAD_NUM]; int i = 0; int *is_all_hit = NULL; - for (i = 0; i < PERF_THREAD_NUM + 1; i++) { + for (i = 0; i < PERF_THREAD_NUM; i++) { thread_params[i].maat_inst = maat_inst; thread_params[i].thread_id = i; thread_params[i].table_name = table_name; - thread_params[i].test_count = PERF_SCAN_COUNT / 10; + thread_params[i].test_count = PERF_SCAN_COUNT; thread_params[i].time_elapse_ms = 0; thread_params[i].logger = logger; if (i < PERF_THREAD_NUM) { pthread_create(&threads[i], NULL, perf_stream_scan_thread, thread_params+i); - } else { - thread_params[i].test_count = 0; - pthread_create(&threads[i], NULL, perf_stream_update_thread, thread_params+i); - } + } } long long time_elapse_ms = 0; long long scan_count = 0; long long scan_per_second = 0; - for (i = 0; i < PERF_THREAD_NUM + 1; i++) { + for (i = 0; i < PERF_THREAD_NUM; i++) { pthread_join(threads[i], (void **)&is_all_hit); time_elapse_ms += thread_params[i].time_elapse_ms; scan_count += thread_params[i].test_count; //maybe expr_runtime rebuild in stream_scan, so should not expect is_all_hit always 1 - //EXPECT_EQ(*is_all_hit, 1); - *is_all_hit = 0; + EXPECT_EQ(*is_all_hit, 1); free(is_all_hit); } scan_per_second = scan_count * 1000 / time_elapse_ms; @@ -710,7 +970,7 @@ struct log_handle *MaatPerfIPScan::logger; TEST_F(MaatPerfIPScan, MultiThread) { - const char *table_name = "IP_PLUS_CONFIG"; + const char *table_name = "IP_PERF_CONFIG"; struct maat *maat_inst = MaatPerfIPScan::_shared_maat_inst; int table_id = maat_get_table_id(maat_inst, table_name); @@ -756,6 +1016,192 @@ TEST_F(MaatPerfIPScan, MultiThread) PERF_THREAD_NUM, scan_per_second); } +class MaatPerfIntegerScan : public testing::Test +{ +protected: + static void SetUpTestCase() { + const char *accept_tags = "{\"tags\":[{\"tag\":\"location\",\"value\":\"北京/朝阳/华严北里/甲22号\"}," + "{\"tag\":\"isp\",\"value\":\"移动\"},{\"tag\":\"location\",\"value\":\"Astana\"}]}"; + char redis_ip[64] = "127.0.0.1"; + int redis_port = 6379; + int redis_db = 0; + + logger = log_handle_create("./maat_framework_perf_gtest.log", 0); + int ret = write_config_to_redis(redis_ip, redis_port, redis_db, logger); + if (ret < 0) { + log_error(logger, MODULE_FRAMEWORK_PERF_GTEST, + "[%s:%d] write config to redis failed.", __FUNCTION__, __LINE__); + } + + struct maat_options *opts = maat_options_new(); + maat_options_set_stat_file(opts, "./stat.log"); + maat_options_set_perf_on(opts); + maat_options_set_redis(opts, redis_ip, redis_port, redis_db); + maat_options_set_logger(opts, "./maat_framework_perf_gtest.log", LOG_LEVEL_INFO); + maat_options_set_accept_tags(opts, accept_tags); + maat_options_set_caller_thread_number(opts, 5); + + _shared_maat_inst = maat_new(opts, table_info_path); + maat_options_free(opts); + if (NULL == _shared_maat_inst) { + log_error(logger, MODULE_FRAMEWORK_PERF_GTEST, + "[%s:%d] create maat instance in MaatFlagScan failed.", + __FUNCTION__, __LINE__); + } + } + + static void TearDownTestCase() { + maat_free(_shared_maat_inst); + log_handle_destroy(logger); + } + + static struct log_handle *logger; + static struct maat *_shared_maat_inst; +}; + +struct maat *MaatPerfIntegerScan::_shared_maat_inst; +struct log_handle *MaatPerfIntegerScan::logger; + +TEST_F(MaatPerfIntegerScan, MultiThread) { + const char *table_name = "INTEGER_PERF_CONFIG"; + struct maat *maat_inst = MaatPerfIntegerScan::_shared_maat_inst; + + int table_id = maat_get_table_id(maat_inst, table_name); + ASSERT_GT(table_id, 0); + + pthread_t threads[PERF_THREAD_NUM + 1]; + struct thread_param thread_params[PERF_THREAD_NUM + 1]; + int i = 0; + int *is_all_hit = NULL; + + for (i = 0; i < PERF_THREAD_NUM + 1; i++) { + thread_params[i].maat_inst = maat_inst; + thread_params[i].thread_id = i; + thread_params[i].table_name = table_name; + thread_params[i].test_count = PERF_SCAN_COUNT; + thread_params[i].time_elapse_ms = 0; + thread_params[i].logger = logger; + + if (i < PERF_THREAD_NUM) { + pthread_create(&threads[i], NULL, perf_integer_scan_thread, thread_params+i); + } else { + thread_params[i].test_count = 0; + pthread_create(&threads[i], NULL, perf_integer_update_thread, thread_params+i); + } + } + + long long time_elapse_ms = 0; + long long scan_count = 0; + long long scan_per_second = 0; + for (i = 0; i < PERF_THREAD_NUM + 1; i++) { + pthread_join(threads[i], (void **)&is_all_hit); + time_elapse_ms += thread_params[i].time_elapse_ms; + scan_count += thread_params[i].test_count; + + EXPECT_EQ(*is_all_hit, 1); + *is_all_hit = 0; + free(is_all_hit); + } + scan_per_second = scan_count * 1000 / time_elapse_ms; + + log_info(maat_inst->logger, MODULE_FRAMEWORK_PERF_GTEST, + "IntegerScan match rate on %d-threads speed %lld lookups/s/thread", + PERF_THREAD_NUM, scan_per_second); +} + +class MaatPerfFlagScan : public testing::Test +{ +protected: + static void SetUpTestCase() { + const char *accept_tags = "{\"tags\":[{\"tag\":\"location\",\"value\":\"北京/朝阳/华严北里/甲22号\"}," + "{\"tag\":\"isp\",\"value\":\"移动\"},{\"tag\":\"location\",\"value\":\"Astana\"}]}"; + char redis_ip[64] = "127.0.0.1"; + int redis_port = 6379; + int redis_db = 0; + + logger = log_handle_create("./maat_framework_perf_gtest.log", 0); + int ret = write_config_to_redis(redis_ip, redis_port, redis_db, logger); + if (ret < 0) { + log_error(logger, MODULE_FRAMEWORK_PERF_GTEST, + "[%s:%d] write config to redis failed.", __FUNCTION__, __LINE__); + } + + struct maat_options *opts = maat_options_new(); + maat_options_set_stat_file(opts, "./stat.log"); + maat_options_set_perf_on(opts); + maat_options_set_redis(opts, redis_ip, redis_port, redis_db); + maat_options_set_logger(opts, "./maat_framework_perf_gtest.log", LOG_LEVEL_INFO); + maat_options_set_accept_tags(opts, accept_tags); + maat_options_set_caller_thread_number(opts, 5); + + _shared_maat_inst = maat_new(opts, table_info_path); + maat_options_free(opts); + if (NULL == _shared_maat_inst) { + log_error(logger, MODULE_FRAMEWORK_PERF_GTEST, + "[%s:%d] create maat instance in MaatFlagScan failed.", + __FUNCTION__, __LINE__); + } + } + + static void TearDownTestCase() { + maat_free(_shared_maat_inst); + log_handle_destroy(logger); + } + + static struct log_handle *logger; + static struct maat *_shared_maat_inst; +}; + +struct maat *MaatPerfFlagScan::_shared_maat_inst; +struct log_handle *MaatPerfFlagScan::logger; + +TEST_F(MaatPerfFlagScan, MultiThread) { + const char *table_name = "FLAG_PERF_CONFIG"; + struct maat *maat_inst = MaatPerfFlagScan::_shared_maat_inst; + + int table_id = maat_get_table_id(maat_inst, table_name); + ASSERT_GT(table_id, 0); + + pthread_t threads[PERF_THREAD_NUM + 1]; + struct thread_param thread_params[PERF_THREAD_NUM + 1]; + int i = 0; + int *is_all_hit = NULL; + + for (i = 0; i < PERF_THREAD_NUM + 1; i++) { + thread_params[i].maat_inst = maat_inst; + thread_params[i].thread_id = i; + thread_params[i].table_name = table_name; + thread_params[i].test_count = PERF_SCAN_COUNT; + thread_params[i].time_elapse_ms = 0; + thread_params[i].logger = logger; + + if (i < PERF_THREAD_NUM) { + pthread_create(&threads[i], NULL, perf_flag_scan_thread, thread_params+i); + } else { + thread_params[i].test_count = 0; + pthread_create(&threads[i], NULL, perf_flag_update_thread, thread_params+i); + } + } + + long long time_elapse_ms = 0; + long long scan_count = 0; + long long scan_per_second = 0; + for (i = 0; i < PERF_THREAD_NUM + 1; i++) { + pthread_join(threads[i], (void **)&is_all_hit); + time_elapse_ms += thread_params[i].time_elapse_ms; + scan_count += thread_params[i].test_count; + + EXPECT_EQ(*is_all_hit, 1); + *is_all_hit = 0; + free(is_all_hit); + } + scan_per_second = scan_count * 1000 / time_elapse_ms; + + log_info(maat_inst->logger, MODULE_FRAMEWORK_PERF_GTEST, + "FlagScan match rate on %d-threads speed %lld lookups/s/thread", + PERF_THREAD_NUM, scan_per_second); +} + class MaatPerfFQDNPluginScan : public testing::Test { protected: diff --git a/test/maat_json.json b/test/maat_json.json index d4c65ba..30a7476 100644 --- a/test/maat_json.json +++ b/test/maat_json.json @@ -2973,7 +2973,135 @@ "not_flag": 0 } ] - } + }, + { + "compile_id": 211, + "service": 0, + "action": 0, + "do_blacklist": 0, + "do_log": 0, + "effective_rage": 0, + "user_region": "ip_perf_test", + "is_valid": "yes", + "groups": [ + { + "regions": [ + { + "table_type": "ip_plus", + "table_name": "IP_PERF_CONFIG", + "table_content": { + "addr_type": "ipv4", + "addr_format": "range", + "ip1": "10.0.0.1", + "ip2": "10.0.0.6", + "port_format": "range", + "port1": "65530", + "port2": "65535", + "protocol": 6 + } + } + ], + "not_flag": 0 + } + ] + }, + { + "compile_id": 212, + "service": 1, + "action": 1, + "do_blacklist": 1, + "do_log": 1, + "user_region": "integer_perf_test", + "is_valid": "yes", + "groups": [ + { + "group_name": "Untitled", + "regions": [ + { + "table_name": "INTEGER_PERF_CONFIG", + "table_type": "interval", + "table_content": { + "low_boundary": 3000, + "up_boundary": 3000 + } + } + ] + } + ] + }, + { + "compile_id": 213, + "service": 1, + "action": 1, + "do_blacklist": 1, + "do_log": 1, + "user_region": "expr_perf_test", + "is_valid": "yes", + "groups": [ + { + "regions": [ + { + "table_name": "EXPR_LITERAL_PERF_CONFIG", + "table_type": "expr", + "table_content": { + "keywords": "today&yesterday", + "expr_type": "and", + "match_method": "sub", + "format": "uncase plain" + } + } + ] + } + ] + }, + { + "compile_id": 214, + "service": 0, + "action": 0, + "do_blacklist": 0, + "do_log": 0, + "user_region": "flag_perf_test", + "is_valid": "yes", + "groups": [ + { + "regions": [ + { + "table_type": "flag", + "table_name": "FLAG_PERF_CONFIG", + "table_content": { + "flag": 15, + "flag_mask": 15 + } + } + ] + } + ] + }, + { + "compile_id": 215, + "service": 1, + "action": 1, + "do_blacklist": 1, + "do_log": 1, + "user_region": "expr_perf_test", + "is_valid": "yes", + "groups": [ + { + "regions": [ + { + "table_name": "EXPR_REGEX_PERF_CONFIG", + "table_type": "expr", + "table_content": { + "keywords": "action=search\\&query=(.*)", + "expr_type": "regex", + "match_method": "sub", + "format": "uncase plain" + } + } + ] + } + ] + } ], "plugin_table": [ { diff --git a/test/table_info.conf b/test/table_info.conf index 07702b4..1dcffe7 100644 --- a/test/table_info.conf +++ b/test/table_info.conf @@ -495,5 +495,75 @@ "table_name":"HTTP_URL_FILTER", "table_type":"virtual", "physical_table": "HTTP_URL" + }, + { + "table_id":42, + "table_name":"IP_PERF_CONFIG", + "table_type":"ip_plus", + "valid_column":11, + "custom": { + "item_id":1, + "group_id":2, + "addr_type":3, + "addr_format":4, + "ip1":5, + "ip2":6, + "port_format":7, + "port1":8, + "port2":9, + "protocol":10 + } + }, + { + "table_id":43, + "table_name":"INTEGER_PERF_CONFIG", + "table_type":"intval", + "valid_column":5, + "custom": { + "item_id":1, + "group_id":2, + "low_bound":3, + "up_bound":4 + } + }, + { + "table_id":44, + "table_name":"EXPR_LITERAL_PERF_CONFIG", + "table_type":"expr", + "valid_column":7, + "custom": { + "item_id":1, + "group_id":2, + "keywords":3, + "expr_type":4, + "match_method":5, + "is_hexbin":6 + } + }, + { + "table_id":45, + "table_name":"EXPR_REGEX_PERF_CONFIG", + "table_type":"expr", + "valid_column":7, + "custom": { + "item_id":1, + "group_id":2, + "keywords":3, + "expr_type":4, + "match_method":5, + "is_hexbin":6 + } + }, + { + "table_id":46, + "table_name":"FLAG_PERF_CONFIG", + "table_type":"flag", + "valid_column":5, + "custom": { + "item_id":1, + "group_id":2, + "flag":3, + "flag_mask":4 + } } ] \ No newline at end of file diff --git a/vendor/rulescan-3.0.1.tar.gz b/vendor/rulescan-3.0.1.tar.gz index 2ddfd3b..e137f1c 100644 Binary files a/vendor/rulescan-3.0.1.tar.gz and b/vendor/rulescan-3.0.1.tar.gz differ