Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Improve performance by using MULTI and MGET commands #13

Merged
merged 2 commits into from
Jul 25, 2024
Merged

Conversation

VojtechVitek
Copy link
Contributor

@VojtechVitek VojtechVitek commented Jul 25, 2024

  • Using MULTI transaction for INCR + EXPIRE will guarantee that we won't ever create any keys without expiry
  • Using MGET to fetch both previous and current window counters in a single atomic operation will improve throughput

Copy link

Benchmark Results

goos: linux
goarch: amd64
pkg: github.com/go-chi/httprate-redis
cpu: AMD EPYC 7763 64-Core Processor                
               │ master.txt │            pr.txt            │
               │   sec/op   │   sec/op    vs base          │
LocalCounter-4   1.569 ± 2%   1.578 ± 2%  ~ (p=0.353 n=10)

               │  master.txt  │                pr.txt                │
               │     B/op     │     B/op      vs base                │
LocalCounter-4   33.89Mi ± 0%   41.38Mi ± 1%  +22.11% (p=0.000 n=10)

               │ master.txt  │               pr.txt                │
               │  allocs/op  │  allocs/op   vs base                │
LocalCounter-4   1.222M ± 0%   1.380M ± 0%  +12.89% (p=0.000 n=10)

Copy link

Benchmark Results

goos: linux
goarch: amd64
pkg: github.com/go-chi/httprate-redis
cpu: AMD EPYC 7763 64-Core Processor                
               │ master.txt │               pr.txt               │
               │   sec/op   │   sec/op    vs base                │
LocalCounter-4   1.679 ± 3%   1.294 ± 1%  -22.97% (p=0.000 n=10)

               │  master.txt  │                pr.txt                │
               │     B/op     │     B/op      vs base                │
LocalCounter-4   33.88Mi ± 0%   38.77Mi ± 0%  +14.43% (p=0.000 n=10)

               │ master.txt  │               pr.txt               │
               │  allocs/op  │  allocs/op   vs base               │
LocalCounter-4   1.222M ± 0%   1.270M ± 0%  +3.93% (p=0.000 n=10)

@VojtechVitek
Copy link
Contributor Author

-22.97% .. 1.3x speedup in the CI 🚀

-52.53% .. 2x speedup on my macOS M2 laptop 🚀 🚀

$ benchstat old.txt new.txt
goos: darwin
goarch: arm64
pkg: github.com/go-chi/httprate-redis
               │   old.txt    │               new.txt                │
               │    sec/op    │    sec/op     vs base                │
LocalCounter-8   1699.3m ± 7%   806.7m ± 11%  -52.53% (p=0.000 n=10)

               │   old.txt    │               new.txt               │
               │     B/op     │     B/op      vs base               │
LocalCounter-8   32.84Mi ± 0%   34.92Mi ± 0%  +6.32% (p=0.000 n=10)

               │   old.txt   │              new.txt               │
               │  allocs/op  │  allocs/op   vs base               │
LocalCounter-8   1.261M ± 0%   1.230M ± 0%  -2.45% (p=0.000 n=10)

@VojtechVitek VojtechVitek merged commit 71c932d into master Jul 25, 2024
3 checks passed
@VojtechVitek VojtechVitek deleted the 6xX3tZqr branch July 25, 2024 16:25
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant