vislee / lua-resty-wrr

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

lua-resty-wrr

weight round robin for Openresty. Similar to ngx_http/stream_upstream_round_robin module.

Table of Contents

Synopsis

http {

    ...

    init_by_lua_block {
        local wrr = require "resty.wrr"
        local servers = {
            {addr="192.168.0.1:80",weight=1,max_fails=5,fail_timeout=3,max_conns=1000,},
            {addr="192.168.0.2:80",weight=2,max_fails=5,fail_timeout=3,max_conns=2000,},
        }
        rrp = wrr.new(servers)
    }

    server {
        listen 8080;

        location / {
            access_by_lua_block {
                local peer = rrp:init()
                local s = peer:get()
                ...
                peer:free()
            }

            proxy_pass ups;
        }
    }
}

Back to TOC

Methods

new

syntax: rrp, err = wrr.new(servers)

Creates a wrr object by servers. the failures, returns nil and error.

init

syntax: peer = rrp:init(tries?)

Creates a object for request. the tries is max retry times.

peer.tries: remaining retry times.

get

syntax: server = peer:get()

Pick a upstream server in peer object. No server is available, returns nil.

free

syntax: peer:free(state?)

Free the pick server and report a health failure, the state is wrr.PEER_FAILED(failed) or 0(OK).

Back to TOC

Author

wenqiang li(vislee)

Back to TOC

Copyright and License

This module is licensed under the BSD license.

Copyright (C) 2021-, by vislee.

All rights reserved.

Back to TOC

About

License:BSD 2-Clause "Simplified" License


Languages

Language:Perl 59.0%Language:Lua 41.0%