File: proxyratelim.lua

package info (click to toggle)
memcached 1.6.39-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,320 kB
  • sloc: ansic: 62,281; perl: 12,500; sh: 4,569; makefile: 468; python: 402; xml: 59
file content (30 lines) | stat: -rw-r--r-- 781 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30

function mcp_config_pools()
    local tbf_global = mcp.ratelim_global_tbf({limit = 25, fillrate = 5, tickrate = 500})
    return tbf_global
end

function mcp_config_routes(t)
    -- limit is an arbitrary token count (bytes, requests, etc)
    -- fillrate is tokens per tickrate
    -- tickrate is milliseconds
    local tbf = mcp.ratelim_tbf({limit = 50, fillrate = 4, tickrate = 500})

    local tbf_global = t

    mcp.attach(mcp.CMD_MG, function(r)
        if tbf(15) then
            return "HD\r\n"
        else
            return "SERVER_ERROR slow down\r\n"
        end
    end)

    mcp.attach(mcp.CMD_GET, function(r)
        if tbf_global(10) then
            return "END\r\n"
        else
            return "SERVER_ERROR global slow down\r\n"
        end
    end)
end