-
Notifications
You must be signed in to change notification settings - Fork 178
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
Update routes pre computation strategy to pre compute less routes #1717
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,11 +11,14 @@ | |
// Contributors: | ||
// ZettaScale Zenoh Team, <[email protected]> | ||
// | ||
use std::{collections::HashMap, sync::Arc}; | ||
|
||
#[zenoh_macros::unstable] | ||
use std::collections::HashMap; | ||
use std::sync::Arc; | ||
|
||
use zenoh_core::zread; | ||
use zenoh_protocol::{ | ||
core::{key_expr::keyexpr, Reliability, WhatAmI, WireExpr}, | ||
core::{key_expr::keyexpr, Reliability, WireExpr}, | ||
network::{ | ||
declare::{ext, SubscriberId}, | ||
Push, | ||
|
@@ -177,61 +180,24 @@ pub(crate) fn undeclare_subscription( | |
} | ||
} | ||
|
||
fn compute_data_routes_(tables: &Tables, routes: &mut DataRoutes, expr: &mut RoutingExpr) { | ||
let indexes = tables.hat_code.get_data_routes_entries(tables); | ||
|
||
let max_idx = indexes.routers.iter().max().unwrap(); | ||
routes | ||
.routers | ||
.resize_with((*max_idx as usize) + 1, || Arc::new(HashMap::new())); | ||
|
||
for idx in indexes.routers { | ||
routes.routers[idx as usize] = | ||
tables | ||
.hat_code | ||
.compute_data_route(tables, expr, idx, WhatAmI::Router); | ||
} | ||
|
||
let max_idx = indexes.peers.iter().max().unwrap(); | ||
routes | ||
.peers | ||
.resize_with((*max_idx as usize) + 1, || Arc::new(HashMap::new())); | ||
|
||
for idx in indexes.peers { | ||
routes.peers[idx as usize] = | ||
tables | ||
.hat_code | ||
.compute_data_route(tables, expr, idx, WhatAmI::Peer); | ||
} | ||
|
||
let max_idx = indexes.clients.iter().max().unwrap(); | ||
routes | ||
.clients | ||
.resize_with((*max_idx as usize) + 1, || Arc::new(HashMap::new())); | ||
|
||
for idx in indexes.clients { | ||
routes.clients[idx as usize] = | ||
tables | ||
.hat_code | ||
.compute_data_route(tables, expr, idx, WhatAmI::Client); | ||
} | ||
} | ||
|
||
pub(crate) fn compute_data_routes(tables: &Tables, expr: &mut RoutingExpr) -> DataRoutes { | ||
let mut routes = DataRoutes::default(); | ||
compute_data_routes_(tables, &mut routes, expr); | ||
tables | ||
.hat_code | ||
.compute_data_routes(tables, &mut routes, expr); | ||
routes | ||
} | ||
|
||
pub(crate) fn update_data_routes(tables: &Tables, res: &mut Arc<Resource>) { | ||
if res.context.is_some() { | ||
if res.context.is_some() && !res.expr().contains('*') && res.has_subs() { | ||
let mut res_mut = res.clone(); | ||
let res_mut = get_mut_unchecked(&mut res_mut); | ||
compute_data_routes_( | ||
tables.hat_code.compute_data_routes( | ||
tables, | ||
&mut res_mut.context_mut().data_routes, | ||
&mut RoutingExpr::new(res, ""), | ||
); | ||
res_mut.context_mut().valid_data_routes = true; | ||
} | ||
} | ||
|
||
|
@@ -249,11 +215,13 @@ pub(crate) fn compute_matches_data_routes<'a>( | |
) -> Vec<(Arc<Resource>, DataRoutes)> { | ||
let mut routes = vec![]; | ||
if res.context.is_some() { | ||
let mut expr = RoutingExpr::new(res, ""); | ||
routes.push((res.clone(), compute_data_routes(tables, &mut expr))); | ||
if !res.expr().contains('*') && res.has_subs() { | ||
let mut expr = RoutingExpr::new(res, ""); | ||
routes.push((res.clone(), compute_data_routes(tables, &mut expr))); | ||
} | ||
for match_ in &res.context().matches { | ||
let match_ = match_.upgrade().unwrap(); | ||
if !Arc::ptr_eq(&match_, res) { | ||
if !Arc::ptr_eq(&match_, res) && !match_.expr().contains('*') && match_.has_subs() { | ||
let mut expr = RoutingExpr::new(&match_, ""); | ||
let match_routes = compute_data_routes(tables, &mut expr); | ||
routes.push((match_, match_routes)); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
expr()
returns&str
, correct?If
expr()
would returnkeyexpr
you could usezenoh/commons/zenoh-keyexpr/src/key_expr/borrowed.rs
Line 133 in f90587b
and rely on the key-expr logic instead of using
contains()
everywhere. It's more a matter of concern encapsulation than anything else.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.
I fully agree. The problem is that:
So until we refactor the resource tree, it's far more efficient to do it like this.