Skip to content
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: show loading progress #197

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

hunjixin
Copy link
Contributor

Resolves #133. change spinner to progressbar.

image

Copy link
Member

@nazar-pc nazar-pc left a comment

Choose a reason for hiding this comment

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

This is a good start, thanks!
Left some suggestions on how to improve it further.

src/backend.rs Outdated Show resolved Hide resolved
src/backend.rs Outdated Show resolved Hide resolved
src/backend.rs Outdated Show resolved Hide resolved
src/backend.rs Outdated
Comment on lines 185 to 214
match self {
LoadingStep::LoadingConfiguration => 0.0,
LoadingStep::ReadingConfiguration => 5.0,
LoadingStep::ConfigurationReadSuccessfully {
configuration_exists: _,
} => 10.0,
LoadingStep::CheckingConfiguration => 15.0,
LoadingStep::ConfigurationIsValid => 20.0,
LoadingStep::DecodingChainSpecification => 25.0,
LoadingStep::DecodedChainSpecificationSuccessfully => 30.0,
LoadingStep::CheckingNodePath => 35.0,
LoadingStep::CreatingNodePath => 40.0,
LoadingStep::NodePathReady => 45.0,
LoadingStep::PreparingNetworkingStack => 50.0,
LoadingStep::ReadingNetworkKeypair => 55.0,
LoadingStep::GeneratingNetworkKeypair => 60.0,
LoadingStep::WritingNetworkKeypair => 65.0,
LoadingStep::InstantiatingNetworkingStack => 70.0,
LoadingStep::NetworkingStackCreatedSuccessfully => 75.0,
LoadingStep::CreatingConsensusNode => 85.0,
LoadingStep::ConsensusNodeCreatedSuccessfully => 90.0,
LoadingStep::CreatingFarmer => 95.0,
LoadingStep::FarmerCreatedSuccessfully => 100.0,
LoadingStep::WipingFarm {
farm_index: _,
path: _,
} => 0.0,
LoadingStep::WipingFarmSuccessfully => 50.0,
LoadingStep::WipingNode { path: _ } => 80.0,
LoadingStep::WipingNodeSuccessfully => 100.0,
Copy link
Member

Choose a reason for hiding this comment

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

Naively you'd think this would work, but it is far from accurate. Different steps take different amount of time and thus progress with fixed 5% between steps is not accurate.

Also it doesn't account for the fact that there could be multiple steps in node creation and it definitely doesn't account for how many farms there are. If you have one farm and 20 it will take vastly different amount of time to complete that step. I see that you take that into consideration below, but it is still 5% for all farms in total.

This is why #133 says to do estimation first and scale everything accordingly to show realistic progress.

src/frontend/loading.rs Outdated Show resolved Hide resolved
src/frontend/loading.rs Outdated Show resolved Hide resolved
Comment on lines 32 to 43
gtk::ProgressBar {
#[watch]
set_fraction: model.progress,
set_show_text: true,
},
Copy link
Member

Choose a reason for hiding this comment

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

I may have not been super clear, but the goal wasn't necessarily to remove the spinner.

While it is probably fine to do the way you did it, I was thinking about high-level steps shown with spinner and detailed steps below progress bar.

High level step would be "Creating farmer" and low-level would be creation and benchmarking of individual farms under that farmer.

Like title and subtitle if it makes sense.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

at first i want to implement a spinner like this
image
GTK does not have native support.

and i am not think its a better idea to use title and subtitle. Implementing a complex solution may not provide much greater help. I think using a progress bar is more suitable, implementing a spinner with a similar effect as shown above could work as well. this will more friendly for both small farm and big farm.

for a more accurate for each farm, maybe need move LoadingStep type to backend, or add a notify in backend/farmer.rs file. but benchmarking need more deep change in farmer.

Copy link
Member

Choose a reason for hiding this comment

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

That is too complex for this purpose, not worth it.

I think simply adding title with main step above progress bar and making text below progress bar describing smaller inner steps will be sufficient.

For benchmarking we will indeed have to modify a farmer since it doesn't expose that information at the moment.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

image
is this your meaning.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, exactly!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

simple set consensus node 20%, all farm occupy 60%, others occupy 20%. if need more accurate, maybe others nearly nothing, consensus node and all farm split 100% equaly (100%/(farmer_len+1).

image

Copy link
Member

Choose a reason for hiding this comment

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

Makes sense overall, though more farms does mean we will spend more time there, so if node fraction is decreased proportionally it'll make things more realistic, but I'm fine with it either way for initial version.

src/main.rs Outdated Show resolved Hide resolved
@hunjixin hunjixin marked this pull request as draft May 24, 2024 03:20
@hunjixin hunjixin marked this pull request as ready for review May 30, 2024 12:54
Copy link
Member

@nazar-pc nazar-pc left a comment

Choose a reason for hiding this comment

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

Thanks for making progress here and feel free to re-request review, there is a button on GitHub for this so I get a notification when you think PR is ready for review

@@ -201,6 +226,7 @@ pub enum BackendNotification {
#[allow(dead_code)]
Copy link
Member

Choose a reason for hiding this comment

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

This and above TODO should be removed by this PR

}
LoadingStep::DecodedChainSpecificationSuccessfully => {
"Decoded chain specification successfully".to_string()
"Decoding chain specification".to_string()
Copy link
Member

Choose a reason for hiding this comment

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

This change needs to be reverted

- LoadingStep::FarmerCreatedSuccessfully.percentage())
/ (disk_farms.len() as f32);

let notifications = Arc::new(farmer::Notifications::default());
Copy link
Member

Choose a reason for hiding this comment

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

Please don't do this, this is not not notifications are supposed to work. There are already subscriptions for existing notifications, just follow that pattern instead of breaking abstractions.

@@ -616,7 +642,8 @@ async fn load_configuration(
notifications_sender
.send(BackendNotification::Loading {
step: LoadingStep::LoadingConfiguration,
progress: 0.0,
progress: LoadingStep::LoadingConfiguration.percentage(),
message: "loading configuration ...".to_string(),
Copy link
Member

Choose a reason for hiding this comment

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

I see all of these messages were copied from another file, but why did you remove capitalization everywhere?:

Suggested change
message: "loading configuration ...".to_string(),
message: "Loading configuration ...".to_string(),

WipingNode {
path: PathBuf,
},
WipingFarm,
Copy link
Member

Choose a reason for hiding this comment

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

I don't think it is the right change to remove properties from this enum variant. In fact I think more variants should have more properties here!
Instead of sending message to the frontend, you should send LoadingStep such that there is enough information for frontend to render the message (kind of like it was before). Backend should not be responsible to rendering user-facing messages for frontend, there is a separation of responsibilities here.

step should contain all the information necessary. Moreover, since you have decided to add percentage as a field on this enum, progress field is not necessary either, step.progress() can be called by UI to render progress accordingly.

@@ -668,10 +668,18 @@ impl App {
fn process_backend_notification(&mut self, notification: BackendNotification) {
match notification {
// TODO: Render progress
Copy link
Member

Choose a reason for hiding this comment

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

Again, once you implement rendering of progress, remove corresponding TODOs

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.

[$100 USDC] Implement loading progress
2 participants