Optimize COLO-compare performance
cover Optimize COLO-compare performance
In this series, adjust the way that the packet are queued and compared to improve the colo net performence.
Mao Zhongyi (4):
colo-compare: Insert packet into the suitable position of packet queue
directly
colo-compare: compare the packet in a specified Connection
colo-compare: Fix comments
colo: Consolidate the duplicate code chunk into a routine
net/colo-compare.c | 61 +++++++++++++++++++++++++++++++----------------------- net/colo.c | 18 +++++++++------- net/colo.h | 1 + 3 files changed, 46 insertions(+), 34 deletions(-)
Signature · 1 line
2.9.4
PATCH 1/4 colo-compare: Insert packet into the suitable position of packet queue directly
Currently, a packet from pri_dev or sec_dev is fristly pushed at the tail of the primary or secondary packet queue then sorted by the tcp sequence number.
Now, this patch use g_queue_insert_sorted to insert the packet directly into the suitable position to avoid ordering all packets each time when a new packet is comming, thereby increasing efficiency.
In addition, consolidate the code that add a packet to the list of Connection (primary or secondary) into a separate routine colo_insert_packet() since the same chunk of code is called from two place.
--- net/colo-compare.c | 40 ++++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 18 deletions(-)
net/colo-compare.c +22 -18
@@ -113,6 +113,26 @@ static gint seq_sorter(Packet *a, Packet *b, gpointer data) }/* +* Return 1 on success, if return 0 means the +* packet will be dropped +*/ +static int colo_insert_packet (GQueue *queue,Packet *pkt) +{ +if (g_queue_get_length (queue) <=MAX_QUEUE_SIZE ) { +if (pkt->ip->ip_p ==IPPROTO_TCP ) { +g_queue_insert_sorted (queue, + pkt, + (GCompareDataFunc )seq_sorter, +NULL ); + }else { +g_queue_push_tail (queue, pkt); + } +return 1 ; + } +return 0 ; +} + +/* * Return 0 on success, if return -1 means the pkt * is unsupported(arp and ipv6) and will be sent later */
@@ -149,28 +169,12 @@ static int packet_enqueue(CompareState *s, int mode) }if (mode ==PRIMARY_IN ) { -if (g_queue_get_length (&conn->primary_list) <= -MAX_QUEUE_SIZE ) { -g_queue_push_tail (&conn->primary_list, pkt); -if (conn->ip_proto ==IPPROTO_TCP ) { -g_queue_sort (&conn->primary_list, - (GCompareDataFunc )seq_sorter, -NULL ); - } - }else { +if (!colo_insert_packet (&conn->primary_list, pkt)) {error_report ("colo compare primary queue size too big," "drop packet" ); } }else { -if (g_queue_get_length (&conn->secondary_list) <= -MAX_QUEUE_SIZE ) { -g_queue_push_tail (&conn->secondary_list, pkt); -if (conn->ip_proto ==IPPROTO_TCP ) { -g_queue_sort (&conn->secondary_list, - (GCompareDataFunc )seq_sorter, -NULL ); - } - }else { +if (!colo_insert_packet (&conn->secondary_list, pkt)) {error_report ("colo compare secondary queue size too big," "drop packet" ); }
Signature · 1 line
2.9.4
PATCH 2/4 colo-compare: compare the packet in a specified Connection
In reply to Mao ZhongyiA package from pri_indev or sec_indev only belongs to a particular Connection, so we only need to compare the package in the specified Connection's primary_list and secondary_list, rather than for each the whole Connection list to compare. This is time-consuming and unnecessary.
Less checkpoint more efficiency.
--- net/colo-compare.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-)
net/colo-compare.c +8 -5
@@ -136,7 +136,7 @@ static int colo_insert_packet(GQueue *queue, Packet *pkt)* Return 0 on success, if return -1 means the pkt * is unsupported(arp and ipv6) and will be sent later */ -static int packet_enqueue (CompareState *s,int mode) +static int packet_enqueue (CompareState *s,int mode,Connection **con) {ConnectionKey key;Packet *pkt =NULL ;
@@ -179,6 +179,7 @@ static int packet_enqueue(CompareState *s, int mode) "drop packet"); } } + con = &conn;return 0 ; }
@@ -728,8 +729,9 @@ static void compare_set_vnet_hdr(Object *obj,static void compare_pri_rs_finalize (SocketReadState *pri_rs) {CompareState *s =container_of (pri_rs, CompareState, pri_rs); +Connection *conn =NULL ; -if (packet_enqueue (s,PRIMARY_IN )) { +if (packet_enqueue (s,PRIMARY_IN , &conn)) {trace_colo_compare_main ("primary: unsupported packet in" ); compare_chr_send(s, pri_rs->buf,
@@ -737,19 +739,20 @@ static void compare_pri_rs_finalize(SocketReadState *pri_rs) pri_rs->vnet_hdr_len); }else {/* compare connection */ -g_queue_foreach (&s->conn_list, colo_compare_connection, s); +colo_compare_connection (conn, s); } }static void compare_sec_rs_finalize (SocketReadState *sec_rs) {CompareState *s =container_of (sec_rs, CompareState, sec_rs); +Connection *conn =NULL ; -if (packet_enqueue (s,SECONDARY_IN )) { +if (packet_enqueue (s,SECONDARY_IN , &conn)) {trace_colo_compare_main ("secondary: unsupported packet in" ); }else {/* compare connection */ -g_queue_foreach (&s->conn_list, colo_compare_connection, s); +colo_compare_connection (conn, s); } }
Signature · 1 line
2.9.4
PATCH 3/4 colo-compare: Fix comments
In reply to Mao Zhongyi--- net/colo-compare.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
net/colo-compare.c +5 -3
@@ -480,7 +480,9 @@ static void colo_old_packet_check(void *opaque)/* * Called from the compare thread on the primary -* for compare connection +* for compare packet with secondary list of the +* specified connection when a new packet was +* queued to it. */ static void colo_compare_connection (void *opaque,void *user_data) {
@@ -738,7 +740,7 @@ static void compare_pri_rs_finalize(SocketReadState *pri_rs) pri_rs->packet_len, pri_rs->vnet_hdr_len); }else { -/* compare connection */ +/* compare packet in the specified connection */ colo_compare_connection (conn, s); } }
@@ -751,7 +753,7 @@ static void compare_sec_rs_finalize(SocketReadState *sec_rs)if (packet_enqueue (s,SECONDARY_IN , &conn)) {trace_colo_compare_main ("secondary: unsupported packet in" ); }else { -/* compare connection */ +/* compare packet in the specified connection */ colo_compare_connection (conn, s); } }
Signature · 1 line
2.9.4
PATCH 4/4 colo: Consolidate the duplicate code chunk into a routine
In reply to Mao ZhongyiConsolidate the code that extract the ip address(src,dst) and port number(src,dst) of the packet into a separate routine extract_ip_and_port() since the same chunk of code is called from two place.
--- net/colo.c | 18 ++++++++++-------- net/colo.h | 1 + 2 files changed, 11 insertions(+), 8 deletions(-)
net/colo.c +10 -8
@@ -82,6 +82,14 @@ int parse_packet_early(Packet *pkt)return 0 ; } +void extract_ip_and_port (uint32_t tmp_ports,ConnectionKey *key,Packet *pkt) +{ + key->src = pkt->ip->ip_src; + key->dst = pkt->ip->ip_dst; + key->src_port =ntohs (tmp_ports >>16 ); + key->dst_port =ntohs (tmp_ports &0xffff ); +} +void fill_connection_key (Packet *pkt,ConnectionKey *key) {uint32_t tmp_ports;
@@ -97,17 +105,11 @@ void fill_connection_key(Packet *pkt, ConnectionKey *key)case IPPROTO_SCTP :case IPPROTO_UDPLITE : tmp_ports = *(uint32_t *)(pkt->transport_header); - key->src = pkt->ip->ip_src; - key->dst = pkt->ip->ip_dst; - key->src_port =ntohs (tmp_ports &0xffff ); - key->dst_port =ntohs (tmp_ports >>16 ); +extract_ip_and_port (tmp_ports, key, pkt);break ;case IPPROTO_AH : tmp_ports = *(uint32_t *)(pkt->transport_header +4 ); - key->src = pkt->ip->ip_src; - key->dst = pkt->ip->ip_dst; - key->src_port =ntohs (tmp_ports &0xffff ); - key->dst_port =ntohs (tmp_ports >>16 ); +extract_ip_and_port (tmp_ports, key, pkt);break ;default :break ;
net/colo.h +1 -0
@@ -76,6 +76,7 @@ typedef struct Connection {uint32_t connection_key_hash (const void *opaque);int connection_key_equal (const void *opaque1,const void *opaque2);int parse_packet_early (Packet *pkt); +void extract_ip_and_port (uint32_t tmp_ports,ConnectionKey *key,Packet *pkt);void fill_connection_key (Packet *pkt,ConnectionKey *key);void reverse_connection_key (ConnectionKey *key);Connection *connection_new (ConnectionKey *key);
Signature · 1 line
2.9.4
Jason Wang
AppliedQuoted 14 lines · Mao Zhongyi
In this series, adjust the way that the packet are queued and compared to improve the colo net performence.
Mao Zhongyi (4):
colo-compare: Insert packet into the suitable position of packet queue
directly
colo-compare: compare the packet in a specified Connection
colo-compare: Fix comments
colo: Consolidate the duplicate code chunk into a routine
Quoted 5 lines
net/colo-compare.c | 61 +++++++++++++++++++++++++++++++----------------------- net/colo.c | 18 +++++++++------- net/colo.h | 1 + 3 files changed, 46 insertions(+), 34 deletions(-)
Applied.
Thanks