-
-
Notifications
You must be signed in to change notification settings - Fork 297
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
Conversation
@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? |
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 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 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? |
By "state of the app" I mean the state of the UI. What you see on the screen. If you |
src/display/ui_state.rs
Outdated
@@ -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 { |
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.
this code is repeated 4 times, does it make sense to refactor it to split the averaging logic from the access to the field?
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.
make sense, let me refactor that
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. |
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? |
Sure. Let's see how it behaves and play around with it until it feels good. |
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. |
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 :) ) |
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.
Cool! I like this! Just 1 knitpick
src/display/ui_state.rs
Outdated
} | ||
|
||
#[derive(Default)] | ||
pub struct NetworkData { | ||
pub total_bytes_downloaded: u128, | ||
pub total_bytes_uploaded: u128, | ||
pub prev_total_bytes_downloaded: u128, |
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.
Now these fields are not used anymore, perhaps we should remove them?
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.
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 :)
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 |
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. |
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 weight0.25
, etc.This change should smoothen the be bandwidth curve somewhat, while giving recent bandwidth data more weight.