Skip to content

Track scheduled function delay - #5592

Open
Shubham8287 wants to merge 9 commits into
masterfrom
shub/scheduled-function-delay-metric
Open

Track scheduled function delay#5592
Shubham8287 wants to merge 9 commits into
masterfrom
shub/scheduled-function-delay-metric

Conversation

@Shubham8287

@Shubham8287 Shubham8287 commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

Summary

fixes: https://github.com/clockworklabs/SpacetimeDBPrivate/issues/3441.

It chooses an arbitrary threshold of 50ms, if a scheduled function starts more than that threshold after its expected time, we emit a warning and record a metric.

Note that, metric does not necessarily tells If something is wrong with Host as drift can also happen due to module's previous schedule function taking long time to finish.

@Shubham8287
Shubham8287 marked this pull request as draft July 27, 2026 15:49
@Shubham8287
Shubham8287 force-pushed the shub/scheduled-function-delay-metric branch from b7fdfac to 61dfc95 Compare July 28, 2026 08:46
@Shubham8287
Shubham8287 marked this pull request as ready for review July 28, 2026 08:53
@Shubham8287
Shubham8287 requested a review from gefjon July 28, 2026 08:54

@gefjon gefjon left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

How much additional work would it be to make the threshold be, say, 25% of the requested delay, rather than a flat 50ms? I worry that 50ms is quite a long time, especially for games which want to run relatively frequent and relatively fast "tick" reducers.

Comment thread crates/core/src/host/scheduler.rs Outdated
Comment thread crates/core/src/host/scheduler.rs Outdated
Comment thread crates/core/src/host/scheduler.rs Outdated
@Shubham8287

Copy link
Copy Markdown
Contributor Author

How much additional work would it be to make the threshold be, say, 25% of the requested delay, rather than a flat 50ms?

The scheduling function has precision of few milliseconds, so we would still need some minimum threshold. On top of that, as I mentioned in the description, long running schedule functions can itself contribute to the delay, potentially causing many false positives.

As you already suggested to record a metric for every run, we will be using this value only logging purpose, so it may be fine?

@gefjon

gefjon commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

How much additional work would it be to make the threshold be, say, 25% of the requested delay, rather than a flat 50ms?

The scheduling function has precision of few milliseconds, so we would still need some minimum threshold. On top of that, as I mentioned in the description, long running schedule functions can itself contribute to the delay, potentially causing many false positives.

As you already suggested to record a metric for every run, we will be using this value only logging purpose, so it may be fine?

Yeah, I don't plan to directly alert on any single schedule invocation violating the threshold, I want to detect patterns of functions deviating significantly.

@Shubham8287
Shubham8287 requested a review from gefjon July 31, 2026 12:33

@gefjon gefjon left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good, thanks!

@Shubham8287
Shubham8287 enabled auto-merge July 31, 2026 15:18
@Shubham8287
Shubham8287 disabled auto-merge July 31, 2026 15:29
@Shubham8287
Shubham8287 enabled auto-merge July 31, 2026 15:35
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