diff --git a/libtransmission/peer-mgr.c b/libtransmission/peer-mgr.c index cf19b99b2..53b6d13a0 100644 --- a/libtransmission/peer-mgr.c +++ b/libtransmission/peer-mgr.c @@ -128,8 +128,8 @@ struct tr_peerMgr tr_ptrArray * torrents; /* Torrent */ tr_ptrArray * incomingHandshakes; /* tr_handshake */ tr_timer * bandwidthTimer; - double rateHistory[2][BANDWIDTH_PULSES_PER_SECOND]; - double globalPoolHistory[2][BANDWIDTH_PULSES_PER_SECOND]; + double rateHistory[2][BANDWIDTH_PULSE_HISTORY]; + double globalPoolHistory[2][BANDWIDTH_PULSE_HISTORY]; }; #define tordbg(t, fmt...) \ @@ -1476,15 +1476,16 @@ tr_peerMgrGetRate( const tr_peerMgr * manager, tr_direction direction ) { int i; - double rate = 0; + double bytes = 0; assert( manager != NULL ); assert( direction==TR_UP || direction==TR_DOWN ); - for( i=0; irateHistory[direction][i]; + for( i=0; irateHistory[direction][i]; - return rate / 1024.0; + return ( BANDWIDTH_PULSES_PER_SECOND * bytes ) + / ( BANDWIDTH_PULSE_HISTORY * 1024 ); } float* @@ -2016,49 +2017,49 @@ reconnectPulse( void * vtorrent ) static double allocateHowMuch( double desiredAvgKB, - const double * history, - int pulseNumber ) + const double * history ) { - int i; - int oldest = ( pulseNumber + 1 ) % BANDWIDTH_PULSES_PER_SECOND; const double baseline = desiredAvgKB * 1024.0 / BANDWIDTH_PULSES_PER_SECOND; const double min = baseline * 0.66; const double max = baseline * 1.33; - double bytes; + int i; + double usedBytes; + double n; + double clamped; - bytes = desiredAvgKB * 1024.0; - for( i=0; iio, direction ); @@ -2122,8 +2123,8 @@ countPeerBandwidth( tr_ptrArray * peers, tr_direction direction ) static void givePeersUnlimitedBandwidth( tr_ptrArray * peers, tr_direction direction ) { - int i; const int n = tr_ptrArraySize( peers ); + int i; for( i=0; itorrents ); + int i, j; for( i=0; itorrents, i ); @@ -2196,7 +2197,6 @@ allocateBandwidth( tr_peerMgr * mgr, setPeerBandwidth( t->peers, direction, t->tor->rateHistory[direction], - pulseNumber, tr_torrentGetSpeedLimit( t->tor, direction ) ); break; @@ -2226,7 +2226,6 @@ allocateBandwidth( tr_peerMgr * mgr, else setPeerBandwidth( globalPool, direction, mgr->globalPoolHistory[direction], - pulseNumber, tr_sessionGetSpeedLimit( session, direction ) ); /* now that we've allocated bandwidth, pump all the connected peers */ @@ -2245,7 +2244,7 @@ bandwidthPulse( void * vmgr ) managerLock( mgr ); /* keep track of how far we are into the cycle */ - if( ++mgr->bandwidthPulseNumber == BANDWIDTH_PULSES_PER_SECOND ) + if( ++mgr->bandwidthPulseNumber == BANDWIDTH_PULSE_HISTORY ) mgr->bandwidthPulseNumber = 0; /* allocate the upload and download bandwidth */ diff --git a/libtransmission/session.h b/libtransmission/session.h index d77297cd2..18cb3e2b2 100644 --- a/libtransmission/session.h +++ b/libtransmission/session.h @@ -35,10 +35,15 @@ #endif #endif -/** - * How frequently to reallocate peer bandwidth. - */ -#define BANDWIDTH_PULSES_PER_SECOND 5 +enum +{ + /* How frequently to reallocate peer bandwidth. */ + BANDWIDTH_PULSES_PER_SECOND = 8, + + /* HOw many pulses to remember for averaging the current speed */ + BANDWIDTH_PULSE_HISTORY = ( BANDWIDTH_PULSES_PER_SECOND * 2 ) +}; + typedef enum { TR_NET_OK, TR_NET_ERROR, TR_NET_WAIT } tr_tristate_t; diff --git a/libtransmission/torrent.h b/libtransmission/torrent.h index ec64d3231..129cd022e 100644 --- a/libtransmission/torrent.h +++ b/libtransmission/torrent.h @@ -180,7 +180,7 @@ struct tr_torrent int uniqueId; - double rateHistory[2][BANDWIDTH_PULSES_PER_SECOND]; + double rateHistory[2][BANDWIDTH_PULSE_HISTORY]; };