Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

help request: 负载策略采用chash时,如果没有key,默认是根据remote_addr hash,可是客户端ip比较固定,能不能如果没key,就round-robin轮询。 #11895

Open
hnzhuzi opened this issue Jan 7, 2025 · 6 comments
Labels
question label for questions asked by users

Comments

@hnzhuzi
Copy link

hnzhuzi commented Jan 7, 2025

Description

负载策略采用chash时,如果没有key,默认是根据remote_addr hash,可是客户端ip比较固定,能不能如果没key,就round-robin轮询。

Environment

  • APISIX version (run apisix version): 3.8
@github-project-automation github-project-automation bot moved this to 📋 Backlog in Apache APISIX backlog Jan 7, 2025
@dosubot dosubot bot added the question label for questions asked by users label Jan 7, 2025
@hnzhuzi
Copy link
Author

hnzhuzi commented Jan 7, 2025

When the load strategy uses chash, if there is no key, the default is based on remote_addr hash, but the client IP is relatively fixed(all traffic will visit a single node). If there is no key, can round-robin polling be performed?

@wklken
Copy link

wklken commented Jan 8, 2025

It's reasonable to use a default key to chash then choose the upstream (It would be much more complex if use a fallback strategy)

I think you should check what key can be performed like RR, or just use RR directly.

@hnzhuzi
Copy link
Author

hnzhuzi commented Jan 9, 2025

It's reasonable to use a default key to chash then choose the upstream (It would be much more complex if use a fallback strategy)

I think you should check what key can be performed like RR, or just use RR directly.

Currently, this requirement is achieved by modifying the code. If the request does not have a key, the time hash is used by default:
if not chash_key then
chash_key = tostring(ngx.time())
end
I would like to know if there is a way without changing the code, such as through a plug-in.

@wklken
Copy link

wklken commented Jan 9, 2025

you can test the vars of nginx here https://nginx.org/en/docs/varindex.html.

time_local as the key?

@hnzhuzi
Copy link
Author

hnzhuzi commented Jan 10, 2025

you can test the vars of nginx here https://nginx.org/en/docs/varindex.html.

time_local as the key?

Can this be done without modifying the code, but still meet my needs? If the request header has a key, use the key hash. If there is no key, the default is based on the time key (the effect is similar to round-robin).

@wklken
Copy link

wklken commented Jan 10, 2025

I don't think so.

you can clone the project, modify the code and generate a patch file, and patch it after installed (or during build image).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question label for questions asked by users
Projects
Status: 📋 Backlog
Development

No branches or pull requests

2 participants