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

[GitHub] [apisix] Revolyssup opened a new issue, #9305: bug: consistent hashing not working

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

   ### Current Behavior
   
   Following the docs here for cookie based consistent hashing, two nodes are provided in upstream. Even after passing the same cookie consistently as given in the doc, the requests are being load balanced in a round robin fashion.
   Here is the output of `/apisix/admin/routes`
   ---
   {"list":[{"key":"/apisix/routes/1","createdIndex":16,"value":{"id":"1","update_time":1681400381,"create_time":1681377310,"uri":"/","priority":0,"status":1,"upstream":{"type":"chash","pass_host":"pass","hash_on":"cookie","nodes":{"revoly.dev":1,"google.com":1},"scheme":"http","key":"sid"}},"modifiedIndex":46}],"total":1}
   ---
   For the above configuration, here is the request being routed to node2(google.com) for a given cookie with key sid
   <img width="977" alt="Screenshot 2023-04-13 at 9 13 52 PM" src="https://user-images.githubusercontent.com/43276904/231813624-a89086ad-9eff-4c31-88b7-e52435b595dc.png">
   
   For the same exact sid cookie, the very next request goes to another node
   <img width="936" alt="Screenshot 2023-04-13 at 9 14 53 PM" src="https://user-images.githubusercontent.com/43276904/231813780-4e747b7d-96b3-403b-abc1-a2a1092fc2a6.png">
   
   
   
   
   ### Expected Behavior
   
   Requests with a given "sid" (`key`) in the Cookie should be consistently routed to the same node in upstream.
   
   ### Error Logs
   
   _No response_
   
   ### Steps to Reproduce
   
   1. Run APISIX using helm chart and port forward on the APISIX pod.
   2. Add the following configuration on route
   ---
   curl http://127.0.0.1:9180/apisix/admin/routes/1 \                                                                     ─╯
   -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
   {
       "uri": "/",
       "upstream": {
           "key": "sid",
           "type": "chash",
           "hash_on": "cookie",
           "nodes": {
               "google.com": 1,
               "revoly.dev": 1
           }
       }
   }'
   ---
   
   Send multiple requests on the below endpoint to see it being round robin'ed across nodes instead of being consistently routed.
   ---
   curl http://127.0.0.1:9080 \
    -H "Cookie: sid=3c183a30cffcda1408daf1c61d47b274"
   ---
   
   
   ### Environment
   
   - APISIX version 3.2.0:
   - Operating system x86_64 GNU/Linux:
   - OpenResty / Nginx version openresty/1.21.4.1
   
   


-- 
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] Revolyssup closed issue #9305: bug: consistent hashing not working

Posted by "Revolyssup (via GitHub)" <gi...@apache.org>.
Revolyssup closed issue #9305: bug: consistent hashing not working
URL: https://github.com/apache/apisix/issues/9305


-- 
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] nic-6443 commented on issue #9305: bug: consistent hashing not working

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

   >  I may be naive but shouldn't the schema validation fail in case a user specified type as chash and the nodes contain DNS records? 
   
   Yes, manually specifying nodes and using service discovery cannot be used at the same time.
   
   > Also I get your suggestion of putting different DNS names under different upstreams and split traffic using the plugin but in that case I'd not be able to make use of an individual upstream's chash load balancing feature.
   
   The premise of using traffic-split is that you need to know in advance the specific rules for implementing traffic splitting, such as forwarding cookie sid starting with a number to google.com and others to revoly.dev. 
   But when it comes to a specific domain name, because there is no way to use the DNS service discovery plugin in traffic-split, it is impossible to achieve consistency hashing.
   


-- 
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] nic-6443 commented on issue #9305: bug: consistent hashing not working

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

   Your testing method is problematic. You should not use public domain names such as `google.com` and `revoly.dev` as upstream nodes. 
   The DNS resolution results and the order of IP addresses in the results may change, which can cause instability in the output of consistent hashing algorithms. 
   Instead, you can replace `google.com` and `revoly.dev` with their respective IP addresses for testing.


-- 
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] Revolyssup commented on issue #9305: bug: consistent hashing not working

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

   @nic-6443 Hmm, in the traffic split plugin also it splits among weighted upstreams and not nodes inside of an upstream. Although it was clear after your comment what the issue was with trying to consistently hash on DNS, it was not clear at first just by looking at the API. I may be naive but shouldn't the schema validation fail in case a user specified `type` as `chash` and the nodes contain DNS records? Because user won't get the expected behaviour. Or maybe it is obvious and I am naive in this case. Any which ways, it would be nice to know your opinion. 


-- 
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] Revolyssup commented on issue #9305: bug: consistent hashing not working

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

   > Your testing method is problematic. You should not use public domain names such as `google.com` and `revoly.dev` as upstream nodes. The DNS resolution results and the order of IP addresses in the results may change, which can cause instability in the output of consistent hashing algorithms. Instead, you can replace `google.com` and `revoly.dev` with their respective IP addresses for testing.
   
   This was helpful. Thank you very much


-- 
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] nic-6443 commented on issue #9305: bug: consistent hashing not working

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

   You can try the DNS service discovery feature:https://apisix.apache.org/docs/apisix/discovery/dns/ 
   In this feature, APISIX will query all DNS entries as upstream nodes instead of selecting one.
   
   However, it is important to note that only one service discovery can be configured in the same upstream. Therefore, it is not possible to configure two different domain names at the same time, which may not be what you want.
   
   So I also recommend that you take a look at the [traffic-split](https://apisix.apache.org/docs/apisix/plugins/traffic-split/) plugin, which can achieve more precise traffic splitting.


-- 
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] Revolyssup commented on issue #9305: bug: consistent hashing not working

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

   @nic-6443  Can you please confirm if there is a way to do DNS based load balancing 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