Analysis of Nginx load Balancing module

Source: Internet
Author: User
Keywords Nginx load Balancing module
Tags aliyun analysis code configuration example function functions html

The load-balancing module determines which backend servers can be divided into specific requests, and the existing implementations are hashed through the rotation method or some portions of the request. This section will introduce the registration and invocation of the http://www.aliyun.com/zixun/aggregation/13996.html "> load Balancing module, and take the Upstream_hash module as an example (source code). The Upstream_hash module hashes a variable that is determined in the nginx.conf.

A load balancing module has the following six aspects:

1. Activation configuration Directive needs to call a registration function registration functions (such as: hash)

2. The registration function defines the legitimate server option (for example: weight=) while registering the upstream host initialization function upstream initialization functions

3. The upstream host initialization function is invoked after the configuration is confirmed:

A to resolve the server name and point to a specific IP address
b allocate space for each socket
(c) Set the peer initialization function peer the callback entry for initialization functions

4. The companion initialization function is invoked once for each request, setting a data structure in which the load-balancing function can enter and operate.

5. Load-balancing functions load-balancing function determines the whereabouts of this request, and is invoked at least once when a client request comes (if the backend server fails to reply, it may take more times). What happened here is very interesting.

6. Finally, in the end of communication with a particular back-end server, the peer-release function peer releasing functions updates the statistics (whether communication succeeds or fails).
There are a lot of content that I will have to unfold a little bit.

5.1. Activation instructions

Directive declarations, which determine both where they are valid and which function to invoke. For the load-balanced module, the identification ngx_http_ups_conf should be available so that nginx know that the instruction is valid only in the upstream configuration section. It should provide a pointer to the registration function. The following is an instruction declaration for the Upstream_hash module:

{ngx_string ("hash"),
Ngx_http_ups_conf| Ngx_conf_noargs,
Ngx_http_upstream_hash,
0,
0,
NULL},

Nothing else.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.