Giter Site home page Giter Site logo

rate-limiter's Introduction

아키텍처

스크린샷 2024-06-22 오후 3 04 07



적용한 처리율 제한기 알고리즘

  • Sliding Window Log

흐름

  • 사용자가 product에 접근하는 경우 redis의 sorted set에 사용자의 key(ex: product:2)와 타임스탬프를 저장하게 됩니다.
  • 1초 이내에 5번 이상 접근하려는 경우 Too many requests 예외가 발생하게 됩니다.
  • redis의 sorted set의 ttl은 1초 입니다.

Lua Script

local key = KEYS[1]
local min = ARGV[1]
local max = ARGV[2]
local score = ARGV[3]
local value = ARGV[4]
local ttl = ARGV[5]

redis.call('ZREMRANGEBYSCORE', key, min, max)
redis.call('ZADD', key, score, value)
redis.call('EXPIRE', key, ttl)
local cardinality = redis.call('ZCARD', KEYS[1])

redis.log(redis.LOG_WARNING, "ZREMRANGEBYSCORE command key:", key, ", min:", min, ", max:", max)
redis.log(redis.LOG_WARNING, "ZADD command key:", key, ", score:", score, ", value:", value)
redis.log(redis.LOG_WARNING, "EXPIRE command key:", key, ", ttl:", ttl)
redis.log(redis.LOG_WARNING, "ZCARD command key:", key, ", cardinality", cardinality)

return cardinality

처리율 제한기 알고리즘 종류


참고

rate-limiter's People

Contributors

kdg0209 avatar torder-kdg avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.