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 timing middleware #11

Merged
merged 14 commits into from
Jan 29, 2024
Merged

Conversation

stuartcampbell
Copy link
Collaborator

Adding a simple timing middleware. Using Starlette as this is more efficient (but less convenient) that the inbuilt FastAPI middleware.

Copy link
Collaborator

@danielballan danielballan left a comment

Choose a reason for hiding this comment

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

Minor suggestions

if scope["type"] != "http":
await self.app(scope, receive, send)
return
start_time = time.time()
Copy link
Collaborator

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.

Suggested change
start_time = time.time()
start_time = time.monotonic()

Copy link
Collaborator Author

@stuartcampbell stuartcampbell Jan 19, 2024

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 ?

src/nsls2api/middleware.py Outdated Show resolved Hide resolved
@@ -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
Copy link
Collaborator

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?

src/nsls2api/main.py Outdated Show resolved Hide resolved
Copy link
Collaborator Author

@stuartcampbell stuartcampbell left a 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! :)

@danielballan danielballan merged commit fd7c1e2 into NSLS2:main Jan 29, 2024
1 check passed
@stuartcampbell stuartcampbell deleted the add-timing-middleware branch February 6, 2024 13:17
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