-
Notifications
You must be signed in to change notification settings - Fork 1
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 routes for time-to-first-byte stats #281
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -270,3 +270,48 @@ export const fetchDailyRetrievalResultCodes = async (pgPools, filter) => { | |
const stats = Object.entries(days).map(([day, rates]) => ({ day, rates })) | ||
return stats | ||
} | ||
|
||
/** | ||
* Fetches daily global retrieval time statistics | ||
* @param {import('@filecoin-station/spark-stats-db').PgPools} pgPools | ||
* @param {import('./typings.js').DateRangeFilter} filter | ||
*/ | ||
export const fetchDailyRetrievalTimes = async (pgPools, filter) => { | ||
const { rows } = await pgPools.evaluate.query(` | ||
SELECT | ||
day::text, | ||
percentile_cont(0.5) WITHIN GROUP (ORDER BY time_to_first_byte_p50) AS ttfb_p50 | ||
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. Having variables 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. There are two aspects to consider:
Also, note that a p50 value calculated from a list of p50 values is not a true global p50 value; it's just an approximation we decided to use to keep this initial implementation simple. In that light, I propose to use the name [
{ "day": "2025-01-08", "ttfb": 850 }
{ "day": "2025-01-09", "ttfb": 930 }
] I think this name works well for the SQL query, too, but I don't mind using a different name there. 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. One more idea to consider - should we encode the unit (milliseconds) in the property name? [
{ "day": "2025-01-08", "ttfb_ms": 850 }
{ "day": "2025-01-09", "ttfb_ms": 930 }
] 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.
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.
Let's convert the number to an integer, e.g. using the Postgres
This is a minor detail, though - I am fine with any rounding function. What's important to me is to produce integer values (number of milliseconds), since that's the precision we are getting from the checker ndoes. |
||
FROM retrieval_times | ||
WHERE day >= $1 AND day <= $2 | ||
GROUP BY day | ||
ORDER BY day | ||
`, [ | ||
filter.from, | ||
filter.to | ||
]) | ||
return rows | ||
} | ||
|
||
/** | ||
* Fetches per miner daily retrieval time statistics | ||
* @param {import('@filecoin-station/spark-stats-db').PgPools} pgPools | ||
* @param {import('./typings.js').DateRangeFilter} filter | ||
* @param {string} minerId | ||
*/ | ||
export const fetchDailyMinerRetrievalTimes = async (pgPools, { from, to }, minerId) => { | ||
const { rows } = await pgPools.evaluate.query(` | ||
SELECT | ||
day::text, | ||
miner_id, | ||
percentile_cont(0.5) WITHIN GROUP (ORDER BY time_to_first_byte_p50) AS ttfb_p50 | ||
FROM retrieval_times | ||
WHERE miner_id = $1 AND day >= $2 AND day <= $3 | ||
GROUP BY day, miner_id | ||
ORDER BY day | ||
`, [ | ||
minerId, | ||
from, | ||
to | ||
]) | ||
return rows | ||
} |
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.
"Retrieval times" isn't self explanatory - it could for example also be the timestamps at which retrievals have been attempted. What about this?
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.
See for example chrome dev tools also using "timings":
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.
+1 to use
timings