-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
TimeService rapidly falls behind actual time. #2176
Comments
Hmm. |
TimeService falling behind is not load dependent. loop_time() (which is what I'm guessing is used for timeouts) will never fall behind by more than about 1 second. time() and strtime() will fall behind, no matter what the load is. strtime() falling behind causes Date headers in responses to be incorrect (this is how I discovered this). See https://gist.github.com/greg-barnett/00b67d3b098bc782db642b068ad4b0d3 for a test script, and output from the master branch and my bugfix. |
Sorry, it's not documented why we have TimeService either. Why not to use just |
It is implementation detail, not part of public API. But the header has 1 second accuracy. We could amortize formatting time by caching a string for 1 second. |
Sorry, I did mislead: time service is never used for timeout calculations but for datatime formatting only. |
So, caching may be implemented MUCH easier. Why not ? _cached_time = None
_cached_time_formatted = None
def format_current_datetime():
global _cached_time
global _cached_time_formatted
now = int(time.time())
if now != _cached_time:
_cached_time_formatted = some_format(now)
return _cached_time_formatted |
+1 |
TimeService is also used in _process_keepalive in RequestHandler, but that should be replaceable with a call to loop.time() |
This commit has a version of TimeService that only caches the formatted string for use in Date headers. |
if we make decision to simplify TimeService, then it should be removed at all. |
This commit has slightly cleaner/faster formatting I agree that getting rid of TimeService completely probably makes sense, but I don't know the codebase well enough to know where the functionality should reside. I don't want to add global variables if it can be avoided. |
Doing some more benchmarking, I'm not even convinced that caching is required. import time |
it is, 5-7% cpu |
@fafhrd91 do you have any benchmarking code that shows TimeService's caching of formatted date makes any significant performance difference? I have not been able to replicate any conditions where it has a noticeable impact. |
I don't have benchmarks now, but I did a lot of benchmarking when worked on performance. |
#2182 |
…ng (#2176) Thanks for @greg-barnett for the code I picked-up.
I hope the problem is fixed in 2.3 |
I'm currently on medical leave and can't devote any time to verifying the fix, so I will defer to @socketpair regarding closing this issue. |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a [new issue] for related bugs. |
TimeService falls behind actual time by about half a second every second. It is supposed to reset every 10 minutes, but doesn't.
More details and a fix are available at:
greg-barnett@de0cc62
The text was updated successfully, but these errors were encountered: