-
Notifications
You must be signed in to change notification settings - Fork 25
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
fix: use a monotonic clock in memory storage #7
Conversation
Codecov Report
@@ Coverage Diff @@
## master #7 +/- ##
===========================================
- Coverage 100% 88.76% -11.24%
===========================================
Files 8 8
Lines 207 356 +149
===========================================
+ Hits 207 316 +109
- Misses 0 40 +40
Continue to review full report at Codecov.
|
This looks OK. monotonic() is a tiny bit slower than time(), but only by a few hundred ns, so nothing to worry about. However, it is slow enough to slightly increase |
Here it also fails in tests/test_multithreading.py:144: AssertionError
Not sure how to fix that |
Hi @xrmx ! Just to clarify, even the normal It seems time.monotonic() is now available in the standard lib since 3.5+, so we could probably use that where available. |
That should be more robust against system time update, e.g. ntp or leap seconds.
Hi @vytas7 Python docs says it uses gettimeofday:
gettimeofday man page says:
So the change still looks sensible to me, I've pushed using time.monotic() because it's clearer but CI still runs of Python 2 it'll not work. Said that I have no use for this PR so leave it for posterity :) |
Aha, right, good call regarding the underlying implementation... That does seem indeed susceptible to time adjustments. OTOH, DST doesn't, to my understanding, affect time.time(). I'll try to move this stuff to GH Actions, and drop 3.3 and 3.4 support. Regarding 2.7, I guess we could also drop it since it's long past its EOL... OTOH it doesn't cost much to keep it unless a major development is planned, which seems less likely at this point. |
In contrast to the previously suggested 3rd party library, I'm not able to benchmark any meaningful performance difference between So merging this 🤠 |
Released as part of https://github.com/falconry/token-bucket/releases/tag/0.3.0 |
That should be more robust against system time update, e.g.
ntp or DST change.