Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add vnswrr algorithm for upstream module. #1306

Merged
merged 1 commit into from
Jul 30, 2019
Merged

Conversation

wangfakang
Copy link
Collaborator

Test Result

$TEST_NGINX_BINARY=/home/fakang.wfk/work/github/tengine/objs/nginx  prove -v -I ./tests/nginx-tests/nginx-tests/lib/    ./tests/nginx-tests/tengine-tests/ngx_http_upstream_vnswrr.t 
./tests/nginx-tests/tengine-tests/ngx_http_upstream_vnswrr.t .. 
1..9
ok 1 - vnswrr 8081
ok 2 - vnswrr 8082
ok 3 - peer down
ok 4 - weight 1
ok 5 - weight 2
ok 6 - vnswrr zone
ok 7 - vnswrr backup
ok 8 - no alerts
ok 9 - no sanitizer errors
ok
All tests successful.
Files=1, Tests=9,  0 wallclock secs ( 0.02 usr  0.00 sys +  0.08 cusr  0.01 csys =  0.11 CPU)
Result: PASS

Introduction

The VNSWRR module is an efficient load balancing algorithm that is smooth, decentralized, and high-performance compared to Nginx's official SWRR algorithm.

Example

http {

    upstream backend {
        vnswrr; # enable VNSWRR 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_vnswrr_module/
make
make install

Directive

  • vnswrr
Syntax: vnswrr
Default: none
Context: upstream

Enable VNSWRR load balancing algorithm.

Performance

In the same pressure environment, the CPU consumption of VNSWRR algorithm accounts for 0.27% ( ngx_http_upstream_get_vnswrr).
Compared with VNSWRR algorithm, the CPU consumption of SWRR (ngx_http_upstream_get_peer 39%) is an order of magnitude higher than VNSWRR.

  • Environment
CPU: Intel(R) Xeon(R) CPU E5-2682 v4 @ 2.50GHz

Tools:./wrk -t25  -d5m -c500  'http://ip/t2000'

Tengine:worker_processes 2; upstream endpoint {server0; ... server1999;}

Request Trace: Client --(keepalive)--> Tengine(proxy_pass) --(no keepalive)--> Endpoint

image

In the above environment, the QPS of VNSWRR increases by 60% compared with SWRR algorithm.

image

Observing the changes of QPS and RT in the different back-end number scenarios.
Under SWRR algorithm, when the number of back-end for every 500 addition, then the QPS of Nginx decreases by about 10% and RT increases by about 1 ms. But under the VNSWRR algorithm, QPS and RT do not change much.

image

image

@wangfakang wangfakang added this to the 2.3.1 milestone Jul 5, 2019
@chobits chobits modified the milestones: 2.3.1, 2.3.2 Jul 5, 2019
@chobits chobits self-requested a review July 5, 2019 08:52
}

*rpeer = best;
if (best == NULL) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

peers->peer will be never empty, and we don't skip failed peer, is it possible to have a NULL value best?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, thx.
The check logical is not necessary.

uvnscf->vnumber = i;
}

begin_number = (uvnscf->last_number + 1) % uvnscf->vnumber;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we don't need to % uvnscf->vnumber here? There is already a % uvnscf->vnumber in the for loop below.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is necessary. Because the initial value of begin_number is ngx_random() % peers->number , But uvnscf->vnumber <= peers->number.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants