From 96abe1d9f4e9a290ed75281a45c63767d612a69b Mon Sep 17 00:00:00 2001 From: zhengchao Date: Tue, 27 Jul 2021 15:17:29 +0800 Subject: [PATCH] =?UTF-8?q?Maat=5Fhierarchy=5Fbuild=5Fregion2clause=5Fhash?= =?UTF-8?q?=E4=B8=AD=EF=BC=8C=E4=B8=8D=E5=9C=A8=E5=AF=B9group=E4=B8=AD?= =?UTF-8?q?=E7=9A=84region=20id=E6=8E=92=E5=BA=8F=E5=92=8C=E5=8E=BB?= =?UTF-8?q?=E9=87=8D=EF=BC=8C=20=E5=8F=AF=E4=BB=A5=E6=8F=90=E9=AB=98?= =?UTF-8?q?=E5=A4=A7Group=E7=9A=84=E5=8A=A0=E8=BD=BD=E6=80=A7=E8=83=BD?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/entry/Maat_hierarchy.cpp | 21 +++++++++++++++------ test/perf_test_maatframe.cpp | 26 ++++++++++++++++++++------ 2 files changed, 35 insertions(+), 12 deletions(-) diff --git a/src/entry/Maat_hierarchy.cpp b/src/entry/Maat_hierarchy.cpp index dc1974a..ca6da37 100644 --- a/src/entry/Maat_hierarchy.cpp +++ b/src/entry/Maat_hierarchy.cpp @@ -1119,15 +1119,16 @@ struct region2clause_value* Maat_hierarchy_build_region2clause_hash(struct Maat_ { g2r=ALLOC(struct group2region, 1); utarray_new(g2r->region_ids, &ut_region_id_icd); + utarray_reserve(g2r->region_ids, group->ref_by_region_cnt); g2r->group_id=group->top_group_ids[i]; HASH_ADD_INT(g2r_hash, group_id, g2r); } - if(utarray_find(g2r->region_ids, &(region->region_id), compare_region_id)) - { - assert(0); - } + + //One region belongs to one group, one group may have many regions. So duplicate region check is unnecessary. + //if(utarray_find(g2r->region_ids, &(region->region_id), compare_region_id)) assert(0); + utarray_push_back(g2r->region_ids, &(region->region_id)); - utarray_sort(g2r->region_ids, compare_region_id); + //utarray_sort(g2r->region_ids, compare_region_id); } } @@ -1178,10 +1179,18 @@ struct region2clause_value* Maat_hierarchy_build_region2clause_hash(struct Maat_ } } - + int tmp1=0, tmp2=0; HASH_ITER(hh, g2r_hash, g2r, g2r_tmp) { HASH_DEL(g2r_hash, g2r); + //Sanity Check + utarray_sort(g2r->region_ids, compare_region_id); + for(i=1; iregion_ids); i++) + { + tmp1=*((int*)utarray_eltptr(g2r->region_ids, i-1)); + tmp2=*((int*)utarray_eltptr(g2r->region_ids, i)); + assert(tmp1!=tmp2); + } utarray_free(g2r->region_ids); g2r->region_ids=NULL; free(g2r); diff --git a/test/perf_test_maatframe.cpp b/test/perf_test_maatframe.cpp index d51a4c0..fa1f2bf 100644 --- a/test/perf_test_maatframe.cpp +++ b/test/perf_test_maatframe.cpp @@ -372,8 +372,10 @@ const char* high_match_string="maatframe!"; struct high_match_rate_thread_para { int thread_id; + int test_count; Maat_feather_t feather; const char* expr_table_name; + unsigned long long time_elapse_ms; }; void* high_match_rate_scan_thread(void *arg) { @@ -385,10 +387,13 @@ void* high_match_rate_scan_thread(void *arg) struct Maat_rule_t result; scan_status_t mid=NULL; - int table_id=0, i=0, ret=0, test_times=10*1000*1000, hit_times=0; + int table_id=0, i=0, ret=0, hit_times=0; table_id=Maat_table_register(feather, expr_table_name); memset(&result, 0, sizeof(result)); - for(i=0; itest_count; i++) { ret=Maat_full_scan_string(feather, table_id, CHARSET_GBK, high_match_string, strlen(high_match_string), &result, NULL, 1, @@ -399,9 +404,10 @@ void* high_match_rate_scan_thread(void *arg) } Maat_clean_status(&mid); } - + clock_gettime(CLOCK_MONOTONIC, &end); + para->time_elapse_ms=(end.tv_sec-start.tv_sec)*1000+(end.tv_nsec-start.tv_nsec)/1000000; int* is_all_hit=(int*)malloc(sizeof(int)); - *is_all_hit=(hit_times==test_times)?1:0; + *is_all_hit=(hit_times==para->test_count)?1:0; return is_all_hit; } void* high_match_rate_update_thread(void *arg) @@ -453,6 +459,7 @@ TEST_F(MaatCMDPerfTest, HighMatchRateOnMultiThread) Maat_command_batch_commit(batch); sleep(4); int global_thread_num=4; + unsigned long long time_elapse_ms=0, scan_count=0, scan_per_second=0; pthread_t threads[global_thread_num+1]; struct high_match_rate_thread_para thread_para[global_thread_num+1]; for(i=0; i