Closed
Conversation
robgjansen
requested changes
Mar 6, 2023
Member
robgjansen
left a comment
There was a problem hiding this comment.
Found a bug while looking so am posting now so I don't forget during regular review.
Comment on lines
+139
to
+157
| for relay in relays.values(): | ||
| for fingerprint in relay.fingerprints: | ||
| cluster_bandwidths = [] | ||
| bandwidth = bandwidths.get(fingerprint) | ||
| if bandwidth is not None: | ||
| cluster_bandwidths.append({ | ||
| 'bandwidth_capacity': int(bandwidth.max_obs_bw), | ||
| 'bandwidth_rate': int(median(bandwidth.bw_rates)) if len(bandwidth.bw_rates) > 0 else 0, | ||
| 'bandwidth_burst': int(median(bandwidth.bw_bursts)) if len(bandwidth.bw_bursts) > 0 else 0, | ||
| }) | ||
| if len(cluster_bandwidths) > 0: | ||
| relay.bandwidth_capacity = max(b['bandwidth_capacity'] for b in cluster_bandwidths) | ||
| relay.bandwidth_rate = max(b['bandwidth_rate'] for b in cluster_bandwidths) | ||
| relay.bandwidth_burst = max(b['bandwidth_burst'] for b in cluster_bandwidths) | ||
| found_bandwidths += 1 | ||
| else: | ||
| relay.bandwidth_capacity = 0 | ||
| relay.bandwidth_rate = 0 | ||
| relay.bandwidth_burst = 0 |
Member
There was a problem hiding this comment.
This looks wrong to me, because we reset the cluster bandwidths list as we iterate items in the cluster. The "cluster representative relay" will always get the bandwidth info of the last iterated relay in the cluster, rather than computing the bandwidth as the max over all relays in the cluster.
I think we want this instead:
diff --git a/tornettools/stage.py b/tornettools/stage.py
index e11fe3c..298cdb1 100644
--- a/tornettools/stage.py
+++ b/tornettools/stage.py
@@ -136,9 +136,11 @@ def stage_relays(args):
bandwidths = bandwidths_from_serverdescs(serverdescs)
found_bandwidths = 0
+ # each 'relay' may actually be many relays clustered into one
for relay in relays.values():
+ # first we want to collect all bandwidth info we have from everyone in the cluster
+ cluster_bandwidths = []
for fingerprint in relay.fingerprints:
- cluster_bandwidths = []
bandwidth = bandwidths.get(fingerprint)
if bandwidth is not None:
cluster_bandwidths.append({
@@ -146,15 +148,16 @@ def stage_relays(args):
'bandwidth_rate': int(median(bandwidth.bw_rates)) if len(bandwidth.bw_rates) > 0 else 0,
'bandwidth_burst': int(median(bandwidth.bw_bursts)) if len(bandwidth.bw_bursts) > 0 else 0,
})
- if len(cluster_bandwidths) > 0:
- relay.bandwidth_capacity = max(b['bandwidth_capacity'] for b in cluster_bandwidths)
- relay.bandwidth_rate = max(b['bandwidth_rate'] for b in cluster_bandwidths)
- relay.bandwidth_burst = max(b['bandwidth_burst'] for b in cluster_bandwidths)
- found_bandwidths += 1
- else:
- relay.bandwidth_capacity = 0
- relay.bandwidth_rate = 0
- relay.bandwidth_burst = 0
+ # now flatten the bandwidth info for the cluster down into a single bandwidth for the cluster representative
+ if len(cluster_bandwidths) > 0:
+ relay.bandwidth_capacity = max(b['bandwidth_capacity'] for b in cluster_bandwidths)
+ relay.bandwidth_rate = max(b['bandwidth_rate'] for b in cluster_bandwidths)
+ relay.bandwidth_burst = max(b['bandwidth_burst'] for b in cluster_bandwidths)
+ found_bandwidths += 1
+ else:
+ relay.bandwidth_capacity = 0
+ relay.bandwidth_rate = 0
+ relay.bandwidth_burst = 0
logging.info("We found bandwidth information for {} of {} relays".format(found_bandwidths, len(relays)))
# for (k, v) in sorted(relays.items(), key=lambda kv: kv[1].bandwidths.max_obs_bw):
Member
|
Pushed fix, and experiments with the fixed version: |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
An updated version of #84. Keeping the former around for the moment for reference, but this one is rebased on the current tornettools head, and changed to cluster /8's instead of /16's.