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

fix(ui-state): do not overcalculate bandwidth and connections #114

Merged
merged 3 commits into from
Jan 14, 2020

Conversation

imsnif
Copy link
Owner

@imsnif imsnif commented Jan 13, 2020

So, yesterday I broke master with this: #77

What that PR essentially does is save a cache of the last 5 states and then display their average bandwidth.

I forgot to take the total bandwidth into account, so until this PR master shows ~5 times as much total bandwidth as there actually is.

I also forgot to take the connection count into account, and so in master the connections were counted once for every state.

The total bandwidth calculation was a fairly straightforward fix: just divide it by the amount of cached states like we do with the rest of the bandwidth.

With the connection count, dividing would not do since we don't want a connection average of the past N seconds, but an exact count (of the past N seconds). I did this here by only counting a connection the first time we see it.

So, umm... oops. :)

Copy link
Collaborator

@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.

👍 Good work, the code can be simplified just a little bit

for state in self.utilization_data.iter().rev() {
let connections_to_procs = &state.connections_to_procs;
let network_utilization = &state.network_utilization;
for (connection, connection_info) in &network_utilization.connections {
let connection_previously_seen = seen_connections.contains(connection);
Copy link
Collaborator

Choose a reason for hiding this comment

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

This can be replaced with

let connection_previously_seen = !seen_connections.insert(connection);

And the insert statement at the bottom can be removed.

Copy link
Owner Author

Choose a reason for hiding this comment

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

Ah, right! Thanks for this :)

Copy link
Collaborator

@ebroto ebroto left a comment

Choose a reason for hiding this comment

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

LGTM! Just marking as "needs work" to take into account @zhangxp1998 suggestion

src/display/ui_state.rs Outdated Show resolved Hide resolved
@imsnif imsnif merged commit 0edc6c2 into master Jan 14, 2020
@imsnif imsnif deleted the fix-ui-state branch September 13, 2020 16:28
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.

None yet

3 participants