diff mbox series

[ovs-dev,v2,06/10] ovn-northd-ddlog: Simplify LBVIPWithStatus to include up_backends string.

Message ID 20210907224516.489604-7-blp@ovn.org
State Accepted
Headers show
Series 3x performance improvement for ddlog with load balancer benchmark | expand

Checks

Context Check Description
ovsrobot/apply-robot success apply and check: success
ovsrobot/github-robot-_Build_and_Test fail github build: failed
ovsrobot/github-robot-_ovn-kubernetes fail github build: failed

Commit Message

Ben Pfaff Sept. 7, 2021, 10:45 p.m. UTC
There was only one use for the 'backends' map, which was to be converted
to a string that listed all the backends that were up, so we might as
well do that at its point of origination.  At the same time, everything
else in LBVIPWithStatus was just a copy of the underlying LBVIP, so we
might as well just reference it.

Only slight improvement to performance.

Signed-off-by: Ben Pfaff <blp@ovn.org>
---
 northd/lswitch.dl    | 32 ++++++++++++++------------------
 northd/ovn_northd.dl | 29 +++++++++--------------------
 2 files changed, 23 insertions(+), 38 deletions(-)
diff mbox series

Patch

diff --git a/northd/lswitch.dl b/northd/lswitch.dl
index ad6475a91..69b1c6eb5 100644
--- a/northd/lswitch.dl
+++ b/northd/lswitch.dl
@@ -445,25 +445,21 @@  function default_protocol(protocol: Option<istring>): istring = {
     }
 }
 
-typedef LBVIPWithStatus = LBVIPWithStatus {
-    lb: Intern<nb::Load_Balancer>,
-    vip_key: istring,
-    backend_ips: istring,
-    health_check: Option<Intern<nb::Load_Balancer_Health_Check>>,
-    vip_addr: v46_ip,
-    vip_port: bit<16>,
-    backends: Map<lb_vip_backend, bool>
-}
-relation LBVIPWithStatus[Intern<LBVIPWithStatus>]
-
-LBVIPWithStatus[LBVIPWithStatus{lb, vip_key, backend_ips, health_check, vip_addr, vip_port, map_empty()}.intern()] :-
-    &LBVIP(lb, vip_key, backend_ips, health_check, vip_addr, vip_port, vec_empty()).
-LBVIPWithStatus[LBVIPWithStatus{lb, vip_key, backend_ips, health_check, vip_addr, vip_port, backends_with_status}.intern()] :-
-    &LBVIP(lb, vip_key, backend_ips, health_check, vip_addr, vip_port, backends),
-    var backend = FlatMap(backends),
+relation LBVIPWithStatus(
+    lbvip: Intern<LBVIP>,
+    up_backends: istring)
+LBVIPWithStatus(lbvip, i"") :-
+    lbvip in &LBVIP(.backends = vec_empty()).
+LBVIPWithStatus(lbvip, up_backends) :-
     LBVIPBackendStatus(lbvip, backend, up),
-    var backends_with_status = ((backend, up)).group_by((lb, vip_key, backend_ips, health_check,
-                                                         vip_addr, vip_port)).to_map().
+    var up_backends = ((backend, up)).group_by(lbvip).to_vec().filter_map(|x| {
+        (LBVIPBackend{var ip, var port, _}, var up) = x;
+        match ((up, port)) {
+            (true, 0) -> Some{"${ip.to_bracketed_string()}"},
+            (true, _) -> Some{"${ip.to_bracketed_string()}:${port}"},
+            _ -> None
+        }
+    }).join(",").intern().
 
 /* Maps from a load-balancer virtual IP backend to whether it's up or not.
  *
diff --git a/northd/ovn_northd.dl b/northd/ovn_northd.dl
index bf2192f7e..5af41fa22 100644
--- a/northd/ovn_northd.dl
+++ b/northd/ovn_northd.dl
@@ -3177,7 +3177,7 @@  function get_match_for_lb_key(ip_address: v46_ip,
 }
 /* New connections in Ingress table. */
 
