Skip to content

Conversation

mfuntowicz
Copy link
Member

No description provided.

@@ -112,6 +136,10 @@ impl Backend for BackendV3 {
.is_ok()
}

fn events(&self) -> BroadcastReceiver<EngineState> {
self.state_events.0.subscribe()
Copy link
Collaborator

Choose a reason for hiding this comment

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

You should send the current state as soon as a new connection is open (new subscribe)

let stream = infer.events();
let sse =
Sse::new(BroadcastStream::from(stream).map(|state| {
Event::default().json_data(state.map_err(|err| axum::Error::new(err))?)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Name of the event ?

Comment on lines +155 to +172
// Dispatch new state to the proxy
{
// Lock free operation (read)
let num_queued_tokens = engine_state.read().await.in_queue;
{
// Critical section, doing as little as possible here
let mut engine_state = engine_state.write().await;
engine_state.in_queue = num_queued_tokens + entry_num_tokens;
}

// Send new state to the channel for broadcasting
if let Err(err) = queue_events.send(*engine_state.read().await) {
tracing::warn!(
"Failed to send BatchEvent::QueueChanged({}): {err}",
num_queued_tokens + entry_num_tokens
)
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
// Dispatch new state to the proxy
{
// Lock free operation (read)
let num_queued_tokens = engine_state.read().await.in_queue;
{
// Critical section, doing as little as possible here
let mut engine_state = engine_state.write().await;
engine_state.in_queue = num_queued_tokens + entry_num_tokens;
}
// Send new state to the channel for broadcasting
if let Err(err) = queue_events.send(*engine_state.read().await) {
tracing::warn!(
"Failed to send BatchEvent::QueueChanged({}): {err}",
num_queued_tokens + entry_num_tokens
)
}
}
engine_state.modify(|state| state.in_queue += entry_num_tokens);

Function modify then send the new state in the SSE

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