diff options
| -rw-r--r-- | ci/travis.sh | 1 | ||||
| -rw-r--r-- | shaping/CMakeLists.txt | 1 | ||||
| -rw-r--r-- | shaping/include/shaper.h | 2 | ||||
| -rw-r--r-- | shaping/src/shaper.cpp | 24 |
4 files changed, 25 insertions, 3 deletions
diff --git a/ci/travis.sh b/ci/travis.sh index 1197c99..d62c1d0 100644 --- a/ci/travis.sh +++ b/ci/travis.sh @@ -48,6 +48,7 @@ yum install -y numactl-libs # required by mrzcpd yum install -y libibverbs # required by mrzcpd yum install -y libbreakpad_mini-devel yum install -y msgpack-devel +yum install -y jemalloc-devel source /etc/profile.d/framework.sh source /etc/profile.d/mrzcpd.sh diff --git a/shaping/CMakeLists.txt b/shaping/CMakeLists.txt index b96c476..a10cd45 100644 --- a/shaping/CMakeLists.txt +++ b/shaping/CMakeLists.txt @@ -13,6 +13,7 @@ target_link_libraries(shaping_engine PUBLIC shaper) target_link_libraries(shaping_engine PUBLIC maat4) target_link_libraries(shaping_engine PUBLIC mrzcpd) target_link_libraries(shaping_engine PUBLIC swarmkv) +target_link_libraries(shaping_engine PUBLIC jemalloc) install(TARGETS shaping_engine RUNTIME DESTINATION bin COMPONENT Program) diff --git a/shaping/include/shaper.h b/shaping/include/shaper.h index a218884..da32ef8 100644 --- a/shaping/include/shaper.h +++ b/shaping/include/shaper.h @@ -93,10 +93,10 @@ struct shaping_profile_info { int in_deposit_token; int out_deposit_token; unsigned long long enqueue_time_us;//to calculate max latency - unsigned long long last_failed_get_token_ms; unsigned char is_priority_blocked; unsigned char is_invalid; struct shaping_stat_for_profile stat; + struct shaping_profile_hash_node *hash_node; }; struct shaping_rule_info { diff --git a/shaping/src/shaper.cpp b/shaping/src/shaper.cpp index 02d7f33..af03f5b 100644 --- a/shaping/src/shaper.cpp +++ b/shaping/src/shaper.cpp @@ -77,6 +77,14 @@ enum shaper_token_get_result { SHAPER_TOKEN_GET_PASS = 1,//don't need to get token, regard as success }; +struct shaping_profile_hash_node { + int id; + unsigned long long last_failed_get_token_ms; + UT_hash_handle hh; +}; + +struct shaping_profile_hash_node *g_shaping_profile_table = NULL; + struct shaper* shaper_new(unsigned int priority_queue_len_max) { struct shaper *sp = NULL; @@ -410,7 +418,7 @@ static void shaper_token_get_cb(const struct swarmkv_reply *reply, void * cb_arg if (reply->integer == 0) {//no token struct timespec curr_time; clock_gettime(CLOCK_MONOTONIC, &curr_time); - s_pf_info->last_failed_get_token_ms = curr_time.tv_sec * MILLI_SECONDS_PER_SEC + curr_time.tv_nsec / NANO_SECONDS_PER_MILLI_SEC; + s_pf_info->hash_node->last_failed_get_token_ms = curr_time.tv_sec * MILLI_SECONDS_PER_SEC + curr_time.tv_nsec / NANO_SECONDS_PER_MILLI_SEC; goto END; } @@ -587,10 +595,22 @@ static int shaper_token_consume(struct shaping_thread_ctx *ctx, struct shaping_f return SHAPER_TOKEN_GET_SUCCESS; } + if (profile->hash_node == NULL) { + struct shaping_profile_hash_node *hash_node = NULL; + HASH_FIND_INT(g_shaping_profile_table, &profile->id, hash_node); + if (hash_node) { + profile->hash_node = hash_node; + } else { + profile->hash_node = (struct shaping_profile_hash_node*)calloc(1, sizeof(struct shaping_profile_hash_node)); + profile->hash_node->id = profile->id; + HASH_ADD_INT(g_shaping_profile_table, id, profile->hash_node); + } + } + struct timespec curr_timespec; clock_gettime(CLOCK_MONOTONIC, &curr_timespec); unsigned long long curr_time_ms = curr_timespec.tv_sec * MILLI_SECONDS_PER_SEC + curr_timespec.tv_nsec / NANO_SECONDS_PER_MILLI_SEC; - if (curr_time_ms - profile->last_failed_get_token_ms < TOKEN_GET_FAILED_INTERVAL_MS) {//if failed to get token in last 1ms, return failed; for swarmkv can't reproduce token in 1ms + if (curr_time_ms - profile->hash_node->last_failed_get_token_ms < TOKEN_GET_FAILED_INTERVAL_MS) {//if failed to get token in last 1ms, return failed; for swarmkv can't reproduce token in 1ms return SHAPER_TOKEN_GET_FAILED; } |
