-
Notifications
You must be signed in to change notification settings - Fork 44
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
try to optimize getting all controllers #1659
Draft
jreidinger
wants to merge
3
commits into
master
Choose a base branch
from
threaded_zfcp
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+92
−12
Draft
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 |
---|---|---|
|
@@ -34,8 +34,71 @@ use crate::{ | |
}, | ||
}; | ||
|
||
pub async fn get_wwpns(controller_id: &str) -> Result<Vec<String>, ServiceError> { | ||
let output = std::process::Command::new("zfcp_san_disc") | ||
.arg("-b") | ||
.arg(controller_id) | ||
.arg("-W") | ||
.output() | ||
.expect("zfcp_san_disc failed"); // TODO: real error handling | ||
Ok(String::from_utf8_lossy(&output.stdout) | ||
.split_whitespace() | ||
.map(|s| s.to_string()) | ||
.collect()) | ||
} | ||
|
||
pub async fn get_luns(controller_id: String, wwpn: String) -> Result<Vec<String>, ServiceError> { | ||
let output = std::process::Command::new("zfcp_san_disc") | ||
.arg("-b") | ||
.arg(controller_id) | ||
.arg("-p") | ||
.arg(wwpn) | ||
.arg("-L") | ||
.output() | ||
.expect("zfcp_san_disc failed"); // TODO: real error handling | ||
Ok(String::from_utf8_lossy(&output.stdout) | ||
.split_whitespace() | ||
.map(|s| s.to_string()) | ||
.collect()) | ||
} | ||
|
||
/// Obtains a LUNs map for the given controller | ||
/// | ||
/// Given a controller id it returns a HashMap with each of its WWPNs as keys and the list of | ||
/// LUNS corresponding to that specific WWPN as values. | ||
/// | ||
/// Arguments: | ||
/// | ||
/// `controller_id`: controller id | ||
pub async fn get_luns_map( | ||
controller_id: String, | ||
) -> Result<HashMap<String, Vec<String>>, ServiceError> { | ||
let wwpns = get_wwpns(controller_id.as_str()).await?; | ||
let mut tasks = vec![]; | ||
for wwpn in wwpns { | ||
tasks.push(( | ||
wwpn.clone(), | ||
tokio::spawn(get_luns(controller_id.to_string(), wwpn.clone())), | ||
)); | ||
} | ||
let mut result = HashMap::with_capacity(tasks.len()); | ||
for (wwpn, task) in tasks { | ||
result.insert(wwpn.clone(), task.await.expect("thread join failed")?); | ||
} | ||
Ok(result) | ||
} | ||
|
||
const ZFCP_CONTROLLER_PREFIX: &'static str = "/org/opensuse/Agama/Storage1/zfcp_controllers"; | ||
|
||
/// Partial zfcp controller data used for thread processing | ||
/// TODO: for final version move all those thread related methods to this struct to procude final result | ||
struct PartialZFCPController { | ||
pub id: String, | ||
pub channel: String, | ||
pub lun_scan: bool, | ||
pub active: bool | ||
} | ||
|
||
/// Client to connect to Agama's D-Bus API for zFCP management. | ||
#[derive(Clone)] | ||
pub struct ZFCPClient<'a> { | ||
|
@@ -99,23 +162,40 @@ impl<'a> ZFCPClient<'a> { | |
) -> Result<Vec<(OwnedObjectPath, ZFCPController)>, ServiceError> { | ||
let managed_objects = self.object_manager_proxy.get_managed_objects().await?; | ||
|
||
let mut devices: Vec<(OwnedObjectPath, ZFCPController)> = vec![]; | ||
let mut devices: Vec<(OwnedObjectPath, PartialZFCPController)> = vec![]; | ||
for (path, ifaces) in managed_objects { | ||
if let Some(properties) = ifaces.get("org.opensuse.Agama.Storage1.ZFCP.Controller") { | ||
let id = extract_id_from_path(&path)?.to_string(); | ||
let channel: String = get_property(properties, "Channel")?; | ||
devices.push(( | ||
path, | ||
ZFCPController { | ||
id: id.clone(), | ||
channel: get_property(properties, "Channel")?, | ||
PartialZFCPController { | ||
id: id, | ||
channel: channel, | ||
lun_scan: get_property(properties, "LUNScan")?, | ||
active: get_property(properties, "Active")?, | ||
luns_map: self.get_luns_map(id.as_str()).await?, | ||
}, | ||
)) | ||
} | ||
} | ||
Ok(devices) | ||
let mut tasks = vec![]; | ||
for (_path, partial_controller) in &devices { | ||
tasks.push( | ||
tokio::spawn(get_luns_map(partial_controller.channel.clone())) | ||
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. with this additional paralellization time is reduced to 5.3 seconds. So basically for two controllers with 3 LUNS in total it is gets to half of time. I expect that for bigger systems it will be even more significant. |
||
) | ||
} | ||
let mut result = Vec::with_capacity(devices.len()); | ||
for (index, task) in tasks.into_iter().enumerate() { | ||
let (path, partial) = devices.get(index).unwrap(); | ||
result.push((path.clone(), ZFCPController { | ||
id: partial.id.clone(), | ||
channel: partial.channel.clone(), | ||
lun_scan: partial.lun_scan, | ||
active: partial.active, | ||
luns_map: task.await.expect("thread join failed")?, | ||
})); | ||
} | ||
Ok(result) | ||
} | ||
|
||
async fn get_controller_proxy( | ||
|
@@ -129,12 +209,6 @@ impl<'a> ZFCPClient<'a> { | |
Ok(dbus) | ||
} | ||
|
||
pub async fn activate_controller(&self, controller_id: &str) -> Result<(), ServiceError> { | ||
let controller = self.get_controller_proxy(controller_id).await?; | ||
controller.activate().await?; | ||
Ok(()) | ||
} | ||
|
||
pub async fn get_wwpns(&self, controller_id: &str) -> Result<Vec<String>, ServiceError> { | ||
let controller = self.get_controller_proxy(controller_id).await?; | ||
let result = controller.get_wwpns().await?; | ||
|
@@ -176,6 +250,12 @@ impl<'a> ZFCPClient<'a> { | |
.collect::<Result<HashMap<String, Vec<String>>, _>>() | ||
} | ||
|
||
pub async fn activate_controller(&self, controller_id: &str) -> Result<(), ServiceError> { | ||
let controller = self.get_controller_proxy(controller_id).await?; | ||
controller.activate().await?; | ||
Ok(()) | ||
} | ||
|
||
pub async fn activate_disk( | ||
&self, | ||
controller_id: &str, | ||
|
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.
Instead of spawning all those processes, I would suggest giving join_all a try.
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.
Tokio has JoinSet, which might be interesting too.
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.
thanks for suggestion. I plan to have it as experiment first and this tokio spawn is suggested way in that linkedin rust training, so it is the first that I would like to give a try.
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.
and testing shows that my change somehow does not work, but as it is just learning/research project I will put it a bit on hold and focus on planned stuff and return to it probably next week.
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.
ok, I cannot sleep without debugging it...so now it is fixed and time is improved to 6.3 second..so already it goes down from 10.8 to 6.3 and I think it can be even better if I parallel also getting wwpns for controller. And then I can start playing with join_all and JoinSet