Skip to contentSkip to conversation

Optimize COLO-compare performance

PATCH Superseded Zhang Chen 2 participants 9 messages Jul 7, 2017 Networking

v1 of 6 Superseded Latest is v6 →

lore
Share & tools
lore

Zhang Chen

author
#0 lore raw

cover Optimize COLO-compare performance

In this serise, we do a lot of job to optimize COLO net performance. Mainly focus on TCP protocol.

Zhang Chen (4):
net/colo-compare.c: Add checkpoint min period to optimize performance net/colo-compare.c: compare tcp packet base on sequence number net/colo-compare.c: Optimize unpredictable tcp options comparison net/colo-compare.c: Adjust net queue pop order for performance

 net/colo-compare.c | 57 ++++++++++++++++++++++++++++++++++++++++++------------
 1 file changed, 45 insertions(+), 12 deletions(-)
Signature · 1 line
2.7.4
author
#1 lore raw

PATCH 1/4 net/colo-compare.c: Add checkpoint min period to optimize performance

If colo-compare find out the first different packet that means the following packet almost is different. we needn't do a lot of checkpoint in this time, so we set the no-need-checkpoint peroid, default just set 3 second.

---
 net/colo-compare.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)
net/colo-compare.c +12 -1
index 6d500e1..0f8e198 100644
@@ -40,6 +40,9 @@
 /* TODO: Should be configurable */
 #define REGULAR_PACKET_CHECK_MS 3000
 
+/* TODO: Should be configurable */
+#define CHECKPOINT_MIN_TIME 3000
+
 /*
   + CompareState ++
   |               |
@@ -455,6 +458,7 @@ static void colo_compare_connection(void *opaque, void *user_data)
     Packet *pkt = NULL;
     GList *result = NULL;
     int ret;
+    static int64_t checkpoint_time_ms;
 
     while (!g_queue_is_empty(&conn->primary_list) &&
            !g_queue_is_empty(&conn->secondary_list)) {
@@ -494,7 +498,14 @@ static void colo_compare_connection(void *opaque, void *user_data)
              */
             trace_colo_compare_main("packet different");
             g_queue_push_tail(&conn->primary_list, pkt);
-            /* TODO: colo_notify_checkpoint();*/
+
+            if (pkt->creation_ms - checkpoint_time_ms > CHECKPOINT_MIN_TIME) {
+                /*
+                 * TODO: Notify colo frame to do checkpoint.
+                 * colo_compare_inconsistent_notify();
+                 */
+                checkpoint_time_ms = pkt->creation_ms;
+            }
             break;
         }
     }
Signature · 1 line
2.7.4
#2 lore raw

Re: [Qemu-devel] [PATCH 1/4] net/colo-compare.c: Add checkpoint min period to optimize performance

Quoted 1 line · Zhang Chen

If colo-compare find out the first different packet

at this situation, why not trigger the checkpoint, and then flush all primary packets and drop secondary packets?

Quoted 48 lines

that means
the following packet almost is different. we needn't do a lot of checkpoint in this time, so we set the no-need-checkpoint peroid, default just set 3 second.

---
  net/colo-compare.c | 13 ++++++++++++-
  1 file changed, 12 insertions(+), 1 deletion(-)
net/colo-compare.c +12 -1
index 6d500e1..0f8e198 100644
@@ -40,6 +40,9 @@
  /* TODO: Should be configurable */
  #define REGULAR_PACKET_CHECK_MS 3000
 
+/* TODO: Should be configurable */
+#define CHECKPOINT_MIN_TIME 3000
+
  /*
    + CompareState ++
    |               |
@@ -455,6 +458,7 @@ static void colo_compare_connection(void *opaque, void *user_data)
      Packet *pkt = NULL;
      GList *result = NULL;
      int ret;
+    static int64_t checkpoint_time_ms;
 
      while (!g_queue_is_empty(&conn->primary_list) &&
             !g_queue_is_empty(&conn->secondary_list)) {
@@ -494,7 +498,14 @@ static void colo_compare_connection(void *opaque, void *user_data)
               */
              trace_colo_compare_main("packet different");
              g_queue_push_tail(&conn->primary_list, pkt);
