Crates.io | poem-ratelimit |
lib.rs | poem-ratelimit |
version | 0.2.2 |
source | src |
created_at | 2022-03-10 03:51:04.038293 |
updated_at | 2022-03-21 16:00:28.169648 |
description | poem-ratelimit is a ratelimit middleware for poem web framework. |
homepage | https://github.com/KernelErr/poem-ratelimit |
repository | https://github.com/KernelErr/poem-ratelimit |
max_upload_size | |
id | 547298 |
size | 20,736 |
Check examples, poem-ratelimit
is available on crates.io.
A yaml
configuration file is used to set limit for global service, per IP and route:
global:
# Global limit for all connections
max_requests: 20
# Seconds to refresh limit, we allow 20req/30s here
time_window: 30
ip:
# QPS limit for a single client IP
max_requests: 10
time_window: 30
route:
/:
# QPS limit for a single route
max_requests: 5
time_window: 30
For every requests, we use sliding window algorithm to check if the request is processable. Sorted lists with key like IP, route is stored in Redis. You can check the lua
script in lib.rs
.
poem-ratelimit
is licensed under Apache-2.0.