go-chi / httprate

net/http rate limiter middleware
MIT License
270 stars 18 forks source link

Export in-memory counter for external use #39

Closed VojtechVitek closed 3 months ago

VojtechVitek commented 3 months ago

httprate.NewLocalLimitCounter(windowLength)

The idea is that other backends (e.g. https://github.com/go-chi/httprate-redis) could fall-back to the in-memory counter.

github-actions[bot] commented 3 months ago

Benchmark Results

goos: linux
goarch: amd64
pkg: github.com/go-chi/httprate
cpu: AMD EPYC 7763 64-Core Processor                
               │ master.txt  │               pr.txt               │
               │   sec/op    │   sec/op     vs base               │
LocalCounter-4   19.60m ± 1%   19.72m ± 1%  +0.61% (p=0.009 n=10)

               │  master.txt  │             pr.txt             │
               │     B/op     │     B/op      vs base          │
LocalCounter-4   2.833Mi ± 0%   2.831Mi ± 0%  ~ (p=0.481 n=10)

               │ master.txt  │            pr.txt             │
               │  allocs/op  │  allocs/op   vs base          │
LocalCounter-4   121.5k ± 0%   121.4k ± 0%  ~ (p=0.481 n=10)