mirror of
https://github.com/transmission/transmission
synced 2024-12-25 09:13:06 +00:00
a few attempts to reduce the "router death" load: lower the total number of connections made per second. increase the intervals for reconnecting to some peers. simplify the code a bit.
This commit is contained in:
parent
94ac86bec6
commit
52efe10ec5
1 changed files with 22 additions and 12 deletions
|
@ -56,11 +56,11 @@ enum
|
|||
RECONNECT_PERIOD_MSEC = (2 * 1000),
|
||||
|
||||
/* max # of peers to ask fer per torrent per reconnect pulse */
|
||||
MAX_RECONNECTIONS_PER_PULSE = 4,
|
||||
MAX_RECONNECTIONS_PER_PULSE = 2,
|
||||
|
||||
/* max number of peers to ask for per second overall.
|
||||
* this throttle is to avoid overloading the router */
|
||||
MAX_CONNECTIONS_PER_SECOND = 8,
|
||||
MAX_CONNECTIONS_PER_SECOND = 4,
|
||||
|
||||
/* number of unchoked peers per torrent.
|
||||
* FIXME: this probably ought to be configurable */
|
||||
|
@ -1755,6 +1755,24 @@ compareCandidates( const void * va, const void * vb )
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
getReconnectIntervalSecs( const struct peer_atom * atom )
|
||||
{
|
||||
int min;
|
||||
|
||||
switch( atom->numFails )
|
||||
{
|
||||
case 0:
|
||||
case 1: min = 7; break;
|
||||
case 2: min = 15; break;
|
||||
case 3: min = 30; break;
|
||||
case 4: min = 60; break;
|
||||
default: min = 120; break;
|
||||
}
|
||||
|
||||
return min * 60;
|
||||
}
|
||||
|
||||
static struct peer_atom **
|
||||
getPeerCandidates( Torrent * t, int * setmeSize )
|
||||
{
|
||||
|
@ -1791,21 +1809,13 @@ getPeerCandidates( Torrent * t, int * setmeSize )
|
|||
if( seed && (atom->flags & ADDED_F_SEED_FLAG) )
|
||||
continue;
|
||||
|
||||
/* we're wasting our time trying to connect to this bozo. */
|
||||
if( atom->numFails > 3 )
|
||||
continue;
|
||||
|
||||
/* If we were connected to this peer recently and transferring
|
||||
* piece data, try to reconnect -- network troubles may have
|
||||
* disconnected us. but if we weren't sharing piece data,
|
||||
* hold off on this peer to give another one a try instead */
|
||||
if( ( now - atom->piece_data_time ) > 30 )
|
||||
if( ( now - atom->piece_data_time ) > 10 )
|
||||
{
|
||||
int minWait = (60 * 5); /* five minutes */
|
||||
int maxWait = minWait * 3;
|
||||
int wait = atom->numFails * minWait;
|
||||
if( wait < minWait ) wait = minWait;
|
||||
if( wait > maxWait ) wait = maxWait;
|
||||
const int wait = getReconnectIntervalSecs( atom );
|
||||
if( ( now - atom->time ) < wait ) {
|
||||
tordbg( t, "RECONNECT peer %d (%s) is in its grace period of %d seconds..",
|
||||
i, tr_peerIoAddrStr(&atom->addr,atom->port), wait );
|
||||
|
|
Loading…
Reference in a new issue