mennanov / limiters

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

add LockPostgreSQL and BenchmarkDistLockers #39

Closed leeym closed 7 months ago

leeym commented 7 months ago

Add the following two

goarch: amd64
pkg: github.com/mennanov/limiters
cpu: Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
BenchmarkDistLockers
2024/03/16 15:44:22 Connected to 127.0.0.1:2181
2024/03/16 15:44:22 authenticated: id=72064875209293827, timeout=4000
2024/03/16 15:44:22 re-submitting `0` credentials after reconnect
BenchmarkDistLockers/LockEtcd
BenchmarkDistLockers/LockEtcd-12                     171           6576282 ns/op
BenchmarkDistLockers/LockConsul
BenchmarkDistLockers/LockConsul-12                   100          15450609 ns/op
BenchmarkDistLockers/LockZookeeper
BenchmarkDistLockers/LockZookeeper-12                265           4537545 ns/op
BenchmarkDistLockers/LockRedis
BenchmarkDistLockers/LockRedis-12                   1238            984753 ns/op
BenchmarkDistLockers/LockMemcached
BenchmarkDistLockers/LockMemcached-12                816           1608760 ns/op
BenchmarkDistLockers/LockPostgreSQL
BenchmarkDistLockers/LockPostgreSQL-12               670           1664998 ns/op

It will be easier to review in unified view and hide whitespace.

I should reopen the previous PR instead of creating a new one. Anyway, the difference is that in https://github.com/mennanov/limiters/pull/38 I used session-level advisory lock. Since in the test we share the same database connection, thus the same session, between two lockers, they interfere with each other as the lock acquired by one locker can be released by the other one. In this PR I use transaction-level advisory lock, so each locker has its own transaction even if they share the same database connection.

codecov[bot] commented 7 months ago

Codecov Report

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

Project coverage is 80.05%. Comparing base (c1474e1) to head (2aa986d).

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #39 +/- ## ========================================== + Coverage 79.90% 80.05% +0.15% ========================================== Files 12 12 Lines 1438 1449 +11 ========================================== + Hits 1149 1160 +11 Misses 212 212 Partials 77 77 ```

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

mennanov commented 7 months ago

Awesome, thanks!