-
Notifications
You must be signed in to change notification settings - Fork 66
apollo_network_benchmark: add ReveresedSqmrSender struct and implementation #11554
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
base: 01-08-apollo_network_benchmark_add_reveresedsqmr_variant_to_networkprotocol_enum
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,7 +14,7 @@ use apollo_network_benchmark::node_args::NetworkProtocol; | |
| use futures::StreamExt; | ||
| use libp2p::gossipsub::{Sha256Topic, Topic}; | ||
| use libp2p::PeerId; | ||
| use tracing::error; | ||
| use tracing::{error, info, trace}; | ||
|
|
||
| // ================================ | ||
| // Types and Constants | ||
|
|
@@ -77,6 +77,48 @@ pub fn register_protocol_channels( | |
| pub enum MessageSender { | ||
| Gossipsub(BroadcastTopicClient<TopicType>), | ||
| Sqmr(SqmrClientSender<TopicType, TopicType>), | ||
| ReveresedSqmr(ReveresedSqmrSender), | ||
| } | ||
|
|
||
| /// Wrapper for ReveresedSqmr that maintains the last active query | ||
| pub struct ReveresedSqmrSender { | ||
| server: SqmrServerReceiver<TopicType, TopicType>, | ||
| active_query: Option<apollo_network::network_manager::ServerQueryManager<TopicType, TopicType>>, | ||
| } | ||
|
|
||
| impl ReveresedSqmrSender { | ||
| pub fn new(server: SqmrServerReceiver<TopicType, TopicType>) -> Self { | ||
| Self { server, active_query: None } | ||
| } | ||
|
|
||
| async fn collect_new_queries(&mut self) { | ||
| // Non-blocking check for new queries, keeping only the last one | ||
| while let Ok(query) = | ||
| tokio::time::timeout(tokio::time::Duration::from_millis(1), self.server.next()).await | ||
| { | ||
| if let Some(query) = query { | ||
| info!("ReveresedSqmr: Received new query, replacing previous query"); | ||
| self.active_query = Some(query); | ||
| } else { | ||
| break; | ||
| } | ||
| } | ||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 1ms timeout per send inflates benchmark latency metricsMedium Severity
|
||
|
|
||
| async fn broadcast_to_queries(&mut self, message: TopicType) { | ||
| if let Some(query) = &mut self.active_query { | ||
| match query.send_response(message).await { | ||
| Ok(()) => { | ||
| trace!("ReveresedSqmr: Sent response to active query"); | ||
| } | ||
| Err(e) => { | ||
| // Query failed, remove it | ||
| error!("ReveresedSqmr: Active query failed, removing it, error: {:?}", e); | ||
| self.active_query = None; | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Silent message drop when no active query existsMedium Severity
|
||
| } | ||
|
|
||
| impl MessageSender { | ||
|
|
@@ -95,6 +137,12 @@ impl MessageSender { | |
| error!("Failed to send SQMR query: {:?}", e); | ||
| } | ||
| }, | ||
| MessageSender::ReveresedSqmr(sender) => { | ||
| // Collect any new queries first | ||
| sender.collect_new_queries().await; | ||
| // Then broadcast the message to all active queries | ||
| sender.broadcast_to_queries(message).await; | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||


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.
Only one query stored despite broadcast-to-all intent
Medium Severity
collect_new_queriesreplacesactive_queryeach iteration, so only the most recent query is retained and all prior queries are silently dropped. The comment on line 143 says "broadcast the message to all active queries," and the method is namedbroadcast_to_queries(plural), but the struct only holds a singleOption— meaning in a multi-receiver benchmark scenario, only the last peer to connect actually receives data. If broadcasting to all connected peers is intended,active_queryneeds to be a collection.Additional Locations (1)
crates/apollo_network_benchmark/src/bin/broadcast_network_stress_test_node/protocol.rs#L139-L145