perf: 优化session_ctx减少内存占用; 优化global metrics的结构
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -12,6 +12,35 @@ extern "C"
|
||||
* Packet IO API for gtest
|
||||
******************************************************************************/
|
||||
|
||||
struct sids
|
||||
{
|
||||
sid_t elems[MR_SID_LIST_MAXLEN];
|
||||
int num;
|
||||
};
|
||||
|
||||
struct route_ctx
|
||||
{
|
||||
char data[64];
|
||||
int len;
|
||||
};
|
||||
|
||||
struct metadata
|
||||
{
|
||||
uint64_t session_id;
|
||||
uint32_t rehash_index;
|
||||
|
||||
char *raw_data; // refer to current packet data
|
||||
int raw_len;
|
||||
uint16_t l7offset;
|
||||
|
||||
int direction; // 1: E2I; 0: I2E
|
||||
int is_ctrl_pkt;
|
||||
int is_decrypted;
|
||||
|
||||
struct sids sids;
|
||||
struct route_ctx route_ctx;
|
||||
};
|
||||
|
||||
int mbuff_get_metadata(marsio_buff_t *rx_buff, struct metadata *meta);
|
||||
int mbuff_set_metadata(marsio_buff_t *tx_buff, struct metadata *meta);
|
||||
void vlan_encapsulate(marsio_buff_t *mbuff, int vlan_id, int replace_orig_vlan_header);
|
||||
|
||||
@@ -8,6 +8,7 @@ extern "C"
|
||||
|
||||
#include "utils.h"
|
||||
#include "packet.h"
|
||||
#include "global_metrics.h"
|
||||
#include <linux/if_ether.h>
|
||||
|
||||
enum traffic_type
|
||||
|
||||
@@ -39,31 +39,6 @@ struct thread_ctx
|
||||
uint64_t tx_packets_ipid;
|
||||
};
|
||||
|
||||
/******************************************************************************
|
||||
* Struct Metadata
|
||||
******************************************************************************/
|
||||
|
||||
struct metadata
|
||||
{
|
||||
int write_ref;
|
||||
uint64_t session_id;
|
||||
uint32_t rehash_index;
|
||||
|
||||
char *raw_data; // refer to current packet data
|
||||
int raw_len;
|
||||
uint16_t l7offset;
|
||||
|
||||
int direction; // 1: E2I; 0: I2E
|
||||
int is_ctrl_pkt;
|
||||
int is_decrypted;
|
||||
|
||||
struct sids sids;
|
||||
struct route_ctx route_ctx;
|
||||
};
|
||||
|
||||
int metadata_isempty(struct metadata *meta);
|
||||
void metadata_copy(struct metadata *dst, struct metadata *src);
|
||||
|
||||
char *memdup(const char *src, int len);
|
||||
|
||||
/******************************************************************************
|
||||
@@ -74,22 +49,32 @@ struct session_ctx
|
||||
{
|
||||
uint64_t session_id;
|
||||
char *session_addr;
|
||||
uint32_t rehash_index;
|
||||
|
||||
// dup from received control packet, for sending control packet
|
||||
char *ctrl_packet_header_data;
|
||||
uint16_t ctrl_packet_header_len;
|
||||
char *ctrl_pkt_hdr_ptr;
|
||||
uint16_t ctrl_pkt_hdr_len;
|
||||
|
||||
uint16_t vxlan_src_port;
|
||||
|
||||
struct four_tuple inner_tuple4;
|
||||
struct mutable_array rule_ids;
|
||||
|
||||
struct metadata decrypted_meta_i2e;
|
||||
struct metadata decrypted_meta_e2i;
|
||||
struct metadata raw_meta_i2e;
|
||||
struct metadata raw_meta_e2i;
|
||||
struct metadata ctrl_meta;
|
||||
// route ctx
|
||||
struct route_ctx decrypted_e2i_route_ctx;
|
||||
struct route_ctx decrypted_i2e_route_ctx;
|
||||
struct route_ctx raw_e2i_route_ctx;
|
||||
struct route_ctx raw_i2e_route_ctx;
|
||||
struct route_ctx ctrl_route_ctx;
|
||||
|
||||
// sids
|
||||
struct sids decrypted_e2i_sids;
|
||||
struct sids decrypted_i2e_sids;
|
||||
struct sids raw_e2i_sids;
|
||||
struct sids raw_i2e_sids;
|
||||
struct sids ctrl_sids;
|
||||
|
||||
// chaining
|
||||
struct selected_chaining *chaining_raw;
|
||||
struct selected_chaining *chaining_decrypted;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user