Repository navigation
⚡ Optimize JSON serialization for static endpoints #80
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,37 @@ | ||||||||||
| import urllib.request | ||||||||||
| import time | ||||||||||
| import threading | ||||||||||
|
|
||||||||||
| URL = "http://localhost:8003/" | ||||||||||
| NUM_REQUESTS = 1000 | ||||||||||
|
|
||||||||||
| def make_requests(): | ||||||||||
| for _ in range(NUM_REQUESTS): | ||||||||||
| try: | ||||||||||
| urllib.request.urlopen(URL).read() | ||||||||||
| except Exception: | ||||||||||
| pass | ||||||||||
|
Comment on lines
+12
to
+13
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Silently ignoring all exceptions with
Suggested change
|
||||||||||
|
|
||||||||||
| def run_benchmark(): | ||||||||||
| threads = [] | ||||||||||
| start_time = time.time() | ||||||||||
|
|
||||||||||
| for _ in range(10): | ||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The number of threads (10) is hardcoded. This value is used again on line 29 for calculating There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The number of threads (10) is hardcoded here and again on line 29 when calculating It would be better to define the number of threads as a constant at the top of the script, similar to |
||||||||||
| t = threading.Thread(target=make_requests) | ||||||||||
| threads.append(t) | ||||||||||
| t.start() | ||||||||||
|
|
||||||||||
| for t in threads: | ||||||||||
| t.join() | ||||||||||
|
|
||||||||||
| end_time = time.time() | ||||||||||
| duration = end_time - start_time | ||||||||||
| total_requests = NUM_REQUESTS * 10 | ||||||||||
| rps = total_requests / duration | ||||||||||
|
|
||||||||||
| print(f"Total Requests: {total_requests}") | ||||||||||
| print(f"Duration: {duration:.2f} seconds") | ||||||||||
| print(f"Requests per Second: {rps:.2f}") | ||||||||||
|
|
||||||||||
| if __name__ == "__main__": | ||||||||||
| run_benchmark() | ||||||||||
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.
Using a broad
except Exception: passsilently swallows all errors. This can be misleading, as the benchmark might report success even if all requests are failing due to network issues, server errors, or other problems. It's better to at least log the error to be aware of any issues during the benchmark run.