-
Notifications
You must be signed in to change notification settings - Fork 6
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 timing middleware #11
Add timing middleware #11
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor suggestions
src/nsls2api/middleware.py
Outdated
if scope["type"] != "http": | ||
await self.app(scope, receive, send) | ||
return | ||
start_time = time.time() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Best practice is to use time.monotonic()
for these kinds of things because it avoids jitter across a clock sync.
start_time = time.time() | |
start_time = time.monotonic() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or would time.perf_counter()
be better still ?
@@ -1,5 +1,5 @@ | |||
# | |||
# This file is autogenerated by pip-compile with Python 3.12 | |||
# This file is autogenerated by pip-compile with Python 3.10 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Intentional step backward in Python version?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Intentional step backward in Python version?
Not intentional, just fighting with hatch to create the correct python virtual env for me! :)
Adding a simple timing middleware. Using Starlette as this is more efficient (but less convenient) that the inbuilt FastAPI middleware.