Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

add LockPostgreSQL and BenchmarkDistLockers #39

Merged
merged 1 commit into from
Mar 19, 2024

Conversation

leeym
Copy link
Collaborator

@leeym leeym commented Mar 16, 2024

Add the following two

  • LockPostgreSQL implements DistLocker using advisory locks in PostgreSQL
  • BenchmarkDistLockers to compare the performance for distributed lockers
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 #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.

Copy link

codecov bot commented Mar 16, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

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

Additional details and impacted files
@@            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              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@leeym leeym marked this pull request as ready for review March 16, 2024 22:39
@leeym leeym force-pushed the add-LockPostgreSQL branch from 1c4438d to 38b6b93 Compare March 16, 2024 23:02
Copy link
Owner

@mennanov mennanov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!
I left just 1 small comment.

Thanks!

Makefile Outdated Show resolved Hide resolved
@leeym leeym force-pushed the add-LockPostgreSQL branch 2 times, most recently from a77138b to 91fc1dd Compare March 18, 2024 19:36
@leeym leeym force-pushed the add-LockPostgreSQL branch from 91fc1dd to 2aa986d Compare March 18, 2024 19:42
@leeym leeym requested a review from mennanov March 18, 2024 21:43
@mennanov mennanov merged commit fdeb965 into mennanov:master Mar 19, 2024
9 checks passed
@mennanov
Copy link
Owner

Awesome, thanks!

@leeym leeym deleted the add-LockPostgreSQL branch May 23, 2024 00:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants