mennanov / limiters

Golang rate limiters for distributed applications
https://godoc.org/github.com/mennanov/limiters
MIT License
411 stars 47 forks source link

Add LockMySQL #40

Closed leeym closed 6 months ago

leeym commented 6 months ago

Add LockMySQL using MySQL's user-level lock. Also, using one database connection to create multiple lockers is probably not how it is used in normal cases, so revert LockPostgreSQL to use session-level as well to maintain the same syntax like LockMySQL

LockRedis is still the most performant lock. LockMemcached, LockPostgreSQL and LockMySQL are about the same.

goos: darwin
goarch: amd64
pkg: github.com/mennanov/limiters
cpu: Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
BenchmarkDistLockers
2024/03/18 23:31:21 Connected to 127.0.0.1:2181
2024/03/18 23:31:21 authenticated: id=72065004698337301, timeout=4000
2024/03/18 23:31:21 re-submitting `0` credentials after reconnect
BenchmarkDistLockers/LockMySQL
BenchmarkDistLockers/LockMySQL-12                   1032           1090960 ns/op
BenchmarkDistLockers/LockEtcd
BenchmarkDistLockers/LockEtcd-12                     274           4639649 ns/op
BenchmarkDistLockers/LockConsul
BenchmarkDistLockers/LockConsul-12                   201           5889630 ns/op
BenchmarkDistLockers/LockZookeeper
BenchmarkDistLockers/LockZookeeper-12                440           2722693 ns/op
BenchmarkDistLockers/LockRedis
BenchmarkDistLockers/LockRedis-12                   2056            612462 ns/op
BenchmarkDistLockers/LockMemcached
BenchmarkDistLockers/LockMemcached-12               1104           1089090 ns/op
BenchmarkDistLockers/LockPostgreSQL
BenchmarkDistLockers/LockPostgreSQL-12              1083           1128017 ns/op
codecov[bot] commented 6 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 80.12%. Comparing base (fdeb965) to head (cac9a38).

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #40 +/- ## ========================================== + Coverage 80.05% 80.12% +0.06% ========================================== Files 12 12 Lines 1449 1454 +5 ========================================== + Hits 1160 1165 +5 Misses 212 212 Partials 77 77 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

leeym commented 6 months ago

It doesn't work with connection pooling.