-
Notifications
You must be signed in to change notification settings - Fork 4
Track recent times #231
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: master
Are you sure you want to change the base?
Track recent times #231
Changes from 5 commits
9227999
ddeb95d
aa48597
e47524e
e17e784
580d6f8
a2e998e
c8e876e
e094153
2e9bfa9
a4a1d1d
e8a4a00
17c4107
38677c3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -9,6 +9,7 @@ | |||||
| import time | ||||||
| import os | ||||||
| import re | ||||||
| from collections import deque | ||||||
| from enum import Enum | ||||||
| from typing import Dict, List, Union, Annotated, Optional | ||||||
|
|
||||||
|
|
@@ -35,6 +36,10 @@ | |||||
| allow_headers=["*"], | ||||||
| ) | ||||||
|
|
||||||
| # We track the time taken for each Solr query for the last 1000 queries so we can track performance via /status. | ||||||
| RECENT_TIMES_COUNT = os.getenv("RECENT_TIMES_COUNT", 1000) | ||||||
| recent_query_times = deque(maxlen=RECENT_TIMES_COUNT) | ||||||
|
|
||||||
| # ENDPOINT / | ||||||
| # If someone tries accessing /, we should redirect them to the Swagger interface. | ||||||
| @app.get("/", include_in_schema=False) | ||||||
|
|
@@ -110,6 +115,11 @@ async def status() -> Dict: | |||||
| 'segmentCount': index.get('segmentCount', ''), | ||||||
| 'lastModified': index.get('lastModified', ''), | ||||||
| 'size': index.get('size', ''), | ||||||
| 'recent_queries': { | ||||||
| 'count': len(recent_query_times), | ||||||
| 'mean_time_ms': sum(recent_query_times) / len(recent_query_times) if recent_query_times else -1, | ||||||
| 'recent_times_ms': list(recent_query_times), | ||||||
| } | ||||||
gaurav marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
| } | ||||||
| else: | ||||||
| return { | ||||||
|
|
@@ -605,9 +615,12 @@ async def lookup(string: str, | |||||
| debug=debug_for_this_request)) | ||||||
|
|
||||||
| time_end = time.time_ns() | ||||||
| time_taken_ms = (time_end - time_start)/1_000_000 | ||||||
| time_taken_ms_solr = (time_solr_end - time_solr_start)/1_000_000 | ||||||
| recent_query_times.append(time_taken_ms) | ||||||
|
||||||
| recent_query_times.append(time_taken_ms) | |
| recent_query_times.append(time_taken_ms_solr) |
Uh oh!
There was an error while loading. Please reload this page.