diff options
| author | root <[email protected]> | 2024-01-11 09:46:00 +0000 |
|---|---|---|
| committer | root <[email protected]> | 2024-01-11 09:46:00 +0000 |
| commit | 783af138f65abdd13ad3a374531c6b47172b7413 (patch) | |
| tree | 252190ba4d30533a25e0fc6d0bd49d3d854dd0f3 | |
| parent | 44245c94530345efbd1445af837fa469f55924de (diff) | |
TSG-18230: 优化:对于同一个profile,当高优先级有排队报文时,500ms内低优先级不允许获得带宽
| -rw-r--r-- | shaping/src/shaper.cpp | 13 | ||||
| -rw-r--r-- | shaping/test/gtest_shaper.cpp | 4 |
2 files changed, 10 insertions, 7 deletions
diff --git a/shaping/src/shaper.cpp b/shaping/src/shaper.cpp index 9ca8a28..6457025 100644 --- a/shaping/src/shaper.cpp +++ b/shaping/src/shaper.cpp @@ -26,6 +26,7 @@ extern "C" { #define TOKEN_ENLARGE_TIMES 10 #define TOKEN_GET_FAILED_INTERVAL_MS 1 #define HMGET_REQUEST_INTERVAL_MS 10 +#define PRIORITY_BLOCK_MIN_TIME_MS 500 #define SWARMKV_QUEUE_LEN_GET_CMD_PRIORITY_1 "HMGET tsg-shaping-%d priority-0" #define SWARMKV_QUEUE_LEN_GET_CMD_PRIORITY_2 SWARMKV_QUEUE_LEN_GET_CMD_PRIORITY_1 " priority-1" @@ -67,7 +68,7 @@ struct shaping_profile_hash_node { int out_deposit_token_bits[SHAPING_PRIORITY_NUM_MAX]; long long last_failed_get_token_ms; long long last_hmget_ms[SHAPING_PRIORITY_NUM_MAX]; - unsigned char is_priority_blocked[SHAPING_PRIORITY_NUM_MAX]; + long long priority_blocked_time_ms[SHAPING_PRIORITY_NUM_MAX]; unsigned char is_invalid; UT_hash_handle hh; }; @@ -608,16 +609,16 @@ static void shaper_queue_len_get_cb(const struct swarmkv_reply *reply, void * cb int priority = arg->priority; struct timespec curr_time; long long curr_time_us; + long long curr_time_ms; clock_gettime(CLOCK_MONOTONIC, &curr_time); curr_time_us = curr_time.tv_sec * MICRO_SECONDS_PER_SEC + curr_time.tv_nsec / NANO_SECONDS_PER_MICRO_SEC; + curr_time_ms = curr_time_us / 1000; shaper_global_stat_swarmkv_latency_update(ctx->ref_ctx->global_stat, curr_time_us - arg->start_time_us); shaper_global_stat_async_callback_inc(&ctx->thread_global_stat); shaper_global_stat_hmget_callback_inc(&ctx->thread_global_stat); - pf_hash_node->is_priority_blocked[priority] = 0; - if (!reply || (reply->type != SWARMKV_REPLY_NIL && reply->type != SWARMKV_REPLY_ARRAY)) { shaper_global_stat_async_hmget_failed_inc(&ctx->thread_global_stat); goto END; @@ -632,14 +633,14 @@ static void shaper_queue_len_get_cb(const struct swarmkv_reply *reply, void * cb char tmp_str[32] = {0}; memcpy(tmp_str, reply->elements[i]->str, reply->elements[i]->len); if (strtoll(tmp_str, NULL, 10) > 0) { - pf_hash_node->is_priority_blocked[priority] = 1; + pf_hash_node->priority_blocked_time_ms[priority] = curr_time_ms; break; } } } END: - pf_hash_node->last_hmget_ms[priority] = curr_time.tv_sec * MILLI_SECONDS_PER_SEC + curr_time.tv_nsec / NANO_SECONDS_PER_MILLI_SEC; + pf_hash_node->last_hmget_ms[priority] = curr_time_ms; free(cb_arg); cb_arg = NULL; @@ -673,7 +674,7 @@ static int shaper_profile_is_priority_blocked(struct shaping_thread_ctx *ctx, st swarmkv_async_command(ctx->swarmkv_db, shaper_queue_len_get_cb, arg, swarmkv_queue_len_get_cmd[priority], profile->id); END: - if (profile->hash_node->is_priority_blocked[priority] == 1) { + if (curr_time_ms - profile->hash_node->priority_blocked_time_ms[priority] < PRIORITY_BLOCK_MIN_TIME_MS) { sf->flag |= SESSION_BORROW; return 1; } else { diff --git a/shaping/test/gtest_shaper.cpp b/shaping/test/gtest_shaper.cpp index 58afc4a..f262412 100644 --- a/shaping/test/gtest_shaper.cpp +++ b/shaping/test/gtest_shaper.cpp @@ -1201,6 +1201,7 @@ TEST(two_session_diff_priority_same_profile, udp_borrow_in_order) } shaper_stat_refresh(&ctx->thread_ctx[0], sf2, 0, 1);//refresh stat, to ensure priority queue_len in swarmkv is correct + stub_curr_time_s_inc(1);//inc time to refresh hmget interval while (!TAILQ_EMPTY(&expec_tx_queue1)) {//last 90 delay packets stub_refresh_token_bucket(2); for (int i = 0; i < 20; i++) {//even though invoke polling more than 10 times, there should be only 10 pkts be sent @@ -1229,7 +1230,7 @@ TEST(two_session_diff_priority_same_profile, udp_borrow_in_order) stat_file = fopen(SHAPING_STAT_FILE_NAME, "r"); memset(line, 0, sizeof(line)); ASSERT_TRUE(NULL != fgets(line, sizeof(line), stat_file));//profile_id 1, primary - shaping_stat_judge(line, 1, 1, 1, 0, 0, 0, 0, 470000, SHAPING_DIR_OUT, profile_type_primary); + shaping_stat_judge(line, 1, 1, 1, 0, 0, 0, 0, 1470000, SHAPING_DIR_OUT, profile_type_primary); ASSERT_TRUE(NULL != fgets(line, sizeof(line), stat_file));//profile_id 2, borrow shaping_stat_judge(line, 1, 2, 2, 100, 10000, 0, 0, 0, SHAPING_DIR_OUT, profile_type_borrow); @@ -1714,6 +1715,7 @@ TEST(two_sessions, primary_profile_priority_blocked_by_borrow_profile) ASSERT_EQ(0, judge_packet_eq(&expec_tx_queue1, actual_tx_queue, 1)); } + stub_curr_time_s_inc(1);//inc time to refresh hmget interval while (!TAILQ_EMPTY(&expec_tx_queue2)) { stub_refresh_token_bucket(1); polling_entry(ctx->thread_ctx[1].sp, ctx->thread_ctx[1].stat, &ctx->thread_ctx[1]); |
