perf: 优化session_ctx减少内存占用; 优化global metrics的结构

This commit is contained in:
luwenpeng
2023-11-24 15:17:18 +08:00
parent bda50d79af
commit eedd18183e
12 changed files with 331 additions and 439 deletions

View File

@@ -9,20 +9,29 @@ extern "C"
#include "utils.h"
#include <MESA/field_stat2.h>
struct metrics_config
struct throughput_metrics
{
char output_file[256];
char statsd_server[32];
int statsd_port;
int statsd_format;
int statsd_cycle;
int prometheus_listen_port;
char prometheus_listen_url[256];
uint64_t n_pkts;
uint64_t n_bytes;
};
struct device_metrics
#define THROUGHPUT_METRICS_INC(iterm, _n_pkts, _n_bytes) \
do \
{ \
(iterm)->n_pkts += (_n_pkts); \
(iterm)->n_bytes += (_n_bytes); \
} while (0)
struct thread_metrics
{
// keepalived packet metrics
struct throughput_metrics downlink_rx; // 累计值
struct throughput_metrics downlink_tx; // 累计值
struct throughput_metrics uplink_rx; // 累计值
struct throughput_metrics uplink_tx_drop; // 累计值
// device packet metrics
struct throughput_metrics nf_rx; // 累计值
struct throughput_metrics nf_tx; // 累计值
@@ -33,11 +42,8 @@ struct device_metrics
struct throughput_metrics endpoint_vlan_rx; // 累计值
struct throughput_metrics endpoint_vlan_tx; // 累计值
struct throughput_metrics endpoint_vlan_drop; // 累计值
};
// data_pkt_metrics 不包含 vxlan frame 所占的字节
struct data_pkt_metrics
{
// data packet metrics 不包含 vxlan frame / vlan header 所占的字节
struct throughput_metrics mirr_bypass; // 累计值
struct throughput_metrics mirr_block; // 累计值
struct throughput_metrics mirr_rx_drop; // 累计值
@@ -51,61 +57,41 @@ struct data_pkt_metrics
struct throughput_metrics miss_sess; // 累计值
struct throughput_metrics error_bypass; // 累计值
struct throughput_metrics error_block; // 累计值
// control packet metrics
struct throughput_metrics ctrl_rx; // 累计值
struct throughput_metrics ctrl_tx; // 累计值
uint64_t ctrl_opening; // 累计值
uint64_t ctrl_active; // 累计值
uint64_t ctrl_closing; // 累计值
uint64_t ctrl_resetall; // 累计值
uint64_t ctrl_error; // 累计值
// sf status metrics
uint64_t sf_active; // 累计值
uint64_t sf_inactive; // 累计值
// sf session metrics
uint64_t session_num; // 当前值
uint64_t session_log; // 累计值
};
struct ctrl_pkt_metrics
struct metrics_config
{
struct throughput_metrics rx; // 累计值
struct throughput_metrics tx; // 累计值
char output_file[256];
char statsd_server[32];
int statsd_port;
int statsd_format;
int statsd_cycle;
uint64_t opening; // 累计值
uint64_t active; // 累计值
uint64_t closing; // 累计值
uint64_t resetall; // 累计值
uint64_t error; // 累计值
};
struct keepalived_pkt_metrics
{
struct throughput_metrics downlink_rx; // 累计值
struct throughput_metrics downlink_tx; // 累计值
struct throughput_metrics uplink_rx; // 累计值
struct throughput_metrics uplink_tx_drop; // 累计值
};
struct sf_status_metrics
{
uint64_t active; // 累计值
uint64_t inactive; // 累计值
};
struct sf_session_metrics
{
uint64_t num; // 当前值
uint64_t log; // 累计值
};
struct thread_metrics
{
struct device_metrics device;
struct data_pkt_metrics data_pkt;
struct ctrl_pkt_metrics ctrl_pkt;
struct keepalived_pkt_metrics kee_pkt;
struct sf_status_metrics sf_status;
struct sf_session_metrics sf_session;
int prometheus_listen_port;
char prometheus_listen_url[256];
};
struct global_metrics
{
struct device_metrics device;
struct data_pkt_metrics data_pkt;
struct ctrl_pkt_metrics ctrl_pkt;
struct keepalived_pkt_metrics kee_pkt;
struct sf_status_metrics sf_status;
struct sf_session_metrics sf_session;
struct thread_metrics sum;
struct metrics_config config;
screen_stat_handle_t fs_handle;