-function ct_lb(backends: string,
+function ct_lb(backends: istring,
                selection_fields: Set<istring>, protocol: Option<istring>): string {
     var args = vec_with_capacity(2);
     args.push("backends=${backends}");
@@ -3198,18 +3198,11 @@  function ct_lb(backends: string,
 
     "ct_lb(" ++ args.join("; ") ++ ");"
 }
-function build_lb_vip_actions(lbvip: Intern<LBVIPWithStatus>,
+function build_lb_vip_actions(lbvip: Intern<LBVIP>,
+                              up_backends: istring,
                               stage: Intern<Stage>,
                               actions0: string): (string, bool) {
-    var up_backends = vec_with_capacity(lbvip.backends.size());
-    for (pair in lbvip.backends) {
-        (var backend, var up) = pair;
-        if (up) {
-            up_backends.push((backend.ip, backend.port))
-        }
-    };
-
-    if (up_backends.is_empty()) {
+    if (up_backends == i"") {
         if (lbvip.lb.options.get_bool_def(i"reject", false)) {
             return ("reg0 = 0; reject { outport <-> inport; ${next_to_stage(stage)};};", true)
         } else if (lbvip.health_check.is_some()) {
@@ -3217,11 +3210,7 @@  function build_lb_vip_actions(lbvip: Intern<LBVIPWithStatus>,
         } // else fall through
     };
 
-    var up_backends_s = up_backends.sort_imm().map(|x| match (x) {
-        (ip, 0) -> "${ip.to_bracketed_string()}",
-        (ip, port) -> "${ip.to_bracketed_string()}:${port}"
-    }).join(",");
-    var actions = ct_lb(up_backends_s, lbvip.lb.selection_fields, lbvip.lb.protocol);
+    var actions = ct_lb(up_backends, lbvip.lb.selection_fields, lbvip.lb.protocol);
     (actions0 ++ actions, false)
 }
 Flow(.logical_datapath = sw._uuid,
@@ -3232,7 +3221,7 @@  Flow(.logical_datapath = sw._uuid,
      .io_port          = None,
      .controller_meter = meter,
      .stage_hint       = 0) :-
-    LBVIPWithStatus[lbvip@&LBVIPWithStatus{.lb = lb}],
+    LBVIPWithStatus(lbvip@&LBVIP{.lb = lb}, up_backends),
     var priority = if (lbvip.vip_port != 0) { 120 } else { 110 },
     (var actions, var reject) = {
         /* Store the original destination IP to be used when generating
@@ -3252,7 +3241,7 @@  Flow(.logical_datapath = sw._uuid,
             ""
         };
 
-        build_lb_vip_actions(lbvip, s_SWITCH_OUT_QOS_MARK(), actions0 ++ actions1)
+        build_lb_vip_actions(lbvip, up_backends, s_SWITCH_OUT_QOS_MARK(), actions0 ++ actions1)
     },
     var __match = "ct.new && " ++ get_match_for_lb_key(lbvip.vip_addr, lbvip.vip_port, lb.protocol, false, false, false),
     sw in &Switch(),
@@ -6843,9 +6832,9 @@  Flow(.logical_datapath = r._uuid,
      .io_port          = None,
      .controller_meter = meter,
      .stage_hint       = 0) :-
-    LBVIPWithStatus[lbvip@&LBVIPWithStatus{.lb = lb}],
+    LBVIPWithStatus(lbvip@&LBVIP{.lb = lb}, up_backends),
     var priority = if (lbvip.vip_port != 0) 120 else 110,
-    (var actions0, var reject) = build_lb_vip_actions(lbvip, s_ROUTER_OUT_SNAT(), ""),
+    (var actions0, var reject) = build_lb_vip_actions(lbvip, up_backends, s_ROUTER_OUT_SNAT(), ""),
     var match0 = "ct.new && " ++
         get_match_for_lb_key(lbvip.vip_addr, lbvip.vip_port, lb.protocol, true, true, true),
     r in &Router(),