Pacemaker - Rate limit library. Currently implemented rate limits are

PaceMaker

Rate limit library. Currently implemented rate limits are

Fixed window rate limit

Fixed window limits—such as 3,000 requests per hour or 10 requests per day—are easy to state, but they are subject to spikes at the edges of the window, as available quota resets. Consider, for example, a limit of 3,000 requests per hour, which still allows for a spike of all 3,000 requests to be made in the first minute of the hour, which might overwhelm the service.

Starts counting time windows when the first request arrives.

Fixed truncated window rate limit

Same as Fixed Window rate limit but truncates the rate limit window to the rate interval configured in order to adjust to real time intervals passing. E.g:

  1. Rate limit interval is configured for new windows every 10 seconds
  2. First request arrives at 2022-02-05 10:23:23
  3. Current rate limit window: from 2022-02-05 10:23:20 to 2022-02-05 10:23:30

You can refer to google architecture docs to read more about rate limits.

TODO:

  • Fixed window bucket variant (refill token with capacity at same rate)
  • Redis storage
  • Token bucket
  • Leaky bucket
Owner
Marquitos
🇪🇸 你喜欢我的裤子吗 🇨🇳
Marquitos
Similar Resources

Light weight http rate limiting proxy

Introduction Light weight http rate limiting proxy. The proxy will perform rate limiting based on the rules defined in the configuration file. If no r

Dec 23, 2022

A little ping pong service that implements rate limiting with golang

Fred the Guardian Introduction Writing a little ping pong service that implements rate limiting with the programming language golang. Requirements Web

Jan 2, 2022

A rate limiter for the gin framework

GinRateLimit GinRateLimit is a rate limiter for the gin framework. By default, it can only store rate limit info in memory. If you want to store it so

Dec 22, 2021

Common rate-limiter implementations

Overview An example Rate Limiter library used to control the rate that events occur, but these can also be used as thresholds that should replenish ov

Dec 1, 2021

A rate limiter for Golang, with ETCD data bindings

Go Rate limiter This package allows us to have a distributed rate limiter, using Redis as a central counter. The limits that are set are only "soft" l

Dec 9, 2021

Go rate limiter used to ensure a minimum duration between executions.

Ratelimiter Rate limiter used to ensure a minimum duration between executions. Additionally supports the optional limit of max queue size. This can be

Jul 14, 2022

Gcra - Package gcra implements the generic cell rate algorithm

gcra Package gcra implements the generic cell rate algorithm (GCRA). Example opt

Jan 23, 2022

A Caddy v2 extension to apply rate-limiting for HTTP requests

ratelimit A Caddy v2 extension to apply rate-limiting for HTTP requests. Installation $ xcaddy build --with github.com/owlwang/caddy-ratelimit Caddyfi

Jan 28, 2022

BGP implemented in the Go Programming Language

GoBGP: BGP implementation in Go GoBGP is an open source BGP implementation designed from scratch for modern environment and implemented in a modern pr

