-
Notifications
You must be signed in to change notification settings - Fork 286
feat(hermes): add latency histograms for SSE/WS send paths #2977
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
feat(hermes): add latency histograms for SSE/WS send paths #2977
Conversation
Co-Authored-By: Tejas Badadare <[email protected]>
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Co-Authored-By: Tejas Badadare <[email protected]>
apps/hermes/server/src/api/ws.rs
Outdated
if let Some(received_at) = received_at_opt { | ||
let pub_to_recv = (received_at - publish_time).max(0) as f64; | ||
self.ws_state | ||
.metrics | ||
.publish_to_receive_latency | ||
.observe(pub_to_recv); | ||
|
||
let now_secs = std::time::SystemTime::now() | ||
.duration_since(std::time::UNIX_EPOCH) | ||
.ok() | ||
.and_then(|d| i64::try_from(d.as_secs()).ok()) | ||
.unwrap_or(received_at); | ||
let recv_to_send = (now_secs - received_at).max(0) as f64; | ||
self.ws_state | ||
.metrics | ||
.receive_to_ws_send_latency | ||
.observe(recv_to_send); | ||
} | ||
|
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.
This is in the wrong place, we should observe the latency after self.sender.flush()
…after flush Co-Authored-By: Tejas Badadare <[email protected]>
Summary
Adds three new histogram metrics to the Hermes service to track latency in price feed updates:
publish_to_receive_latency
: Time frompublish_time
toreceive_time
(tracked for both SSE and WS)receive_to_ws_send_latency
: Time fromreceive_time
to WebSocket send timereceive_to_sse_send_latency
: Time fromreceive_time
to SSE send timeRationale
These metrics provide visibility into latency at different stages of the price feed pipeline, enabling monitoring and optimization of the Hermes service performance. The metrics help identify bottlenecks between price publication, reception, and delivery to clients.
Implementation Details
WsMetrics
struct to includepublish_to_receive_latency
andreceive_to_ws_send_latency
histogramsSseMetrics
struct withreceive_to_sse_send_latency
histogramApiState
to include SSE metricsArchitecture Notes
The
publish_to_receive_latency
metric is registered inWsMetrics
but observed by both endpoints. SSE accesses it viastate.ws.metrics.publish_to_receive_latency
to avoid duplicate registration.How has this been tested?
cargo build
)Testing performed: Verified compilation success with
cargo build
. No runtime testing of metrics collection was performed.Review Checklist
Please pay special attention to:
Metrics architecture: Is the cross-endpoint access pattern (
SSE -> WS metrics
) acceptable or shouldpublish_to_receive_latency
be registered differently?Timing accuracy: Are the wall-clock measurements using
SystemTime::now()
appropriate for latency tracking in hot paths?Performance impact: Review the overhead of adding histogram observations to every price update in both WS and SSE paths
Borrow checker solutions: Verify the approach of capturing
received_at
andpublish_time
before movingupdate
structs is soundHistogram buckets: Validate that the 0.1-20.0 second range with the chosen bucket distribution makes sense for expected latencies
Link to Devin run: https://app.devin.ai/sessions/e9af526709c3456c8bd160207b8ec67a
Requested by: Tejas Badadare ([email protected])