Skip to content

Commit

Permalink
iwrr: a wrr with always O(1) time and O(n) memory
Browse files Browse the repository at this point in the history
  • Loading branch information
jizhuozhi committed Jan 25, 2023
1 parent 37d4dcf commit d96d598
Show file tree
Hide file tree
Showing 5 changed files with 834 additions and 0 deletions.
61 changes: 61 additions & 0 deletions docs/modules/ngx_http_upstream_iwrr_module.md
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.
62 changes: 62 additions & 0 deletions docs/modules/ngx_http_upstream_iwrr_module_cn.md
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` 加权轮询算法。
14 changes: 14 additions & 0 deletions modules/ngx_http_upstream_iwrr_module/config
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
Loading

0 comments on commit d96d598

Please sign in to comment.