This article mainly introduces several scheduling algorithms for Nginx seven-layer load balancing. The example code in this article is very detailed and has a certain reference value for everyone's study or work. Friends in need can refer to it. Nginx is a lightweight, high-performance web server, as well as an excellent load balancer and reverse proxy server. It is often used as a seven-layer load balancing because of its support for powerful regular matching rules, dynamic and static separation, URL rewrite function, simple installation and configuration, and very little dependence on network stability. If the hardware is not bad, it can usually stably support tens of thousands of concurrent connections. If the hardware performance is good enough and the system kernel parameters and Nginx configuration are optimized, it can even reach more than 100,000 concurrent connections. The following are several commonly used scheduling algorithms and applicable business scenarios for Nginx as a seven-layer load balancing 1. Polling (default scheduling algorithm) Features: Each request is assigned to a different backend server for processing in chronological order. 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 Round Robin Features: Specify the polling probability, the weight value is proportional to the access ratio, and user requests are allocated according to the weight ratio. 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 assigned according to the hash result of the access IP, so that each visitor accesses a fixed backend server, which can solve the problem of session retention. 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 backend server, the one with the least number of connections will be allocated first. Applicable business scenarios: Applicable to businesses that need to maintain a long connection between the client and 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 (need to compile and install the third-party module ngx_http_upstream_fair_module) Features: Requests are distributed according to the response time of the backend server, with priority given to requests with shorter response time. 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 (need to compile and install the third-party module ngx_http_upstream_hash_module) Features: Allocate requests based on the hash result of the access URL, so that the same URL accesses the same backend server. Applicable business scenarios: This method is more effective when the backend server is a cache server. 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; hash $request_uri; } The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM. You may also be interested in:
|
<<: Implementing a simple calculator based on JavaScript
>>: How to optimize MySQL performance through MySQL slow query
The uniapp applet will have a similar drop-down p...
Preface One of the functions of an interceptor is...
ins and del were introduced in HTML 4.0 to help au...
1. CSS3 animation ☺CSS3 animations are much easie...
When encapsulating the date picker, you need to d...
Table of contents Problem description: Installati...
Background Replication is a complete copy of data...
Because the company asked me to build a WebServic...
Timer Effects: <div> <font id='timeC...
<br />Navigation does not just refer to the ...
Installation Environment Description •System vers...
Table of contents Vue2 Writing Vue3 plugin versio...
Table of contents Drag and drop implementation Dr...
Location means "positioning", which is ...
If you have installed the Win10 system and want t...