Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the scheduling algorithms of Nginx layer 7 load balancing

2025-03-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly shows you "what are the scheduling algorithms of Nginx layer-7 load balancer". It is easy to understand and well-organized. I hope it can help you solve your doubts. Let me lead you to study and learn the article "what are the scheduling algorithms of Nginx layer-7 load balancer".

Nginx is not only a lightweight high-performance web server, but also an excellent load balancer and reverse proxy server. Because it supports powerful regular matching rules, dynamic and static separation, URLrewrite function, simple installation and configuration, and little dependence on network stability, it is often used as layer 7 load balancing. In the case of the same hardware, it can usually stably support tens of thousands of concurrent connections, the hardware performance is good enough, and the optimization of system kernel parameters and Nginx configuration can even achieve more than 100000 concurrency.

The following are several scheduling algorithms and applicable business scenarios commonly used by Nginx as a seven-tier load balancer

1. Polling (default scheduling algorithm)

Features: each request is allocated to a different back-end server for processing one by one in chronological order.

Applicable to business scenarios: the hardware performance configuration of the back-end server is completely consistent, and it can be used when there are no special requirements for the business.

Upstream backendserver {server 192.168.0.14:80 max_fails=2 fail_timeout=10s; server 192.168.0.15:80 max_fails=2 fail_timeout=10s;}

2. Weighted polling

Features: specify the polling probability, the weight value (weight) is proportional to the access ratio, and the user requests are allocated according to the weight ratio.

Suitable for business scenarios: used in situations where the hardware processing capacity of back-end servers is uneven.

Upstream backendserver {server 192.168.0.14:80 weight=5 max_fails=2 fail_timeout=10s; server 192.168.0.15:80 weight=10 max_fails=2 fail_timeout=10s;}

3 、 ip_hash

Features: each request is allocated according to the hash result of accessing ip, so that each visitor accesses a back-end server regularly, which can solve the problem of session session persistence.

Suitable for business scenarios: it is suitable for systems that require account login and businesses where session connections are maintained.

Upstream backendserver {ip_hash; server 192.168.0.14:80 max_fails=2 fail_timeout=10s; server 192.168.0.15:80 max_fails=2 fail_timeout=10s;}

4. Minimum number of connections least_conn

Features: according to the number of connections between the nginx reverse proxy and the back-end server, priority allocation with the least number of connections.

Suitable for business scenarios: it is suitable for businesses where the client needs to maintain a long connection with the backend server.

Upstream backendserver {least_conn;server 192.168.0.14:80 max_fails=2 fail_timeout=10s; server 192.168.0.15:80 max_fails=2 fail_timeout=10s;}

5. Fair (third-party module ngx_http_upstream_fair_module needs to be compiled and installed)

Features: allocate requests according to the response time of the back-end server, and give priority to those with short response time.

Applicable business scenarios: businesses with certain requirements for access response speed.

Upstream backendserver {fair; server 192.168.0.14:80 max_fails=2 fail_timeout=10s; server 192.168.0.15:80 max_fails=2 fail_timeout=10s;}

6. Url_hash (third-party module ngx_http_upstream_hash_module needs to be compiled and installed)

Features: assign requests according to the hash results of accessing url, so that the same url accesses the same back-end server.

Suitable for business scenarios: it is more effective when the back-end server is a cache server.

Upstream backendserver {server 192.168.0.14 max_fails=2 fail_timeout=10s;server 192.168.0.15 max_fails=2 fail_timeout=10s; hash $request_uri;} above are all the contents of this article entitled "what are the scheduling algorithms for Nginx seven-layer load balancing". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report