You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by "thor533 (via GitHub)" <gi...@apache.org> on 2023/04/03 08:18:25 UTC

[GitHub] [apisix] thor533 opened a new issue, #9225: The least conn algorithm cant work!!!

thor533 opened a new issue, #9225:
URL: https://github.com/apache/apisix/issues/9225

   ### Description
   
   I set three servers (12, 14, 15), whose TCP connections are 120, 150, and 201,(i use “netstat -ant | grep ^tcp | wc -l” to query) respectively. I used least conn algorithm, with the same weight is 1. When I access route, I don't hit 12 servers all the time, but randomly.
   
   the step is :
   1.create the route and Setting three upstream fractions is 12, 14, and 15 ,which have the same weigth is 1(least conn algorithm)
   2.I first query the connection number of three servers, respectively 120,150, 201,
   3.I start requesting this route,Normally, multiple requests should hit 12 servers all the time (the minimum number of connections is 120), but they don't. Instead, they're randomly selected all the time
   
   ps:
   What seems to be the problem? I only set up a route, I am working alone, is there a problem with the configuration? Or the connection number query is wrong,
   please help me
   thanks!!!
   
   
   
   ### Environment
   
   - APISIX version (run `apisix 2.15-alpine`):
   - Operating system (run `uname -a`):
   - OpenResty / Nginx version (run `openresty -V` or `nginx -V`):
   - etcd version, if relevant (run `curl http://127.0.0.1:9090/v1/server_info`):
   - APISIX Dashboard version, if relevant:
   - Plugin runner version, for issues related to plugin runners:
   - LuaRocks version, for installation issues (run `luarocks --version`):
   


-- 
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.apache.org

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


[GitHub] [apisix] Sn0rt commented on issue #9225: The least conn algorithm cant work!!!

Posted by "Sn0rt (via GitHub)" <gi...@apache.org>.
Sn0rt commented on issue #9225:
URL: https://github.com/apache/apisix/issues/9225#issuecomment-1510834670

   there are not same concept. A tcp connection is not equal to an nginx 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] thor533 commented on issue #9225: The least conn algorithm cant work!!!

Posted by "thor533 (via GitHub)" <gi...@apache.org>.
thor533 commented on issue #9225:
URL: https://github.com/apache/apisix/issues/9225#issuecomment-1511099546

   > there are not same concept. A tcp connection is not equal to an nginx connection
   
   In the online environment, centos7, how can we test this function? For serial requests, active-conn=0, using the polling algorithm, but for parallel requests using jmeter, we don't see the expected effect. How can the request fetch the active_conn data in apisix? 


-- 
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] thor533 commented on issue #9225: The least conn algorithm cant work!!!

Posted by "thor533 (via GitHub)" <gi...@apache.org>.
thor533 commented on issue #9225:
URL: https://github.com/apache/apisix/issues/9225#issuecomment-1495534049

   
   
   
   > can you share the reproduce env ?
   > 
   > I reproduce this issues by self need more time.
   
   it is very easy to reproduce the issue, you can see the route config:
   `{
       "uri": "/least/*",
       "name": "最小连接数",
       "priority": 1,
       "methods": [
           "GET",
           "POST",
           "PUT",
           "DELETE",
           "PATCH",
           "HEAD",
           "OPTIONS",
           "CONNECT",
           "TRACE"
       ],
       "plugins": {
           "proxy-rewrite": {
               "regex_uri": [
                   "^/least(/|$)(.*)",
                   "/$2"
               ]
           }
       },
       "upstream": {
           "nodes": [
               {
                   "host": "10.4.16.12",
                   "port": 9001,
                   "weight": 1
               },
               {
                   "host": "10.4.16.13",
                   "port": 9001,
                   "weight": 1
               },
               {
                   "host": "10.4.16.14",
                   "port": 9001,
                   "weight": 1
               }
           ],
           "retries": 1,
           "timeout": {
               "connect": 1,
               "send": 1,
               "read": 9
           },
           "type": "least_conn",
           "scheme": "http",
           "pass_host": "pass",
           "keepalive_pool": {
               "idle_timeout": 60,
               "requests": 1000,
               "size": 320
           },
           "retry_timeout": 1
       },
       "labels": {
           "1": "1"
       },
       "status": 1
   }`
   
   You only need to prepare three different upstream servers, route using the minimum number of connections algorithm to access, see if the hit server is the least connected upstream service! 
   thank you you reply!
   


-- 
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] thor533 commented on issue #9225: The least conn algorithm cant work!!!

Posted by "thor533 (via GitHub)" <gi...@apache.org>.
thor533 commented on issue #9225:
URL: https://github.com/apache/apisix/issues/9225#issuecomment-1499945238

   > > > can you share the reproduce env ?
   > > > I reproduce this issues by self need more time.
   > > 
   > > 
   > > My environment is LAN and you cannot access it
   > 
   > ok , I will try to reproduce it by self later. (not high priority
   Do you have any results
   
   
   


-- 
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] Sn0rt commented on issue #9225: The least conn algorithm cant work!!!

Posted by "Sn0rt (via GitHub)" <gi...@apache.org>.
Sn0rt commented on issue #9225:
URL: https://github.com/apache/apisix/issues/9225#issuecomment-1504425752

   The current implementation may suffer from imbalance at low quantity levels.
   Currently using the heap to maintain the connection is only balanced within a single worker.
   Can you try using a single nginx worker?


-- 
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] thor533 closed issue #9225: The least conn algorithm cant work!!!

Posted by "thor533 (via GitHub)" <gi...@apache.org>.
thor533 closed issue #9225: The least conn algorithm cant work!!!
URL: https://github.com/apache/apisix/issues/9225


-- 
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] thor533 commented on issue #9225: The least conn algorithm cant work!!!

Posted by "thor533 (via GitHub)" <gi...@apache.org>.
thor533 commented on issue #9225:
URL: https://github.com/apache/apisix/issues/9225#issuecomment-1506702619

   > 
   yep, i will try again ,thank you reply !


-- 
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] thor533 commented on issue #9225: The least conn algorithm cant work!!!

Posted by "thor533 (via GitHub)" <gi...@apache.org>.
thor533 commented on issue #9225:
URL: https://github.com/apache/apisix/issues/9225#issuecomment-1502573580

   > > > can you share the reproduce env ?
   > > > I reproduce this issues by self need more time.
   > > 
   > > 
   > > My environment is LAN and you cannot access it
   > 
   > ok , I will try to reproduce it by self later. (not high priority
   
   Is it the version problem?
   
   


-- 
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] Sn0rt commented on issue #9225: The least conn algorithm cant work!!!

Posted by "Sn0rt (via GitHub)" <gi...@apache.org>.
Sn0rt commented on issue #9225:
URL: https://github.com/apache/apisix/issues/9225#issuecomment-1502581844

   > > > > can you share the reproduce env ?
   > > > > I reproduce this issues by self need more time.
   > > > 
   > > > 
   > > > My environment is LAN and you cannot access it
   > > 
   > > 
   > > ok , I will try to reproduce it by self later. (not high priority
   > 
   > Is it the version problem?
   
   sorry. I not start to process this issue yet because it need more resource for reproduce. 
   
   I will to an other method for reproduce (by test
   
   >  Is it the version problem?
   
   not sure. 


-- 
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] thor533 commented on issue #9225: The least conn algorithm cant work!!!

Posted by "thor533 (via GitHub)" <gi...@apache.org>.
thor533 commented on issue #9225:
URL: https://github.com/apache/apisix/issues/9225#issuecomment-1510660668

   > > > The current implementation may suffer from imbalance at low quantity levels. Currently using the heap to maintain the connection is only balanced within a single worker. Can you try using a single Nginx worker?
   > > 
   > > 
   > > Is it normal for you to test?
   > 
   > I write a unit test and run it on a local machine. **it's working normally**.
   > 
   > the unit test is as follows. ( actually, I modify the original test, which files you find from `t/node/least_conn.t`)
   > 
   > ```lua
   > === TEST 2: select least conn
   > --- apisix_yaml
   > upstreams:
   >     -
   >     id: 1
   >     type: least_conn
   >     nodes:
   >         "127.0.0.1:1980": 1
   >         "127.0.0.2:1980": 1
   >         "127.0.0.3:1980": 1
   >         "127.0.0.4:1980": 1
   > --- config
   >     location /t {
   >         content_by_lua_block {
   >             local http = require "resty.http"
   >             local uri = "http://127.0.0.1:" .. ngx.var.server_port
   >                         .. "/mysleep?seconds=0.1"
   > 
   >             local t = {}
   >             for i = 1, 3000 do
   >                 local th = assert(ngx.thread.spawn(function(i)
   >                     local httpc = http.new()
   >                     local res, err = httpc:request_uri(uri..i, {method = "GET"})
   >                     if not res then
   >                         ngx.log(ngx.ERR, err)
   >                         return
   >                     end
   >                 end, i))
   >                 table.insert(t, th)
   >             end
   >             for i, th in ipairs(t) do
   >                 ngx.thread.wait(th)
   >             end
   >         }
   >     }
   > --- request
   > GET /t
   > --- grep_error_log eval
   > qr/proxy request to \S+ while connecting to upstream/
   > --- grep_error_log_out
   > proxy request to 127.0.0.1:1980 while connecting to upstream
   > proxy request to 0.0.0.0:1980 while connecting to upstream
   > proxy request to 127.0.0.1:1980 while connecting to upstream
   > ```
   > 
   > try to run it, and ignore the error output.
   > 
   > ```shell
   > $ prove -I. -I../test-nginx/inc -I../test-nginx/lib -r t/node/least_conn.t
   > ```
   > 
   > Use the log to count the back-end distribution
   > 
   > ```shell
   > $ cat t/servroot/logs/error.log  |grep 'while connecting to upstream' | grep -o 'run():.*client'|grep -o 'run(): proxy request to 127\.0\.0\.[1-3]'| sort | uniq -c
   >     773 run(): proxy request to 127.0.0.1
   >     770 run(): proxy request to 127.0.0.2
   >     843 run(): proxy request to 127.0.0.3
   > ```
   
   However, when I tested the least-conn algorithm in a centos environment, I got exactly the same results as the polling algorithm,
   1.First server-->10.xx.xx.12,
   the conn number is 92,
   ![image](https://user-images.githubusercontent.com/62246176/232374715-710dba54-ea2b-4f91-baa3-65acb3110ccf.png)
   
   2.Second server -->10.xx.xx.105
   the conn number is 3
   ![image](https://user-images.githubusercontent.com/62246176/232374668-73b30abc-f6b3-4085-b367-073025a51f1c.png)
   
   But the result is the same as the weighted polling algorithm
   
   Is there something wrong with me
   
   
   
   
   
   


-- 
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] thor533 commented on issue #9225: The least conn algorithm cant work!!!

Posted by "thor533 (via GitHub)" <gi...@apache.org>.
thor533 commented on issue #9225:
URL: https://github.com/apache/apisix/issues/9225#issuecomment-1495535398

   > can you share the reproduce env ?
   > 
   > I reproduce this issues by self need more time.
   
   My environment is LAN and you cannot access 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] thor533 commented on issue #9225: The least conn algorithm cant work!!!

Posted by "thor533 (via GitHub)" <gi...@apache.org>.
thor533 commented on issue #9225:
URL: https://github.com/apache/apisix/issues/9225#issuecomment-1506506470

   > The current implementation may suffer from imbalance at low quantity levels. Currently using the heap to maintain the connection is only balanced within a single worker. Can you try using a single nginx worker?
   
   Is it normal for you to test?


-- 
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] Sn0rt commented on issue #9225: The least conn algorithm cant work!!!

Posted by "Sn0rt (via GitHub)" <gi...@apache.org>.
Sn0rt commented on issue #9225:
URL: https://github.com/apache/apisix/issues/9225#issuecomment-1495566481

   > > can you share the reproduce env ?
   > > I reproduce this issues by self need more time.
   > 
   > My environment is LAN and you cannot access it
   
   ok , I will try to reproduce it by self later. (not high priority


-- 
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] Sn0rt commented on issue #9225: The least conn algorithm cant work!!!

Posted by "Sn0rt (via GitHub)" <gi...@apache.org>.
Sn0rt commented on issue #9225:
URL: https://github.com/apache/apisix/issues/9225#issuecomment-1494000318

   can you share the reproduce env ? 
   
   I reproduce this issues by self need more time.
   


-- 
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] Sn0rt commented on issue #9225: The least conn algorithm cant work!!!

Posted by "Sn0rt (via GitHub)" <gi...@apache.org>.
Sn0rt commented on issue #9225:
URL: https://github.com/apache/apisix/issues/9225#issuecomment-1506645873

   > > The current implementation may suffer from imbalance at low quantity levels. Currently using the heap to maintain the connection is only balanced within a single worker. Can you try using a single nginx worker?
   > 
   > Is it normal for you to test?
   
   I wrtie a unit test and run it in local machine . it work normal.
   
   the unit test as follow.
   
   ```lua
   === TEST 2: select least conn
   --- apisix_yaml
   upstreams:
       -
       id: 1
       type: least_conn
       nodes:
           "127.0.0.1:1980": 1
           "127.0.0.2:1980": 1
           "127.0.0.3:1980": 1
           "127.0.0.4:1980": 1
   --- config
       location /t {
           content_by_lua_block {
               local http = require "resty.http"
               local uri = "http://127.0.0.1:" .. ngx.var.server_port
                           .. "/mysleep?seconds=0.1"
   
               local t = {}
               for i = 1, 3000 do
                   local th = assert(ngx.thread.spawn(function(i)
                       local httpc = http.new()
                       local res, err = httpc:request_uri(uri..i, {method = "GET"})
                       if not res then
                           ngx.log(ngx.ERR, err)
                           return
                       end
                   end, i))
                   table.insert(t, th)
               end
               for i, th in ipairs(t) do
                   ngx.thread.wait(th)
               end
           }
       }
   --- request
   GET /t
   --- grep_error_log eval
   qr/proxy request to \S+ while connecting to upstream/
   --- grep_error_log_out
   proxy request to 127.0.0.1:1980 while connecting to upstream
   proxy request to 0.0.0.0:1980 while connecting to upstream
   proxy request to 127.0.0.1:1980 while connecting to upstream
   ```
   
   try to run it , and igonre the error output.
   
   ```bash
   $ prove -I. -I../test-nginx/inc -I../test-nginx/lib -r t/node/least_conn.t
   ```
   
   Use the log to count the back-end distribution
   
   ```bash
   $ cat t/servroot/logs/error.log  |grep 'while connecting to upstream' | grep -o 'run():.*client'|grep -o 'run(): proxy request to 127\.0\.0\.[1-3]'| sort | uniq -c
       773 run(): proxy request to 127.0.0.1
       770 run(): proxy request to 127.0.0.2
       843 run(): proxy request to 127.0.0.3
   ```


-- 
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] thor533 commented on issue #9225: The least conn algorithm cant work!!!

Posted by "thor533 (via GitHub)" <gi...@apache.org>.
thor533 commented on issue #9225:
URL: https://github.com/apache/apisix/issues/9225#issuecomment-1506505849

   > The current implementation may suffer from imbalance at low quantity levels. Currently using the heap to maintain the connection is only balanced within a single worker. Can you try using a single nginx worker?
   
   I just use a single nginx worker to test
   
   


-- 
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] thor533 closed issue #9225: The least conn algorithm cant work!!!

Posted by "thor533 (via GitHub)" <gi...@apache.org>.
thor533 closed issue #9225: The least conn algorithm cant work!!!
URL: https://github.com/apache/apisix/issues/9225


-- 
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