summaryrefslogtreecommitdiff
path: root/shaping/src/shaper_stat.cpp
diff options
context:
space:
mode:
authorroot <[email protected]>2024-01-22 08:08:30 +0000
committerroot <[email protected]>2024-01-22 08:08:30 +0000
commit4bc81cc24f2989b84670c54252585c5403acbc01 (patch)
treef975da4d76e1ecbaa1415c21a7d348b89600658b /shaping/src/shaper_stat.cpp
parentf0c91c0cfd4ec5a8f3e6636605484f1467c40a1f (diff)
add aqm blue algorithm temp code, and some performance optimize
Diffstat (limited to 'shaping/src/shaper_stat.cpp')
-rw-r--r--shaping/src/shaper_stat.cpp58
1 files changed, 38 insertions, 20 deletions
diff --git a/shaping/src/shaper_stat.cpp b/shaping/src/shaper_stat.cpp
index 735e154..75db668 100644
--- a/shaping/src/shaper_stat.cpp
+++ b/shaping/src/shaper_stat.cpp
@@ -14,7 +14,7 @@
#define SHAPER_STAT_ROW_NAME "traffic_shaping_rule_hits"
-#define SHAPER_STAT_REFRESH_TIME_NS 10000000 //10 ms
+#define SHAPER_STAT_REFRESH_TIME_US 10000 //10 ms
struct shaper_stat_conf {
int enable_backgroud_thread;
@@ -150,6 +150,7 @@ static void shaper_stat_swarmkv_hincrby_cb(const struct swarmkv_reply *reply, vo
if (reply->type != SWARMKV_REPLY_INTEGER) {
shaper_global_stat_async_hincrby_failed_inc(&ctx->thread_global_stat);
+ arg->start_time_us = curr_time_us;
shaper_global_stat_async_invoke_inc(&ctx->thread_global_stat);//hincrby failed, retry
shaper_global_stat_hincrby_invoke_inc(&ctx->thread_global_stat);
@@ -164,13 +165,37 @@ static void shaper_stat_swarmkv_hincrby_cb(const struct swarmkv_reply *reply, vo
return;
}
-static void shaper_stat_profile_metirc_refresh(struct shaping_thread_ctx *ctx, int vsys_id, int thread_id, int rule_id, struct shaping_profile_info *profile, int profile_type, int need_update_guage)
+static void shaper_stat_priority_queue_len_refresh(struct shaping_thread_ctx *ctx, struct shaping_profile_info *profile, int priority, long long curr_time_us)
+{
+ if (curr_time_us - profile->hash_node->local_queue_len_update_time_us[priority] < SHAPER_STAT_REFRESH_TIME_US) {
+ return;
+ }
+
+ struct shaping_hincrby_cb_arg *arg = (struct shaping_hincrby_cb_arg *)calloc(1, sizeof(struct shaping_hincrby_cb_arg));
+
+ arg->ctx = ctx;
+ arg->start_time_us = curr_time_us;
+ arg->profile_id = profile->id;
+ arg->priority = priority;
+ arg->queue_len = profile->hash_node->queue_len[priority];
+ shaper_global_stat_async_invoke_inc(&ctx->thread_global_stat);
+ shaper_global_stat_hincrby_invoke_inc(&ctx->thread_global_stat);
+ swarmkv_async_command(ctx->swarmkv_db, shaper_stat_swarmkv_hincrby_cb, arg, "HINCRBY tsg-shaping-%d priority-%d %lld", arg->profile_id, arg->priority, arg->queue_len);
+
+ profile->hash_node->local_queue_len_update_time_us[priority] = curr_time_us;
+ profile->hash_node->queue_len[priority] = 0;
+
+ return;
+}
+
+static void shaper_stat_profile_metirc_refresh(struct shaping_thread_ctx *ctx, struct shaping_rule_info *rule, int thread_id, struct shaping_profile_info *profile, int profile_type, int need_update_guage, long long curr_time_us)
{
struct shaping_stat_for_profile *profile_stat = &profile->stat;
struct shaping_stat *stat = ctx->stat;
+ int priority = profile->priority;
unsigned long long old_latency;
- shaper_stat_tags_build(vsys_id, rule_id, profile->id, profile->priority, profile_type);
+ shaper_stat_tags_build(rule->vsys_id, rule->id, profile->id, priority, profile_type);
fieldstat_dynamic_table_metric_value_incrby(stat->instance, stat->table_id, stat->column_ids[IN_DROP_PKTS_IDX], SHAPER_STAT_ROW_NAME, profile_stat->in.drop_pkts, tags, TAG_IDX_MAX, thread_id);
fieldstat_dynamic_table_metric_value_incrby(stat->instance, stat->table_id, stat->column_ids[IN_PKTS_IDX], SHAPER_STAT_ROW_NAME, profile_stat->in.pkts, tags, TAG_IDX_MAX, thread_id);
fieldstat_dynamic_table_metric_value_incrby(stat->instance, stat->table_id, stat->column_ids[IN_BYTES_IDX], SHAPER_STAT_ROW_NAME, profile_stat->in.bytes, tags, TAG_IDX_MAX, thread_id);
@@ -195,18 +220,8 @@ static void shaper_stat_profile_metirc_refresh(struct shaping_thread_ctx *ctx, i
fieldstat_dynamic_table_metric_value_incrby(stat->instance, stat->table_id, stat->column_ids[OUT_QUEUE_LEN_IDX], SHAPER_STAT_ROW_NAME, profile_stat->out.queue_len, tags, TAG_IDX_MAX, thread_id);
}
- struct shaping_hincrby_cb_arg *arg = (struct shaping_hincrby_cb_arg *)calloc(1, sizeof(struct shaping_hincrby_cb_arg));
- struct timespec curr_time;
-
- clock_gettime(CLOCK_MONOTONIC, &curr_time);
- arg->ctx = ctx;
- arg->start_time_us = curr_time.tv_sec * MICRO_SECONDS_PER_SEC + curr_time.tv_nsec / NANO_SECONDS_PER_MICRO_SEC;
- arg->profile_id = profile->id;
- arg->priority = profile->priority;
- arg->queue_len = profile_stat->in.queue_len + profile_stat->out.queue_len;
- shaper_global_stat_async_invoke_inc(&ctx->thread_global_stat);
- shaper_global_stat_hincrby_invoke_inc(&ctx->thread_global_stat);
- swarmkv_async_command(ctx->swarmkv_db, shaper_stat_swarmkv_hincrby_cb, arg, "HINCRBY tsg-shaping-%d priority-%d %lld", arg->profile_id, arg->priority, arg->queue_len);
+ profile->hash_node->queue_len[priority] += profile_stat->in.queue_len + profile_stat->out.queue_len;
+ shaper_stat_priority_queue_len_refresh(ctx, profile, priority, curr_time_us);
memset(profile_stat, 0, sizeof(struct shaping_stat_for_profile));
} else {
@@ -229,14 +244,17 @@ void shaper_stat_refresh(struct shaping_thread_ctx *ctx, struct shaping_flow *sf
struct shaping_rule_info *rule;
struct timespec curr_time;
int need_refresh = 0;
+ long long curr_time_us;
+
+ 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;
if (force) {
need_refresh = 1;
} else {
- clock_gettime(CLOCK_MONOTONIC, &curr_time);
- if (curr_time.tv_sec - sf->stat_update_time.tv_sec > 0 || curr_time.tv_nsec - sf->stat_update_time.tv_nsec >= SHAPER_STAT_REFRESH_TIME_NS) {
+ if (curr_time_us - sf->stat_update_time_us >= SHAPER_STAT_REFRESH_TIME_US) {
need_refresh = 1;
- memcpy(&sf->stat_update_time, &curr_time, sizeof(struct timespec));
+ sf->stat_update_time_us = curr_time_us;
}
}
@@ -248,10 +266,10 @@ void shaper_stat_refresh(struct shaping_thread_ctx *ctx, struct shaping_flow *sf
for (int i = 0; i < sf->rule_num; i++) {
rule = &sf->matched_rule_infos[i];
- shaper_stat_profile_metirc_refresh(ctx, rule->vsys_id, thread_id, rule->id, &rule->primary, PROFILE_IN_RULE_TYPE_PRIMARY, need_update_guage);
+ shaper_stat_profile_metirc_refresh(ctx, rule, thread_id, &rule->primary, PROFILE_IN_RULE_TYPE_PRIMARY, need_update_guage, curr_time_us);
for (int j = 0; j < rule->borrowing_num; j++) {
- shaper_stat_profile_metirc_refresh(ctx, rule->vsys_id, thread_id, rule->id, &rule->borrowing[j], PROFILE_IN_RULE_TYPE_BORROW, need_update_guage);
+ shaper_stat_profile_metirc_refresh(ctx, rule, thread_id, &rule->borrowing[j], PROFILE_IN_RULE_TYPE_BORROW, need_update_guage, curr_time_us);
}
}