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

nginx proxy does not distribute client connections to all synapse workers #1022

Closed
JohannesKleine opened this issue Apr 23, 2021 · 2 comments

Comments

@JohannesKleine
Copy link
Contributor

The ip_hash does not work as intended, only one synapse worker gets the requests. I assume it is through the cascading nginx proxy of client calls to synapse. In element the client ip was the one from the nginx proxy. Removiing this line:

results in correct distribution to all synapse workers. Without ip_hash nginx falls back to round_robin. This could lead to more resource usage from ram and cpu, since one client might be handled by more than one worker. If one user uses more than one client simultaneously the differences between ip_hasch and round_robin gravitate to have less impact.

Work around: remove this line.

Possible fix: add some headers to roles/matrix-nginx-proxy/templates/nginx/conf.d/matrix-synapse.conf.j2 and roles/matrix-nginx-proxy/templates/nginx/conf.d/matrix-domain.conf.j2 so that the last nginx gets the original client ip for ip_hash. Help needed from an experienced nginx config writer.

Possible fix: integrate the content off roles/matrix-nginx-proxy/templates/nginx/conf.d/matrix-synapse.conf.j2 into roles/matrix-nginx-proxy/templates/nginx/conf.d/matrix-domain.conf.j2 so that instead of using the

set $backend "{{ matrix_nginx_proxy_proxy_matrix_federation_api_addr_with_container }}";
backend use instead. Preferred method.

@spantaleev
Copy link
Owner

Good catch! This is indeed a problem.

A similar problem is being discussed here: https://serverfault.com/questions/660323/nginx-ip-hash-behind-proxy-cloudflare

I've tried one of the solutions, which I believe should work for us. I haven't tested it though. If you have multiple generic workers and can test it out, that'd be great!

@JohannesKleine
Copy link
Contributor Author

Thank you, it looks like it is working, the cpu load is not equal on each worker, but i guess it depends on some power users. I will monitor it a while.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants