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

Display weighted average of bandwidth #77

Merged
merged 5 commits into from
Jan 12, 2020
Merged

Display weighted average of bandwidth #77

merged 5 commits into from
Jan 12, 2020

Conversation

zhangxp1998
Copy link
Collaborator

The idea of exponential decay is used. When displaying bandwidth, it takes an weighted average of all bandwidth in the past. The bandwidth of last 1 second gets weight 0.5, the bandwidth of last 2 seconds gets weight 0.25, etc.

This change should smoothen the be bandwidth curve somewhat, while giving recent bandwidth data more weight.

@zhangxp1998 zhangxp1998 requested a review from imsnif January 5, 2020 20:19
@zhangxp1998
Copy link
Collaborator Author

@imsnif Looks like some UI tests have failed, possibly because I changed UI. But I'm not sure how to interpret the snapshots. Would you give some guidance?

@imsnif
Copy link
Owner

imsnif commented Jan 5, 2020

Sure - happy to see you're picking this up. I like the direction this is going. Fair warning, it might take me a few days to give this a thorough review. Meanwhile so you're not stuck though:

The tests use insta in order to perform snapshot testing: https://github.com/mitsuhiko/insta
If you run them locally, they will compare the state of the app in various situations against pre-recorded snapshots. If the comparison fails, they will create temporary files with the snapshots they received. If you override the existing snapshots with these files, the tests will pass.

You can automate this process and make reviews easier if you use insta to review. You need to install it locally and then you'd be able to cargo insta review and see the diff.

Here, I imagine the difference would mostly be in the bandwidth values, as their calculation has now changed.

I would also like to add tests that specifically test the new bandwidth calculation (eg. run traffic for longer and see that the calculation is correct).

Makes sense?

@imsnif
Copy link
Owner

imsnif commented Jan 5, 2020

By "state of the app" I mean the state of the UI. What you see on the screen. If you cat the first snapshot of a test, you'll see the initial UI. The snapshot after it will be the changes to the screen at each update interval (1s currently).

@@ -30,6 +39,24 @@ impl Bandwidth for ConnectionData {
fn get_total_bytes_downloaded(&self) -> u128 {
self.total_bytes_downloaded
}
fn get_avg_bytes_uploaded(&self) -> u128 {
Copy link
Contributor

Choose a reason for hiding this comment

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

this code is repeated 4 times, does it make sense to refactor it to split the averaging logic from the access to the field?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

make sense, let me refactor that

@imsnif
Copy link
Owner

imsnif commented Jan 6, 2020

Hey @zhangxp1998 - this is great!

Before going into the implementation, I'd like to first play around with the behaviour.

Currently, the information on the UI still flickers in and out without a lot of chance at reading it unless it's a sustained connection.

Looking (admittedly very briefly!) through the code, we seem to be saving just 1 state back, is that correct? Do you think we can make it save an arbitrary amount of states back? Like, try for 10, see if the UI feels better and play with it from there?

@zhangxp1998
Copy link
Collaborator Author

Hey @zhangxp1998 - this is great!

Before going into the implementation, I'd like to first play around with the behaviour.

Currently, the information on the UI still flickers in and out without a lot of chance at reading it unless it's a sustained connection.

Looking (admittedly very briefly!) through the code, we seem to be saving just 1 state back, is that correct? Do you think we can make it save an arbitrary amount of states back? Like, try for 10, see if the UI feels better and play with it from there?

Yes I'm only tracking 1 state back. But that state contain information about traffic from beginning of time(exponential decaying weight). So it's different from just averaging 2 seconds of traffic.

@imsnif
Copy link
Owner

imsnif commented Jan 6, 2020

Yes I'm only tracking 1 state back. But that state contain information about traffic from beginning of time(exponential decaying weight). So it's different from just averaging 2 seconds of traffic.

Ah, cool. I think it would be great if the connections appear on the screen longer.

As in, if we're keeping info about 10 states back, that if sometime during those 10 seconds we had traffic, it would appear on screen. What do you say?

@zhangxp1998
Copy link
Collaborator Author

Yes I'm only tracking 1 state back. But that state contain information about traffic from beginning of time(exponential decaying weight). So it's different from just averaging 2 seconds of traffic.

Ah, cool. I think it would be great if the connections appear on the screen longer.

As in, if we're keeping info about 10 states back, that if sometime during those 10 seconds we had traffic, it would appear on screen. What do you say?

I think it's a good idea. 10 maybe too long though, maybe make it 3-5?

@imsnif
Copy link
Owner

imsnif commented Jan 6, 2020

Sure. Let's see how it behaves and play around with it until it feels good.

@zhangxp1998
Copy link
Collaborator Author

This PR and PR82 probably conflicts with each other... Which one should we work on first?

@imsnif
Copy link
Owner

imsnif commented Jan 7, 2020

This PR and PR82 probably conflicts with each other... Which one should we work on first?

This one. I'm sure we can handle the merge once it's done.

@imsnif
Copy link
Owner

imsnif commented Jan 12, 2020

Hey @zhangxp1998 - I pushed a commit with a suggestion for storing the previous states and displaying their average in the UI. I didn't factor in the bandwidth decay - was hoping you could include it, because I think you had a specific vision for it and I liked your direction.

If you run this branch, you'll see that the tool is much less erratic, and IMO displays the bandwidth in a more comfortable and less "blinky" way than what's currently on master. We could also play around with the RECALL_LENGTH as we discussed above. Would love to hear your thoughts.

(if you don't like this direction, feel free to revert my commit... tbh, I just felt like coding and wanted to lend a hand to this feature :) )

Copy link
Collaborator Author

@zhangxp1998 zhangxp1998 left a comment

Choose a reason for hiding this comment

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

Cool! I like this! Just 1 knitpick

}

#[derive(Default)]
pub struct NetworkData {
pub total_bytes_downloaded: u128,
pub total_bytes_uploaded: u128,
pub prev_total_bytes_downloaded: u128,
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Now these fields are not used anymore, perhaps we should remove them?

Copy link
Owner

Choose a reason for hiding this comment

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

Ah yeah - for sure. Didn't want to cause too much of a mess in case you were in the middle of something.

I saw you've removed this already though, so thanks :)

@imsnif
Copy link
Owner

imsnif commented Jan 12, 2020

I don't mind fixing all the tests so this can pass - but wanted to know if you'd like to incorporate the bandwidth decay before? I'm also happy with going ahead like this and adding the bandwidth decay later if we want to - what do you think?

@zhangxp1998
Copy link
Collaborator Author

I don't mind fixing all the tests so this can pass - but wanted to know if you'd like to incorporate the bandwidth decay before? I'm also happy with going ahead like this and adding the bandwidth decay later if we want to - what do you think?

I couldn't think of any way to incorporate bandwidth decay into this easily. So let's add that later

@zhangxp1998
Copy link
Collaborator Author

The computed bandwidth seems incorrect: When a process engages in a burst of traffic, the displayed bandwidth will be much smaller than the instantaneous bandwidth. Is this okay though...

@imsnif
Copy link
Owner

imsnif commented Jan 12, 2020

The computed bandwidth seems incorrect: When a process engages in a burst of traffic, the displayed bandwidth will be much smaller than the instantaneous bandwidth. Is this okay though...

Yeah, this is the trade-off. We will now show the average of the last 5 seconds. If the burst lasts less than that, we'll swallow it. Do you feel this hurts the functionality too much?

@zhangxp1998
Copy link
Collaborator Author

The computed bandwidth seems incorrect: When a process engages in a burst of traffic, the displayed bandwidth will be much smaller than the instantaneous bandwidth. Is this okay though...

Yeah, this is the trade-off. We will now show the average of the last 5 seconds. If the burst lasts less than that, we'll swallow it. Do you feel this hurts the functionality too much?

I think this is a reasonable trade off, but we should probably document this somewhere to not confuse ourselves/users in the future.

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.

3 participants