Opened 11 years ago

Closed 11 years ago

#4592 closed Bug (fixed)

Algorithm bug in bandwidth allocation

Reported by: Algorithmus Owned by: jordan
Priority: Normal Milestone: 2.50
Component: libtransmission Version: 2.42
Severity: Minor Keywords: backport-2.4x priority bandwidth peer turtle round robin random


I noticed that with torrents set to the same priority, with limited download bandwidth, only one or a few get most of the bandwidth. This is caused by an algorithm bug in bandwidth.c:phaseOne(). Starting at a random peer and moving linearly is well intentioned, but due to swapping peers that are done to the end of the array, only the first peer is random, and after that it's effectively a reverse traversal starting from the end. That is why the peers at the end of the array always get precedence. I confirmed this by monitoring the filtered debug output.

There are some ways to fix this, but none as clean as randomly selecting a new peer each time round the while loop. I'll attach a patch that effects this change, and saves four lines of code also. The overhead is minimal because rand() is computationally cheap. I confirmed that this patch does balance downloads more evenly at each priority level.

Attachments (1)

bandwidth.c.patch (1.5 KB) - added by Algorithmus 11 years ago.

Download all attachments as: .zip

Change History (3)

Changed 11 years ago by Algorithmus

comment:1 Changed 11 years ago by jordan

  • Status changed from new to assigned

Thanks for the patch!

comment:2 Changed 11 years ago by jordan

  • Keywords backport-2.4x added
  • Milestone changed from None Set to 2.50
  • Resolution set to fixed
  • Status changed from assigned to closed

Added in r13032.

Note: See TracTickets for help on using tickets.