Dec 31, 2022
Comments
  • FixedTruncatedWindowRateLimiter Check() does not work  correctly

    FixedTruncatedWindowRateLimiter Check() does not work correctly

    	rateLimit := pacemaker.NewTokenFixedWindowRateLimiter(
    		pacemaker.NewFixedTruncatedWindowRateLimiter(
    			pacemaker.FixedTruncatedWindowArgs{
    				Capacity: cfg.Capacity,
    				Rate: pacemaker.Rate{
    					Unit:   cfg.Rate.Unit,
    					Amount: cfg.Rate.Amount,
    				},
    				Clock: cfg.Clock,
    				DB: pacemaker.NewFixedWindowRedisStorage(
    					cfg.RedisCli,
    					pacemaker.FixedWindowRedisStorageOpts{
    						Prefix: cfg.Bucket,
    					},
    				),
    			},
    		),
    	)
    
    	result, err := rateLimit.Try(context.Background(), 1)
    	if err != nil {
    		log.Errorf("error try: '%v'", err)
    	}
    
    	log.Debugf("Try Result: '%v'", result)
    
    	result, err = rateLimit.Check(context.Background(), 1)
    	if err != nil {
    		log.Errorf("error try: '%v'", err)
    	}
    
    	log.Debugf("Check Result: '%v'", result)
    
    $ go run examples/rate_limits/main.go                                            
    2022-11-04T12:48:03Z - DEBUG - {"service":"example"} - connected to redis
    2022-11-04T12:48:03Z - DEBUG - {"service":"example"} - Try Result: '{0s 159990}'
    2022-11-04T12:48:03Z - DEBUG - {"service":"example"} - Check Result: '{0s 159990}'
    $ go run examples/rate_limits/main.go                                            
    2022-11-04T12:48:07Z - DEBUG - {"service":"example"} - connected to redis
    2022-11-04T12:48:07Z - DEBUG - {"service":"example"} - Try Result: '{0s 159989}'
    2022-11-04T12:48:07Z - DEBUG - {"service":"example"} - Check Result: '{0s 159989}'
    $ go run examples/rate_limits/main.go                                            
    2022-11-04T12:48:24Z - DEBUG - {"service":"example"} - connected to redis
    2022-11-04T12:48:24Z - DEBUG - {"service":"example"} - Try Result: '{0s 159988}'
    $ go run examples/rate_limits/main.go                                            
    2022-11-04T12:48:42Z - DEBUG - {"service":"example"} - connected to redis
    2022-11-04T12:48:42Z - DEBUG - {"service":"example"} - Check Result: '{0s 160000}'
    $ go run examples/rate_limits/main.go                                            
    2022-11-04T12:48:45Z - DEBUG - {"service":"example"} - connected to redis
    2022-11-04T12:48:45Z - DEBUG - {"service":"example"} - Check Result: '{0s 160000}'
    $ go run examples/rate_limits/main.go                                            
    2022-11-04T12:49:03Z - DEBUG - {"service":"example"} - connected to redis
    2022-11-04T12:49:03Z - DEBUG - {"service":"example"} - Try Result: '{0s 159987}'
    2022-11-04T12:49:03Z - DEBUG - {"service":"example"} - Check Result: '{0s 159987}'
    

    If we run both(try/check) the returned value by Check method is correct.

    If we run only the check method, the returned value of Check methods is the capacity of the bucket instead of the remaining value.

  • fix: truncated window on rates for units greater than seconds

    fix: truncated window on rates for units greater than seconds

    Para unidades por debajo del minuto se necesita truncate con Rate.Unit, sin embargo, para unidades mayores, el truncado solo tiene sentido hacerlo mediante rate.Duration().

  • fix: truncated window rate limits

    fix: truncated window rate limits

    Prior to this commit, truncated rate limits were seriously malfunctioning. Tests were passing because rate windows were always configured to work with seconds (TODO @sonirico add more tests with greater time units).

  • feat: prevent increasing counter state

    feat: prevent increasing counter state

    Prior to this commit when employing the 'Try' interface, if the call incurred in rate limit, the state counter accumulated payload tokens unnecessarily, making the 'Check' interface to return unexpected values.

Related tags
Dhrate - Quickly check Dockerhub rate (limit) as an unauthenticated user
Dhrate - Quickly check Dockerhub rate (limit) as an unauthenticated user

Dockerhub Rate A small Go program that returns the Dockerhub rate of an unauthen

Feb 7, 2022
Ratelimit - This package provides a Golang implementation of the leaky-bucket rate limit algorithm

Go rate limiter This package provides a Golang implementation of the leaky-bucke

Jul 26, 2022
A very simple rate limiter in go, made as a learning project to learn go and rate limiting patterns!
A very simple rate limiter in go, made as a learning project to learn go and rate limiting patterns!

rate-limiter-go A very simple rate limiter in go, made as a learning project to learn go and rate limiting patterns! Demo: Running the project: To exe

Jun 1, 2022
Redis-rate-limiter - An abstraction over redist rate/v9 package

RATE_LIMIT_POC Notes This POC is based on github.com/go-redis/redis_rate/v9 pack

Feb 14, 2022
A Go package for sending and receiving ethernet frames. Currently supporting Linux, Freebsd, and OS X.

ether ether is a go package for sending and receiving ethernet frames. Currently supported platform: BPF based OS X FreeBSD AF_PACKET based Linux Docu

Sep 27, 2022
Antenna RPC is an RPC protocol for distributed computing, it's based on QUIC and Colfer. its currently an WIP.

aRPC - Antenna Remote Procedure Call Antenna remote procedure call (aRPC) is an RPC protocol focused on distributed processing and HPC. aRPC is implem

Jun 16, 2021
WebRTC media servers stress testing tool (currently only Janus)
 WebRTC media servers stress testing tool (currently only Janus)

GHODRAT WebRTC media servers stress testing tool (currently only Janus) Architecture Janus media-server under load Deployment ghodrat # update or crea

Nov 9, 2022
Checks sneaker availability, currently Asos/JD/Nike + Air Force 1 '07 44 only

airforce Setup Requires a .env file with Twilio credentials and phone numbers. SID=AC0ae6d46612d3a0c3d49977485652f665 TOKEN=7ff8d07a7d0fc9e6432a14ad84

Dec 12, 2021
Golang implementation of Sliding Window Algorithm for distributed rate limiting.
Golang implementation of Sliding Window Algorithm for distributed rate limiting.

slidingwindow Golang implementation of Sliding Window Algorithm for distributed rate limiting. Installation $ go get -u github.com/RussellLuo/slidingw

Dec 27, 2022
HTTP rate limiting module for Caddy 2

This module implements both internal and distributed HTTP rate limiting. Requests can be rejected after a specified rate limit is hit.

Jan 3, 2023