Skip to content

Notebook query elapsed time #644

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

Merged
merged 5 commits into from
May 23, 2023
Merged

Notebook query elapsed time #644

merged 5 commits into from
May 23, 2023

Conversation

SilasMarvin
Copy link
Contributor

Added support for dashboard notebooks showing server side time elapsed for queries

@@ -75,7 +75,14 @@
<div class="notebook-duration">
<div class="markdown-body">
<div class="flex flex-row-reverse">
<code>TODO</code>
<code>Time: <%-
Copy link
Contributor

Choose a reason for hiding this comment

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

Did you consider moving this inside the sql.html <div class="markdown-body">? I think that might be better to track each statement independently, but I only thought it through because of the warning about an unused variable in the template.

Otherwise, I'd move it to the cell template that uses it.

Copy link
Contributor Author

@SilasMarvin SilasMarvin May 22, 2023

Choose a reason for hiding this comment

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

Sorry I totally missed the unused variable error. I switched back to stable from nightly and can see it now.

That was my original plan, but then I saw in the models.rs the Cell struct already had an execution_time attribute and the cell.html had a TODO section for it.

I just pushed a commit that also shows the timing for each sql statement independently. Let me know what you think! Do you want me to remove the rendering of the Cell execution_time in the cell.html? If so, should I completely remove the execution_time attribute for the Cell struct and update the migrations to not include that column?

Copy link
Contributor

@montanalow montanalow left a comment

Choose a reason for hiding this comment

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

This is looking pretty good to me, with a couple cleanups.

microseconds @ 1000000.. => format!("{}s", (microseconds as f64) / 1000000.),
microseconds @ 1000..=999999 => format!("{}ms", (microseconds as f64) / 1000.),
microseconds @ 0..=999 => format!("{}μs", microseconds),
_ => "0".to_string(),
Copy link
Contributor

Choose a reason for hiding this comment

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

This is unreachable, and unnecessary since your conditions are exhaustive (according the the compiler).

@@ -24,6 +24,15 @@
<% } %>
</tbody>
</table>
<code>
Time:
<%- match execution_duration.as_micros() {
Copy link
Contributor

Choose a reason for hiding this comment

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

It'd be nice to have a util function to convert a duration to a string consistently throughout the app that can be reused across these placements.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added a utils.rs module with a function for doing this. I made it take an f64, as we convert it to that regardless of whether we are working with a std::time::Duration or postgres Interval.

@@ -24,6 +24,15 @@
<% } %>
</tbody>
</table>
<code>
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be nice to hide this block if there is only a single statement, so that we don't double display the timing in that case.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

@montanalow montanalow merged commit 04f7e26 into postgresml:master May 23, 2023
@SilasMarvin SilasMarvin deleted the notebook-query-elapsed-time branch May 23, 2023 01:20
SilasMarvin added a commit that referenced this pull request Oct 5, 2023
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