Skip to content
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

rust: Add support for ws-protocol time capability #188

Merged
merged 5 commits into from
Feb 7, 2025

Conversation

gasmith
Copy link
Contributor

@gasmith gasmith commented Feb 5, 2025

Add the capability and publishing for server time.

I also moved the websocket tests under the websocket module. Apart from feeling more natural, this also gives us the ability to access crate::websocket::protocol::server without making it more visible throughout the crate.

@gasmith gasmith self-assigned this Feb 5, 2025
Copy link

linear bot commented Feb 5, 2025

@gasmith gasmith force-pushed the gasmith/fg-9671-ws-time branch from 4978731 to 36c4005 Compare February 5, 2025 20:51
@gasmith gasmith requested review from eloff and bryfox February 5, 2025 20:55
@gasmith gasmith marked this pull request as ready for review February 5, 2025 20:55
Copy link
Contributor

@bryfox bryfox left a comment

Choose a reason for hiding this comment

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

I left a couple of questions, which might spur follow-up issues, but this looks good to me.

@jtbandes and @achim-k might have thoughts or opinions here.

@@ -431,6 +433,28 @@ impl Server {
}
}

/// Publish the current timestamp to all clients.
#[cfg(feature = "unstable")]
pub async fn broadcast_time(&self, timestamp_nanos: u64) {
Copy link
Contributor

Choose a reason for hiding this comment

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

We can shelve naming discussions until this moves to the stable API, but we don't necessarily need to follow the server interfaces from ws-protocol here. I like 'broadcast' but also think we should consider this alongside 'publish' parameter values (which may or may not broadcast).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah. I don't feel strongly about it. Maybe I'll develop stronger opinions as we fill in more of the interface. Consistency is nice.


let clients = self.clients.get();
for client in clients.iter() {
if let Err(err) = client.control_plane_tx.send_async(message.clone()).await {
Copy link
Contributor

Choose a reason for hiding this comment

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

control_plane_tx seems reasonable for a start, but this does make me wonder if these should be prioritized, and/or dealt with in some way such that we don't queue up multiple time messages.

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe debounce these? That seems to be coming up a lot lately as a future improvement

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Debouncing sounds reasonable, and prioritizing time messages ahead of other message types also seems reasonable, since queueing delays will be manifested as clock skew on the client side. I'm tempted to defer this until we have a better sense of the requirements for other message types.

@bryfox bryfox requested review from jtbandes and achim-k February 5, 2025 22:07
Copy link
Contributor

@eloff eloff left a comment

Choose a reason for hiding this comment

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

I guess this is just how the API works, but I'm surprised the end user had to call broadcast_time explicitly.

I would have expected the server itself maybe publishes the current time periodically.

I'm curious why it works this way.

What do you think of Bryan's recommendation for a name for the method?

The implementation looks good to me. I agree with the test reorganization.

@gasmith
Copy link
Contributor Author

gasmith commented Feb 6, 2025

I guess this is just how the API works, but I'm surprised the end user had to call broadcast_time explicitly.

I would have expected the server itself maybe publishes the current time periodically.

I'm curious why it works this way.

I thought about that too. The ws-protocol spec mention that this can be used to obtain "accelerated, slowed, or stepped control over the progress of time." Which sound a bit funkier than plain old clock synchronization.

We could provide a batteries-included helper for periodically broadcasting the wallclock time, if that would be useful. But I guess I'd like to learn more about how this interface is typically used before we do that.

@gasmith gasmith merged commit 17e8040 into main Feb 7, 2025
27 checks passed
@gasmith gasmith deleted the gasmith/fg-9671-ws-time branch February 7, 2025 15:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants