You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by we...@apache.org on 2025/05/29 02:57:54 UTC

(apisix) branch master updated: perf: compare service discovery nodes by addresss (#12258)

This is an automated email from the ASF dual-hosted git repository.

wenming pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/apisix.git


The following commit(s) were added to refs/heads/master by this push:
     new 77e33f9ed perf: compare service discovery nodes by addresss (#12258)
77e33f9ed is described below

commit 77e33f9ed6ef3a68fd2253eadb8895a5dda83f4e
Author: Nic <qi...@api7.ai>
AuthorDate: Thu May 29 10:57:48 2025 +0800

    perf: compare service discovery nodes by addresss (#12258)
---
 apisix/upstream.lua       | 27 ++++++++++++---------------
 apisix/utils/upstream.lua |  4 ++++
 2 files changed, 16 insertions(+), 15 deletions(-)

diff --git a/apisix/upstream.lua b/apisix/upstream.lua
index ef70477f7..624cb031b 100644
--- a/apisix/upstream.lua
+++ b/apisix/upstream.lua
@@ -108,7 +108,8 @@ local function create_checker(upstream)
     end
 
     local healthcheck_parent = upstream.parent
-    if healthcheck_parent.checker and healthcheck_parent.checker_upstream == upstream then
+    if healthcheck_parent.checker and healthcheck_parent.checker_upstream == upstream
+        and healthcheck_parent.checker_nodes_ver == upstream._nodes_ver then
         return healthcheck_parent.checker
     end
 
@@ -175,6 +176,7 @@ local function create_checker(upstream)
 
     healthcheck_parent.checker = checker
     healthcheck_parent.checker_upstream = upstream
+    healthcheck_parent.checker_nodes_ver = upstream._nodes_ver
     healthcheck_parent.checker_idx = check_idx
 
     upstream.is_creating_checker = nil
@@ -302,27 +304,21 @@ function _M.set_by_route(route, api_ctx)
 
         local same = upstream_util.compare_upstream_node(up_conf, new_nodes)
         if not same then
+            if not up_conf._nodes_ver then
+                up_conf._nodes_ver = 0
+            end
+            up_conf._nodes_ver = up_conf._nodes_ver + 1
+
             local pass, err = core.schema.check(core.schema.discovery_nodes, new_nodes)
             if not pass then
                 return HTTP_CODE_UPSTREAM_UNAVAILABLE, "invalid nodes format: " .. err
             end
 
-            local new_up_conf = core.table.clone(up_conf)
-            new_up_conf.nodes = new_nodes
-            new_up_conf.original_nodes = up_conf.nodes
+            up_conf.nodes = new_nodes
 
             core.log.info("discover new upstream from ", up_conf.service_name, ", type ",
                           up_conf.discovery_type, ": ",
-                          core.json.delay_encode(new_up_conf, true))
-
-            local parent = up_conf.parent
-            if parent.value.upstream then
-                -- the up_conf comes from route or service
-                parent.value.upstream = new_up_conf
-            else
-                parent.value = new_up_conf
-            end
-            up_conf = new_up_conf
+                          core.json.delay_encode(up_conf, true))
         end
     end
 
@@ -330,7 +326,8 @@ function _M.set_by_route(route, api_ctx)
     local conf_version = up_conf.parent.modifiedIndex
     -- include the upstream object as part of the version, because the upstream will be changed
     -- by service discovery or dns resolver.
-    set_directly(api_ctx, id, conf_version .. "#" .. tostring(up_conf), up_conf)
+    set_directly(api_ctx, id, conf_version .. "#" .. tostring(up_conf) .. "#"
+                                    .. tostring(up_conf._nodes_ver or ''), up_conf)
 
     local nodes_count = up_conf.nodes and #up_conf.nodes or 0
     if nodes_count == 0 then
diff --git a/apisix/utils/upstream.lua b/apisix/utils/upstream.lua
index c39d4cce2..d79ce3cfd 100644
--- a/apisix/utils/upstream.lua
+++ b/apisix/utils/upstream.lua
@@ -35,6 +35,10 @@ local function compare_upstream_node(up_conf, new_t)
     end
 
     local old_t = up_conf.original_nodes or up_conf.nodes
+    if old_t == new_t then
+        return true
+    end
+
     if type(old_t) ~= "table" then
         return false
     end