-            /* TODO: colo_notify_checkpoint();*/
+
+            if (pkt->creation_ms - checkpoint_time_ms > CHECKPOINT_MIN_TIME) {
+                /*
+                 * TODO: Notify colo frame to do checkpoint.
+                 * colo_compare_inconsistent_notify();
+                 */
+                checkpoint_time_ms = pkt->creation_ms;
+            }
              break;
          }
      }
Signature · 2 lines
Best regards.
Li Zhijian (8528)
author
#3 lore raw

Re: [Qemu-devel] [PATCH 1/4] net/colo-compare.c: Add checkpoint min period to optimize performance

Quoted 5 lines · Li Zhijian
Quoted 1 line · Zhang Chen

If colo-compare find out the first different packet

at this situation, why not trigger the checkpoint, and then flush all primary packets and drop secondary packets?

In this time we already do this job, but before this checkpoint to be done,
a lot of checkpoint has been triggered. It is no sense do many checkpoint in very short time. So we just need do once checkpoint in this situation.

Thanks
Zhang Chen

Quoted 52 lines
Quoted 51 lines

that means
the following packet almost is different. we needn't do a lot of checkpoint in this time, so we set the no-need-checkpoint peroid, default just set 3 second.

---
  net/colo-compare.c | 13 ++++++++++++-
  1 file changed, 12 insertions(+), 1 deletion(-)
net/colo-compare.c +11 -1
index 6d500e1..0f8e198 100644
@@ -40,6 +40,9 @@
  /* TODO: Should be configurable */
  #define REGULAR_PACKET_CHECK_MS 3000
  +/* TODO: Should be configurable */
+#define CHECKPOINT_MIN_TIME 3000
+
  /*
    + CompareState ++
    |               |
@@ -455,6 +458,7 @@ static void colo_compare_connection(void *opaque, 
 void *user_data)
      Packet *pkt = NULL;
      GList *result = NULL;
      int ret;
+    static int64_t checkpoint_time_ms;
        while (!g_queue_is_empty(&conn->primary_list) &&
             !g_queue_is_empty(&conn->secondary_list)) {
@@ -494,7 +498,14 @@ static void colo_compare_connection(void 
 *opaque, void *user_data)
               */
              trace_colo_compare_main("packet different");
              g_queue_push_tail(&conn->primary_list, pkt);
-            /* TODO: colo_notify_checkpoint();*/
+
+            if (pkt->creation_ms - checkpoint_time_ms > 
 CHECKPOINT_MIN_TIME) {
+                /*
+                 * TODO: Notify colo frame to do checkpoint.
+                 * colo_compare_inconsistent_notify();
+                 */
+                checkpoint_time_ms = pkt->creation_ms;
+            }
              break;
          }
      }
Signature · 2 lines
Thanks
Zhang Chen
author
#4 lore raw

PATCH 2/4 net/colo-compare.c: compare tcp packet base on sequence number

In reply to Zhang Chen

If primary packet's sequence number not same with secondary packet's sequence number, no need to compare the packet other field.

---
 net/colo-compare.c | 6 ++++++
 1 file changed, 6 insertions(+)
net/colo-compare.c +6 -0
index 0f8e198..2caeb80 100644
@@ -222,6 +222,12 @@ static int colo_packet_compare_tcp(Packet *spkt, Packet *ppkt)
     ptcp = (struct tcphdr *)ppkt->transport_header;
     stcp = (struct tcphdr *)spkt->transport_header;
 
