Skip to content

prabhat393/QPS-limiter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Redis-based QPS and total query limiter

This is an implementation of query/sec and total query limiter using Redis. We are making use of SET with expire, INCR and GET to implement the limiter.

Due to the EXPIRE passive behaviour, we were observing that redis will either miss deleting the key when TTL has past or delete with some delay. This was giving us false "Too many requests" especially in the case of QPS. So, we also added TTL check for the key using PTTL and deleting it using DEL, if the TTL is approaching its expiry.

How to work with this repo

  1. Set the following env variables in a .env file in the project root directory:
API_PORT=3000
API_MODE=debug
REDIS_ADDR=redis:6379
QPS_LIMIT=10
QUERY_LIMIT=100
  1. Build the application using make app

  2. Bring up containers using docker-compose up

  3. Overwrite the qps and query limit constants in test/main.go file to what you have in .env file. The variables in test/main.go must correspond to the values in .env file.

  4. Run test using go run test/main.go. Your will see the result logs in the results folder. There are some logs already for the following inputs:

    • Query limit: 10000, QPS limit: 5
    • Query limit: 10000, QPS limit: 10
    • Query limit: 10000, QPS limit: 50

About

Redis-based qps limiter

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published