From 52efe10ec555798aa0a37e00c614e50ff1cfd526 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Sat, 16 Aug 2008 05:12:55 +0000 Subject: [PATCH] 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. --- libtransmission/peer-mgr.c | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/libtransmission/peer-mgr.c b/libtransmission/peer-mgr.c index 7f0cb560b..6531de331 100644 --- a/libtransmission/peer-mgr.c +++ b/libtransmission/peer-mgr.c @@ -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 );