+    if ((ptcp->th_flags & TH_SYN) != TH_SYN &&
+        ptcp->th_seq != stcp->th_seq) {
+        trace_colo_compare_main("colo_packet_compare_tcp seq not same");
+        return -1;
+    }
+
     /*
      * The 'identification' field in the IP header is *very* random
      * it almost never matches.  Fudge this by ignoring differences in
Signature · 1 line
2.7.4
#5 lore raw

Re: [Qemu-devel] [PATCH 2/4] net/colo-compare.c: compare tcp packet base on sequence number

this title confused me

i think you want to express "only compare the packets that has the same sequence number"

and i think this optimization can not reduce this checkpoint optimization.

Thanks

Quoted 25 lines · Zhang Chen

If primary packet's sequence number not same with secondary packet's sequence number, no need to compare the packet other field.

---
  net/colo-compare.c | 6 ++++++
  1 file changed, 6 insertions(+)
net/colo-compare.c +6 -0
index 0f8e198..2caeb80 100644
@@ -222,6 +222,12 @@ static int colo_packet_compare_tcp(Packet *spkt, Packet *ppkt)
      ptcp = (struct tcphdr *)ppkt->transport_header;
      stcp = (struct tcphdr *)spkt->transport_header;
 
+    if ((ptcp->th_flags & TH_SYN) != TH_SYN &&
+        ptcp->th_seq != stcp->th_seq) {
+        trace_colo_compare_main("colo_packet_compare_tcp seq not same");
+        return -1;
+    }
+
      /*
       * The 'identification' field in the IP header is *very* random
       * it almost never matches.  Fudge this by ignoring differences in
author
#6 lore raw

Re: [Qemu-devel] [PATCH 2/4] net/colo-compare.c: compare tcp packet base on sequence number

Quoted 3 lines · Li Zhijian

this title confused me

i think you want to express "only compare the packets that has the same sequence number"

OK, I will fix it in next version.

Quoted 3 lines

and i think this optimization can not reduce this checkpoint optimization.

In my test it can reduce many full comparison(like memcmp), and in the future we have some job about this point.

Thanks
Zhang Chen

Quoted 33 lines

Thanks

Quoted 16 lines · Zhang Chen

If primary packet's sequence number not same with secondary packet's sequence number, no need to compare the packet other field.

---
  net/colo-compare.c | 6 ++++++
  1 file changed, 6 insertions(+)
net/colo-compare.c +0 -0
index 0f8e198..2caeb80 100644
@@ -222,6 +222,12 @@ static int colo_packet_compare_tcp(Packet *spkt, 
 Packet *ppkt)
      ptcp = (struct tcphdr *)ppkt->transport_header;
      stcp = (struct tcphdr *)spkt->transport_header;

net/colo-compare.c static int colo_packet_compare_tcp(Packet *spkt, · line 233

Quoted 10 lines
net/colo-compare.c +5 -0
  +    if ((ptcp->th_flags & TH_SYN) != TH_SYN &&
+        ptcp->th_seq != stcp->th_seq) {
+        trace_colo_compare_main("colo_packet_compare_tcp seq not 
 same");
+        return -1;
+    }
+
      /*
       * The 'identification' field in the IP header is *very* random
       * it almost never matches.  Fudge this by ignoring differences in

.

Signature · 2 lines
Thanks
Zhang Chen
author
#7 lore raw

PATCH 3/4 net/colo-compare.c: Optimize unpredictable tcp options comparison

In reply to Zhang Chen

When network is busy, some tcp options(like sack) will unpredictable occur in primary side or secondary side. it will make packet size not same, but the two packet's payload is identical. colo just care about packet payload, so we skip the option field.

---
 net/colo-compare.c | 34 +++++++++++++++++++++++++---------
 1 file changed, 25 insertions(+), 9 deletions(-)
net/colo-compare.c +25 -9
index 2caeb80..6406c4a 100644
@@ -183,7 +183,10 @@ static int packet_enqueue(CompareState *s, int mode)
  * return:    0  means packet same
  *            > 0 || < 0 means packet different
  */
-static int colo_packet_compare_common(Packet *ppkt, Packet *spkt, int offset)
+static int colo_packet_compare_common(Packet *ppkt,
+                                      Packet *spkt,
+                                      int poffset,
+                                      int soffset)
 {
     if (trace_event_get_state(TRACE_COLO_COMPARE_MISCOMPARE)) {
         char pri_ip_src[20], pri_ip_dst[20], sec_ip_src[20], sec_ip_dst[20];
@@ -198,9 +201,10 @@ static int colo_packet_compare_common(Packet *ppkt, Packet *spkt, int offset)
                                    sec_ip_src, sec_ip_dst);
     }
 
