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

per torrent ratio and up/down do not match #7817

Closed
Dmole opened this issue Jan 13, 2024 · 4 comments · Fixed by #7853
Closed

per torrent ratio and up/down do not match #7817

Dmole opened this issue Jan 13, 2024 · 4 comments · Fixed by #7853
Assignees

Comments

@Dmole
Copy link
Contributor

Dmole commented Jan 13, 2024

Describe the bug
per torrent ratio and up/down do not match

To Reproduce

  1. download a torrent
  2. restart part way through

Current behavior
total ratio is shown with session up / down

Expected behavior
total ratio should be shown with total up / down

Screenshots

wut(1)

@qstokkink
Copy link
Contributor

For debugging, a breakdown of these numbers:

What is shown:

up = format_size(self.current_download['total_up'])
down = format_size(self.current_download['total_down'])
self.window().download_detail_ratio_label.setText(
f"{self.current_download['ratio']:.3f}, up: {up}, down: {down}"
)

Where it comes from:

"total_up": state.get_total_transferred(UPLOAD),
"total_down": state.get_total_transferred(DOWNLOAD),
"ratio": state.get_seeding_ratio(),

How it's implemented:

def get_total_transferred(self, direct):
"""
Returns the total amount of up or downloaded bytes.
@return The amount in bytes.
"""
if not self.lt_status:
return 0
elif direct == UPLOAD:
return self.lt_status.total_upload
return self.lt_status.total_download
def get_seeding_ratio(self):
if self.lt_status and self.lt_status.total_done > 0:
return self.lt_status.all_time_upload / float(self.lt_status.total_done)
return 0

The core of the inconsistency seems to be that the shown ratio is all_time_upload / total_done and the expected ratio (based on the reported "up" and "down") is total_upload / total_download.

@drew2a drew2a self-assigned this Jan 25, 2024
@drew2a drew2a added this to the 7.14.0 milestone Jan 25, 2024
@kozlovsky
Copy link
Contributor

kozlovsky commented Jan 26, 2024

After some investigation, I need to say that the previous formula all_time_upload / total_done is close to the correct answer and is an expected way to calculate the ratio.

For each torrent session, we have:

  • total_upload, total_download - the number of bytes downloaded and uploaded to all peers, accumulated, this session only. The session restarts when a torrent is paused and restarted again. When a torrent is paused, these counters are reset to 0.
  • total_payload_download, total_payload_upload - the number of bytes sent and received this session, but only the actual payload data, ignoring any protocol overhead. When a torrent is paused, these counters are reset to 0.
  • all_time_upload and all_time_download - are accumulated byte counters; they are saved in and restored from resume data to keep totals across sessions.
  • total_done - the total number of bytes of the file(s) that we have. All this does not necessarily have to be downloaded during this session.

The ratio value is commonly considered as (uploaded / downloaded), where the exact meaning of "uploaded" and "downloaded" can differ slightly depending on a specific corner case and a specific torrent client.

  • When a user pauses and restarts a torrent several times, he still expects the ratio to be calculated over all session restarts, so total_upload and total_download are unsuitable.
  • all_time_upload and all_time_download suits better, but we should not include protocol overhead and rejected blocks that failed integrity checks in the total download. Using all_time_download could potentially inflate the download portion of the ratio if some torrent pieces were downloaded multiple times due to errors or incomplete transfers. Therefore, total_done is the most suitable counter for the ratio calculation.

But I agree that the calculated ratio does not match with the up / down counters because counters currently only display the data for the current session (after the torrent was unpaused). To fix it, we should also display the total number of uploaded/downloaded bytes.

So, the torrent statistics can be displayed as:

Ratio: 0.1, up: 1 MB (total 100 MB), down: 2 MB (total 1 GB)

This should remove user confusion, as the ratio is calculated for totals that will be displayed now.

There is a corner case that is not correctly handled by the current formula: when a user seeds a pre-downloaded torrent, and the total_done counter is 0, the ratio is calculated as 0. It should be ♾ or "MAX" instead because 0 has the opposite meaning for the ratio.

@Dmole
Copy link
Contributor Author

Dmole commented Jan 26, 2024

I think it would make most sense to display just the all-time ratio/numbers but if both are to be shown then separate them like this:

Ratio: 0.1, up: 100 MB, down: 1 GB (Session Ratio: 0.5, up: 1 MB, down: 2 MB)

@synctext
Copy link
Member

All time ratio is defined as total from, say, 10 Tribler sessions. The original if report was (possibly) simply that all counters reset when restarting Tribler.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging a pull request may close this issue.

5 participants