summaryrefslogtreecommitdiff
path: root/shaping/src/shaper.cpp
diff options
context:
space:
mode:
authorroot <[email protected]>2024-03-21 03:30:55 +0000
committerroot <[email protected]>2024-03-21 03:30:55 +0000
commitdb240b23f54bd8f419a8fb70e0dabd06fe057338 (patch)
tree440407c0cfef757b6333c765c18126588d84b1a5 /shaping/src/shaper.cpp
parentadec4a3d8eb5e826fd3c3ea340dd1143c66db75a (diff)
TSG-19771:定期刷新profile配置,在刷新周期内,配置改变造成的限速不准现象为正常情况,刷新周期为5秒
Diffstat (limited to 'shaping/src/shaper.cpp')
-rw-r--r--shaping/src/shaper.cpp23
1 files changed, 22 insertions, 1 deletions
diff --git a/shaping/src/shaper.cpp b/shaping/src/shaper.cpp
index 2ff490d..91117f5 100644
--- a/shaping/src/shaper.cpp
+++ b/shaping/src/shaper.cpp
@@ -30,6 +30,8 @@ extern "C" {
#define HMGET_REQUEST_INTERVAL_MS 10
#define PRIORITY_BLOCK_MIN_TIME_MS 500
+#define PROFILE_HASH_NODE_REFRESH_SEC 5
+
#define SWARMKV_QUEUE_LEN_GET_CMD "HMGET tsg-shaping-%d priority-0 priority-1 priority-2 priority-3 priority-4 priority-5 priority-6 priority-7 priority-8 priority-9"
struct shaper {//trees in one thread
@@ -563,6 +565,23 @@ static int shaper_deposit_token_get(struct shaping_profile_info *profile, int re
return -1;
}
+static void shaper_profile_hash_node_refresh(struct shaping_thread_ctx *ctx, struct shaping_profile_hash_node *pf_hash_node)
+{
+ time_t curr_time_s = time(NULL);
+ if (curr_time_s - pf_hash_node->last_refresh_time_s < PROFILE_HASH_NODE_REFRESH_SEC) {
+ return;
+ }
+
+ struct shaping_profile *profile = shaper_maat_profile_get(ctx, pf_hash_node->id);
+ if (profile) {
+ pf_hash_node->limit_direction = profile->limit_direction;
+ pf_hash_node->aqm_type = profile->aqm_type;
+ }
+ pf_hash_node->last_refresh_time_s = curr_time_s;
+
+ return;
+}
+
static void shaper_token_get_from_profile(struct shaping_thread_ctx *ctx, struct shaping_flow *sf, struct shaping_profile_info *pf_info, int profile_type, int req_token_bits, unsigned char direction, struct timespec *curr_timespec)
{
struct shaping_tconsume_cb_arg *arg = NULL;
@@ -572,6 +591,8 @@ static void shaper_token_get_from_profile(struct shaping_thread_ctx *ctx, struct
if (pf_hash_node->tconsume_ref_cnt > 0) {
return;
}
+
+ shaper_profile_hash_node_refresh(ctx, pf_hash_node);
if (pf_hash_node->limit_direction == PROFILE_LIMIT_DIRECTION_BIDIRECTION) {
snprintf(key, sizeof(key), "tsg-shaping-%d-bidirectional", pf_info->id);
@@ -708,7 +729,7 @@ END:
}
}
-void shaper_profile_hash_node_update(struct shaping_thread_ctx *ctx, struct shaping_profile_info *profile)
+void shaper_profile_hash_node_set(struct shaping_thread_ctx *ctx, struct shaping_profile_info *profile)
{
if (profile->hash_node == NULL) {
struct shaping_profile_hash_node *hash_node = NULL;