Skip to content

Be1zebub/Leaky-Bucket.lua

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 

Repository files navigation

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

Topics

Resources

License

Stars

Watchers

Forks

Languages