-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
iwrr: a wrr with always O(1) time and O(n) memory
- Loading branch information
Showing
5 changed files
with
834 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
|
||
## Name | ||
|
||
ngx_http_upstream_iwrr_module. | ||
|
||
|
||
## Introduction | ||
|
||
The `IWRR` module is an efficient load balancing algorithm with `O(1)` time complexity, but `IWRR` is no need to incremental initialization. | ||
|
||
Compared with Nginx's official `SWRR` algorithm and `VNSWRR`, `IWRR` abandons smoothness on the premise of ensuring the correctness of the weighted load balancing algorithm, ensuring that no matter how the total weight of the cluster changes, `IWRR` space The complexity is always `O(n)`. | ||
|
||
## Example | ||
|
||
``` | ||
http { | ||
upstream backend { | ||
iwrr; # enable IWRR load balancing algorithm. | ||
127.0.0.1 port=81; | ||
127.0.0.1 port=82 weight=2; | ||
127.0.0.1 port=83; | ||
127.0.0.1 port=84 backup; | ||
127.0.0.1 port=85 down; | ||
} | ||
server { | ||
server_name localhost; | ||
location / { | ||
proxy_pass http://backend; | ||
} | ||
} | ||
} | ||
``` | ||
|
||
## Installation | ||
|
||
Build Tengine with this module from source: | ||
|
||
``` | ||
./configure --add-module=./modules/ngx_http_upstream_iwrr_module/ | ||
make | ||
make install | ||
``` | ||
|
||
|
||
## Directive | ||
|
||
iwrr | ||
======= | ||
``` | ||
Syntax: iwrr [max_init=number] | ||
Default: none | ||
Context: upstream | ||
``` | ||
|
||
Enable `iwrr` load balancing algorithm. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
|
||
## 名称 | ||
|
||
ngx_http_upstream_iwrr_module. | ||
|
||
|
||
## 介绍 | ||
|
||
`IWRR`模块是一个高效的负载均衡算法,与`VNSWRR`相同,它具有`O(1)`的时间复杂度,但是`IWRR`不需要执行渐进式初始化操作。 | ||
|
||
同Nginx官方的加权轮询负载均衡算法及`VNSWRR`相比,`IWRR`在保证加权负载均衡算法正确性的前提下,牺牲了平滑的特点,保证无论集群总权重如何变化,`IWRR`空间复杂度总是`O(n)`的。 | ||
|
||
## 配置列子 | ||
|
||
``` | ||
http { | ||
upstream backend { | ||
iwrr; # enable IWRR load balancing algorithm. | ||
127.0.0.1 port=81; | ||
127.0.0.1 port=82 weight=2; | ||
127.0.0.1 port=83; | ||
127.0.0.1 port=84 backup; | ||
127.0.0.1 port=85 down; | ||
} | ||
server { | ||
server_name localhost; | ||
location / { | ||
proxy_pass http://backend; | ||
} | ||
} | ||
} | ||
``` | ||
|
||
## 安装方法 | ||
|
||
在Tengine中,通过源码安装此模块: | ||
|
||
|
||
``` | ||
./configure --add-module=./modules/ngx_http_upstream_iwrr_module | ||
make | ||
make install | ||
``` | ||
|
||
|
||
## 指令描述 | ||
|
||
iwrr | ||
======= | ||
``` | ||
Syntax: iwrr | ||
Default: none | ||
Context: upstream | ||
``` | ||
|
||
在upstream里面启用 `iwrr` 加权轮询算法。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
ngx_addon_name=ngx_http_upstream_iwrr_module | ||
HTTP_UPSTREAM_IWRR_SRCS="$ngx_addon_dir/ngx_http_upstream_iwrr_module.c" | ||
|
||
if test -n "$ngx_module_link"; then | ||
ngx_module_type=HTTP | ||
ngx_module_name=$ngx_addon_name | ||
ngx_module_deps= | ||
ngx_module_srcs="$HTTP_UPSTREAM_IWRR_SRCS" | ||
|
||
. auto/module | ||
else | ||
HTTP_MODULES="$HTTP_MODULES ngx_http_upstream_iwrr_module" | ||
NGX_ADDON_SRCS="$NGX_ADDON_SRCS $HTTP_UPSTREAM_IWRR_SRCS" | ||
fi |
Oops, something went wrong.