-    if (ppkt->size == spkt->size) {
-        return memcmp(ppkt->data + offset, spkt->data + offset,
-                      spkt->size - offset);
+    if (ppkt->size == spkt->size || poffset != soffset) {
+        return memcmp(ppkt->data + poffset,
+                      spkt->data + soffset,
+                      spkt->size - soffset);
     } else {
         trace_colo_compare_main("Net packet size are not the same");
         return -1;
@@ -263,12 +267,22 @@ static int colo_packet_compare_tcp(Packet *spkt, Packet *ppkt)
      * so we just need skip this field.
      */
     if (ptcp->th_off > 5) {
-        ptrdiff_t tcp_offset;
-        tcp_offset = ppkt->transport_header - (uint8_t *)ppkt->data
+        ptrdiff_t ptcp_offset, stcp_offset;
+
+        ptcp_offset = ppkt->transport_header - (uint8_t *)ppkt->data
                      + (ptcp->th_off * 4);
-        res = colo_packet_compare_common(ppkt, spkt, tcp_offset);
+        stcp_offset = spkt->transport_header - (uint8_t *)spkt->data
+                     + (stcp->th_off * 4);
+
+        /*
+         * When network is busy, some tcp options(like sack) will unpredictable
+         * occur in primary side or secondary side. it will make packet size
+         * not same, but the two packet's payload is identical. colo just
+         * care about packet payload, so we skip the option field.
+         */
+        res = colo_packet_compare_common(ppkt, spkt, ptcp_offset, stcp_offset);
     } else if (ptcp->th_sum == stcp->th_sum) {
-        res = colo_packet_compare_common(ppkt, spkt, ETH_HLEN);
+        res = colo_packet_compare_common(ppkt, spkt, ETH_HLEN, ETH_HLEN);
     } else {
         res = -1;
     }
@@ -328,6 +342,7 @@ static int colo_packet_compare_udp(Packet *spkt, Packet *ppkt)
      * the ip payload here.
      */
     ret = colo_packet_compare_common(ppkt, spkt,
+                                     network_header_length + ETH_HLEN,
                                      network_header_length + ETH_HLEN);
 
     if (ret) {
@@ -365,6 +380,7 @@ static int colo_packet_compare_icmp(Packet *spkt, Packet *ppkt)
      * the ip payload here.
      */
     if (colo_packet_compare_common(ppkt, spkt,
+                                   network_header_length + ETH_HLEN,
                                    network_header_length + ETH_HLEN)) {
         trace_colo_compare_icmp_miscompare("primary pkt size",
                                            ppkt->size);
@@ -402,7 +418,7 @@ static int colo_packet_compare_other(Packet *spkt, Packet *ppkt)
                                    sec_ip_src, sec_ip_dst);
     }
 
-    return colo_packet_compare_common(ppkt, spkt, 0);
+    return colo_packet_compare_common(ppkt, spkt, 0, 0);
 }
 
 static int colo_old_packet_check_one(Packet *pkt, int64_t *check_time)
Signature · 1 line
2.7.4
author
#8 lore raw

PATCH 4/4 net/colo-compare.c: Adjust net queue pop order for performance

In reply to Zhang Chen

The packet_enqueue() use g_queue_push_tail() to
enqueue net packet, so it is more efficent way use g_queue_pop_head() to get packet for compare.
That will improve the success rate of comparison.
In my test the performance of ftp put 1000M file will increase 10%

---
 net/colo-compare.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
net/colo-compare.c +2 -2
index 6406c4a..9397269 100644
@@ -484,7 +484,7 @@ static void colo_compare_connection(void *opaque, void *user_data)
 
     while (!g_queue_is_empty(&conn->primary_list) &&
            !g_queue_is_empty(&conn->secondary_list)) {
-        pkt = g_queue_pop_tail(&conn->primary_list);
+        pkt = g_queue_pop_head(&conn->primary_list);
         switch (conn->ip_proto) {
         case IPPROTO_TCP:
             result = g_queue_find_custom(&conn->secondary_list,
@@ -519,7 +519,7 @@ static void colo_compare_connection(void *opaque, void *user_data)
              * until next comparison.
              */
             trace_colo_compare_main("packet different");
-            g_queue_push_tail(&conn->primary_list, pkt);
+            g_queue_push_head(&conn->primary_list, pkt);
 
             if (pkt->creation_ms - checkpoint_time_ms > CHECKPOINT_MIN_TIME) {
                 /*
Signature · 1 line
2.7.4