You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by me...@apache.org on 2020/10/05 15:19:53 UTC

[apisix] branch master updated: feat: also call picker.after_balance before retry (#2350)

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

membphis 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 16a2d4d  feat: also call picker.after_balance before retry (#2350)
16a2d4d is described below

commit 16a2d4dfa97a8b10cf37936aed8c0173b374d4a4
Author: 罗泽轩 <sp...@gmail.com>
AuthorDate: Mon Oct 5 23:19:40 2020 +0800

    feat: also call picker.after_balance before retry (#2350)
---
 apisix/balancer.lua      | 4 ++++
 apisix/balancer/ewma.lua | 7 ++++++-
 apisix/init.lua          | 2 +-
 3 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/apisix/balancer.lua b/apisix/balancer.lua
index cfe53b9..f2eec90 100644
--- a/apisix/balancer.lua
+++ b/apisix/balancer.lua
@@ -172,6 +172,10 @@ local function pick_server(route, ctx)
         return nil, "no valid upstream node"
     end
 
+    if ctx.server_picker and ctx.server_picker.after_balance then
+        ctx.server_picker.after_balance(ctx, true)
+    end
+
     if up_conf.timeout then
         local timeout = up_conf.timeout
         local ok, err = set_timeouts(timeout.connect, timeout.send,
diff --git a/apisix/balancer/ewma.lua b/apisix/balancer/ewma.lua
index 5198c28..bdc7722 100644
--- a/apisix/balancer/ewma.lua
+++ b/apisix/balancer/ewma.lua
@@ -146,7 +146,12 @@ local function _ewma_find(ctx, up_nodes)
 end
 
 
-local function _ewma_after_balance(ctx)
+local function _ewma_after_balance(ctx, before_retry)
+    if before_retry then
+        -- don't count tries which fail to complete
+        return nil
+    end
+
     local response_time = tonumber(ctx.var.upstream_response_time) or 0
     local connect_time = tonumber(ctx.var.upstream_connect_time) or 0
     local rtt = connect_time + response_time
diff --git a/apisix/init.lua b/apisix/init.lua
index 780757f..cc7902b 100644
--- a/apisix/init.lua
+++ b/apisix/init.lua
@@ -672,7 +672,7 @@ function _M.http_log_phase()
     healcheck_passive(api_ctx)
 
     if api_ctx.server_picker and api_ctx.server_picker.after_balance then
-        api_ctx.server_picker.after_balance(api_ctx)
+        api_ctx.server_picker.after_balance(api_ctx, false)
     end
 
     if api_ctx.uri_parse_param then