You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by GitBox <gi...@apache.org> on 2022/10/20 04:52:40 UTC

[GitHub] [apisix] tzssangglass opened a new pull request, #8130: adjust ai plugin priority

tzssangglass opened a new pull request, #8130:
URL: https://github.com/apache/apisix/pull/8130

   ### Description
   
   <!-- Please include a summary of the change and which issue is fixed. -->
   <!-- Please also include relevant motivation and context. -->
   
   Fixes # (issue)
   
   ### Checklist
   
   - [x] I have explained the need for this PR and the problem it solves
   - [x] I have explained the changes or the new features added to this PR
   - [x] I have added tests corresponding to this change
   - [ ] I have updated the documentation to reflect this change
   - [x] I have verified that this change is backward compatible (If not, please discuss on the [APISIX mailing list](https://github.com/apache/apisix/tree/master#community) first)
   
   <!--
   
   Note
   
   1. Mark the PR as draft until it's ready to be reviewed.
   2. Always add/update tests for any changes unless you have a good reason.
   3. Always update the documentation to reflect the changes made in the PR.
   4. Make a new commit to resolve conversations instead of `push -f`.
   5. To resolve merge conflicts, merge master instead of rebasing.
   6. Use "request review" to notify the reviewer after making changes.
   7. Only a reviewer can mark a conversation as resolved.
   
   -->
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [apisix] tzssangglass commented on a diff in pull request #8130: perf: simple setup upstream

Posted by GitBox <gi...@apache.org>.
tzssangglass commented on code in PR #8130:
URL: https://github.com/apache/apisix/pull/8130#discussion_r1000837369


##########
t/debug/dynamic-hook.t:
##########
@@ -405,7 +405,8 @@ hook_test:                      # module and function list, name: hook_test
                     "uri": "/hello",
                     "upstream": {
                         "nodes": {
-                            "127.0.0.1:1980": 1
+                            "127.0.0.1:1980": 1,

Review Comment:
   done



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [apisix] membphis commented on a diff in pull request #8130: perf: simple setup upstream

Posted by GitBox <gi...@apache.org>.
membphis commented on code in PR #8130:
URL: https://github.com/apache/apisix/pull/8130#discussion_r1001516411


##########
apisix/plugins/ai.lua:
##########
@@ -100,33 +108,120 @@ local function gen_get_cache_key_func(route_flags)
 end
 
 
+local function ai_upstream()
+    core.log.info("enable sample upstream")
+end
+
+
+local pool_opt = { pool_size = 320 }
+local function ai_balancer_run(route)
+    local server = route.value.upstream.nodes[1]
+    if enable_keepalive then
+        local ok, err = balancer.set_current_peer(server.host, server.port or 80, pool_opt)
+        if not ok then
+            core.log.error("failed to set server peer [", server.host, ":",
+                           server.port, "] err: ", err)
+            return ok, err
+        end
+        balancer.enable_keepalive(60, 1000)

Review Comment:
   We should enable `keepalive` by default



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [apisix] spacewander merged pull request #8130: perf: simple setup upstream

Posted by GitBox <gi...@apache.org>.
spacewander merged PR #8130:
URL: https://github.com/apache/apisix/pull/8130


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [apisix] membphis commented on a diff in pull request #8130: perf: simple setup upstream

Posted by GitBox <gi...@apache.org>.
membphis commented on code in PR #8130:
URL: https://github.com/apache/apisix/pull/8130#discussion_r1000589930


##########
t/debug/dynamic-hook.t:
##########
@@ -405,7 +405,8 @@ hook_test:                      # module and function list, name: hook_test
                     "uri": "/hello",
                     "upstream": {
                         "nodes": {
-                            "127.0.0.1:1980": 1
+                            "127.0.0.1:1980": 1,

Review Comment:
   why do we need to change this?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [apisix] tzssangglass commented on a diff in pull request #8130: perf: simple setup upstream

Posted by GitBox <gi...@apache.org>.
tzssangglass commented on code in PR #8130:
URL: https://github.com/apache/apisix/pull/8130#discussion_r1001537715


##########
apisix/plugins/ai.lua:
##########
@@ -138,6 +233,27 @@ local function routes_analyze(routes)
             router.router_http.match = orig_router_match
         end
     end
+
+    if not route_flags["service"]
+            and not route_flags["service_id"]
+            and not route_flags["upstream_id"]
+            and not route_flags["enable_websocket"]
+            and not route_flags["plugins"]
+            and not route_up_flags["has_domain"]
+            and route_up_flags["pass_host"]
+            and route_up_flags["scheme"]
+            and not route_up_flags["checks"]
+            and not route_up_flags["retries"]
+            and not route_up_flags["timeout"]
+            and not route_up_flags["timeout"]

Review Comment:
   fixed



##########
apisix/plugins/ai.lua:
##########
@@ -138,6 +233,27 @@ local function routes_analyze(routes)
             router.router_http.match = orig_router_match
         end
     end
+
+    if not route_flags["service"]
+            and not route_flags["service_id"]
+            and not route_flags["upstream_id"]
+            and not route_flags["enable_websocket"]
+            and not route_flags["plugins"]
+            and not route_up_flags["has_domain"]
+            and route_up_flags["pass_host"]
+            and route_up_flags["scheme"]
+            and not route_up_flags["checks"]
+            and not route_up_flags["retries"]
+            and not route_up_flags["timeout"]
+            and not route_up_flags["timeout"]
+            and not route_up_flags["keepalive"] then

Review Comment:
   updated



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [apisix] spacewander commented on a diff in pull request #8130: perf: simple setup upstream

Posted by GitBox <gi...@apache.org>.
spacewander commented on code in PR #8130:
URL: https://github.com/apache/apisix/pull/8130#discussion_r1001420302


##########
apisix/plugins/ai.lua:
##########
@@ -100,33 +108,120 @@ local function gen_get_cache_key_func(route_flags)
 end
 
 
+local function ai_upstream()
+    core.log.info("enable sample upstream")
+end
+
+
+local pool_opt = { pool_size = 320 }
+local function ai_balancer_run(route)
+    local server = route.value.upstream.nodes[1]
+    if enable_keepalive then
+        local ok, err = balancer.set_current_peer(server.host, server.port or 80, pool_opt)
+        if not ok then
+            core.log.error("failed to set server peer [", server.host, ":",
+                           server.port, "] err: ", err)
+            return ok, err
+        end
+        balancer.enable_keepalive(60, 1000)

Review Comment:
   Why don't we use the keepalive configured in the yaml?



##########
apisix/plugins/ai.lua:
##########
@@ -138,6 +233,27 @@ local function routes_analyze(routes)
             router.router_http.match = orig_router_match
         end
     end
+
+    if not route_flags["service"]
+            and not route_flags["service_id"]
+            and not route_flags["upstream_id"]
+            and not route_flags["enable_websocket"]
+            and not route_flags["plugins"]
+            and not route_up_flags["has_domain"]
+            and route_up_flags["pass_host"]
+            and route_up_flags["scheme"]
+            and not route_up_flags["checks"]
+            and not route_up_flags["retries"]
+            and not route_up_flags["timeout"]
+            and not route_up_flags["timeout"]
+            and not route_up_flags["keepalive"] then

Review Comment:
   Is it possible to use allow list instead of a pile of deny list?



##########
apisix/plugins/ai.lua:
##########
@@ -100,33 +108,120 @@ local function gen_get_cache_key_func(route_flags)
 end
 
 
+local function ai_upstream()
+    core.log.info("enable sample upstream")
+end
+
+
+local pool_opt = { pool_size = 320 }
+local function ai_balancer_run(route)
+    local server = route.value.upstream.nodes[1]
+    if enable_keepalive then
+        local ok, err = balancer.set_current_peer(server.host, server.port or 80, pool_opt)
+        if not ok then
+            core.log.error("failed to set server peer [", server.host, ":",
+                           server.port, "] err: ", err)
+            return ok, err
+        end
+        balancer.enable_keepalive(60, 1000)
+    else
+        balancer.set_current_peer(server.host, server.port or 80)
+    end

Review Comment:
   We can move:
   ```
   if enable_keepalive then
   ```
   to here?
   Like:
   ```
   if enable_keepalive then
       balancer.enable_keepalive(60, 1000)
   ```



##########
apisix/plugins/ai.lua:
##########
@@ -138,6 +233,27 @@ local function routes_analyze(routes)
             router.router_http.match = orig_router_match
         end
     end
+
+    if not route_flags["service"]
+            and not route_flags["service_id"]
+            and not route_flags["upstream_id"]
+            and not route_flags["enable_websocket"]
+            and not route_flags["plugins"]
+            and not route_up_flags["has_domain"]
+            and route_up_flags["pass_host"]
+            and route_up_flags["scheme"]
+            and not route_up_flags["checks"]
+            and not route_up_flags["retries"]
+            and not route_up_flags["timeout"]
+            and not route_up_flags["timeout"]

Review Comment:
   Repeated condition?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [apisix] tzssangglass commented on a diff in pull request #8130: perf: simple setup upstream

Posted by GitBox <gi...@apache.org>.
tzssangglass commented on code in PR #8130:
URL: https://github.com/apache/apisix/pull/8130#discussion_r1001537517


##########
apisix/plugins/ai.lua:
##########
@@ -100,33 +108,120 @@ local function gen_get_cache_key_func(route_flags)
 end
 
 
+local function ai_upstream()
+    core.log.info("enable sample upstream")
+end
+
+
+local pool_opt = { pool_size = 320 }
+local function ai_balancer_run(route)
+    local server = route.value.upstream.nodes[1]
+    if enable_keepalive then
+        local ok, err = balancer.set_current_peer(server.host, server.port or 80, pool_opt)
+        if not ok then
+            core.log.error("failed to set server peer [", server.host, ":",
+                           server.port, "] err: ", err)
+            return ok, err
+        end
+        balancer.enable_keepalive(60, 1000)
+    else
+        balancer.set_current_peer(server.host, server.port or 80)
+    end
+end
+
 local function routes_analyze(routes)
     -- TODO: need to add a option in config.yaml to enable this feature(default is true)

Review Comment:
   done



##########
apisix/plugins/ai.lua:
##########
@@ -100,33 +108,120 @@ local function gen_get_cache_key_func(route_flags)
 end
 
 
+local function ai_upstream()
+    core.log.info("enable sample upstream")
+end
+
+
+local pool_opt = { pool_size = 320 }
+local function ai_balancer_run(route)
+    local server = route.value.upstream.nodes[1]
+    if enable_keepalive then
+        local ok, err = balancer.set_current_peer(server.host, server.port or 80, pool_opt)
+        if not ok then
+            core.log.error("failed to set server peer [", server.host, ":",
+                           server.port, "] err: ", err)
+            return ok, err
+        end
+        balancer.enable_keepalive(60, 1000)

Review Comment:
   done



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [apisix] tzssangglass commented on a diff in pull request #8130: perf: simple setup upstream

Posted by GitBox <gi...@apache.org>.
tzssangglass commented on code in PR #8130:
URL: https://github.com/apache/apisix/pull/8130#discussion_r1001407694


##########
apisix/plugins/ai.lua:
##########
@@ -100,33 +108,120 @@ local function gen_get_cache_key_func(route_flags)
 end
 
 
+local function ai_upstream()
+    core.log.info("enable sample upstream")
+end
+
+
+local pool_opt = { pool_size = 320 }
+local function ai_balancer_run(route)
+    local server = route.value.upstream.nodes[1]
+    if enable_keepalive then
+        local ok, err = balancer.set_current_peer(server.host, server.port or 80, pool_opt)
+        if not ok then
+            core.log.error("failed to set server peer [", server.host, ":",
+                           server.port, "] err: ", err)
+            return ok, err
+        end
+        balancer.enable_keepalive(60, 1000)
+    else
+        balancer.set_current_peer(server.host, server.port or 80)
+    end
+end
+
 local function routes_analyze(routes)
     -- TODO: need to add a option in config.yaml to enable this feature(default is true)

Review Comment:
   next PR fix it.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [apisix] tzssangglass commented on a diff in pull request #8130: perf: simple setup upstream

Posted by GitBox <gi...@apache.org>.
tzssangglass commented on code in PR #8130:
URL: https://github.com/apache/apisix/pull/8130#discussion_r1001537994


##########
apisix/plugins/ai.lua:
##########
@@ -100,33 +108,120 @@ local function gen_get_cache_key_func(route_flags)
 end
 
 
+local function ai_upstream()
+    core.log.info("enable sample upstream")
+end
+
+
+local pool_opt = { pool_size = 320 }
+local function ai_balancer_run(route)
+    local server = route.value.upstream.nodes[1]
+    if enable_keepalive then
+        local ok, err = balancer.set_current_peer(server.host, server.port or 80, pool_opt)
+        if not ok then
+            core.log.error("failed to set server peer [", server.host, ":",
+                           server.port, "] err: ", err)
+            return ok, err
+        end
+        balancer.enable_keepalive(60, 1000)
+    else
+        balancer.set_current_peer(server.host, server.port or 80)
+    end
+end
+
 local function routes_analyze(routes)
     -- TODO: need to add a option in config.yaml to enable this feature(default is true)
-    local route_flags = core.table.new(0, 2)
+    local route_flags = core.table.new(0, 5)
+    local route_up_flags = core.table.new(0, 8)
     for _, route in ipairs(routes) do
-        if route.methods then
-            route_flags["methods"] = true
-        end
+        if type(route) == "table" then

Review Comment:
   changed



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [apisix] tzssangglass commented on a diff in pull request #8130: perf: simple setup upstream

Posted by GitBox <gi...@apache.org>.
tzssangglass commented on code in PR #8130:
URL: https://github.com/apache/apisix/pull/8130#discussion_r1001547522


##########
apisix/plugins/ai.lua:
##########
@@ -100,33 +108,120 @@ local function gen_get_cache_key_func(route_flags)
 end
 
 
+local function ai_upstream()
+    core.log.info("enable sample upstream")
+end
+
+
+local pool_opt = { pool_size = 320 }
+local function ai_balancer_run(route)
+    local server = route.value.upstream.nodes[1]
+    if enable_keepalive then
+        local ok, err = balancer.set_current_peer(server.host, server.port or 80, pool_opt)
+        if not ok then
+            core.log.error("failed to set server peer [", server.host, ":",
+                           server.port, "] err: ", err)
+            return ok, err
+        end
+        balancer.enable_keepalive(60, 1000)
+    else
+        balancer.set_current_peer(server.host, server.port or 80)
+    end

Review Comment:
   maybe not, follow: https://github.com/apache/apisix/blob/ecdc209523f011b5fb4a0fee3a8e867da9c53fb5/apisix/balancer.lua#L291-L338
   
   if `enable_keepalive`, would add `pool_opt` as the third argument to `balancer.set_current_peer`.
   
   Do we fix the call to `set_current_peer` here and in `balancer.lua`, pass `pool_opt` even if there is disable `enable_keepalive`, otherwise it will all become non-persistent connection.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [apisix] membphis commented on a diff in pull request #8130: perf: simple setup upstream

Posted by GitBox <gi...@apache.org>.
membphis commented on code in PR #8130:
URL: https://github.com/apache/apisix/pull/8130#discussion_r1001391139


##########
apisix/plugins/ai.lua:
##########
@@ -100,33 +108,120 @@ local function gen_get_cache_key_func(route_flags)
 end
 
 
+local function ai_upstream()
+    core.log.info("enable sample upstream")
+end
+
+
+local pool_opt = { pool_size = 320 }
+local function ai_balancer_run(route)
+    local server = route.value.upstream.nodes[1]
+    if enable_keepalive then
+        local ok, err = balancer.set_current_peer(server.host, server.port or 80, pool_opt)
+        if not ok then
+            core.log.error("failed to set server peer [", server.host, ":",
+                           server.port, "] err: ", err)
+            return ok, err
+        end
+        balancer.enable_keepalive(60, 1000)
+    else
+        balancer.set_current_peer(server.host, server.port or 80)
+    end
+end
+
 local function routes_analyze(routes)
     -- TODO: need to add a option in config.yaml to enable this feature(default is true)

Review Comment:
   I think we can remove this line now



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [apisix] membphis commented on a diff in pull request #8130: perf: simple setup upstream

Posted by GitBox <gi...@apache.org>.
membphis commented on code in PR #8130:
URL: https://github.com/apache/apisix/pull/8130#discussion_r1001431875


##########
apisix/plugins/ai.lua:
##########
@@ -100,33 +108,120 @@ local function gen_get_cache_key_func(route_flags)
 end
 
 
+local function ai_upstream()
+    core.log.info("enable sample upstream")
+end
+
+
+local pool_opt = { pool_size = 320 }
+local function ai_balancer_run(route)
+    local server = route.value.upstream.nodes[1]
+    if enable_keepalive then
+        local ok, err = balancer.set_current_peer(server.host, server.port or 80, pool_opt)
+        if not ok then
+            core.log.error("failed to set server peer [", server.host, ":",
+                           server.port, "] err: ", err)
+            return ok, err
+        end
+        balancer.enable_keepalive(60, 1000)
+    else
+        balancer.set_current_peer(server.host, server.port or 80)
+    end
+end
+
 local function routes_analyze(routes)
     -- TODO: need to add a option in config.yaml to enable this feature(default is true)
-    local route_flags = core.table.new(0, 2)
+    local route_flags = core.table.new(0, 5)
+    local route_up_flags = core.table.new(0, 8)
     for _, route in ipairs(routes) do
-        if route.methods then
-            route_flags["methods"] = true
-        end
+        if type(route) == "table" then

Review Comment:
   we can change it to a better style, which is simpler:
   
   ```lua
   local route_flags = {}
   
   for _, route in ipairs(routes) do
       for key, value in pairs(route.value) do
           -- collect route flags
           if key == "host" or key = "hosts" then
               route_flags["host"] = true
           elseif key == "remote_addr" or key = "remote_addrs" then
               route_flags["remote_addr"] = true
           else
               route_flags[key] = true
           end
   
           -- ... ...
       end
   
   end
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org