Be1zebub / Leaky-Bucket.lua

A Lua implementation of Leaky bucket algorithm

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Leaky-Bucket.lua

A Lua implementation of Leaky bucket algorithm https://en.wikipedia.org/wiki/Leaky_bucket

Example

local LeakyBucket = require("leaky-bucket")(1000, 50) -- 1 liter capacity, 50 milliliters per second bandwidth

function webserver:onRequestReceive(request, response)
	LeakyBucket:Add(request.headers.length, function() -- fluid size = request length
		response.headers.code = 200
		response.body = "pong!"
		response()
	end)
end

while true do
	LeakyBucket()
	webserver.listen()
end

TODO

gmod net.Incoming ratelimiter based on this lib

Join to our developers community incredible-gmod.ru

thumb

About

A Lua implementation of Leaky bucket algorithm

License:MIT License


Languages

Language:Lua 100.0%