From 1fc7f10b6c49726d3c141bcac34ead7f6e7821f1 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Wed, 13 May 2009 20:54:35 +0000 Subject: [PATCH] (trunk libT) #2035: Transmission causes wakeups by unnecessary polling --- libtransmission/peer-mgr.c | 54 +++++++++++++++++++++++++++----------- libtransmission/tracker.c | 2 +- 2 files changed, 40 insertions(+), 16 deletions(-) diff --git a/libtransmission/peer-mgr.c b/libtransmission/peer-mgr.c index 8241bd31d..6a3156832 100644 --- a/libtransmission/peer-mgr.c +++ b/libtransmission/peer-mgr.c @@ -53,7 +53,7 @@ enum BANDWIDTH_PERIOD_MSEC = 500, /* how frequently to age out old piece request lists */ - REFILL_UPKEEP_PERIOD_MSEC = 10000, + REFILL_UPKEEP_PERIOD_MSEC = ( 10 * 1000 ), /* how frequently to decide which peers live and die */ RECONNECT_PERIOD_MSEC = 500, @@ -450,28 +450,33 @@ tr_peerMgr* tr_peerMgrNew( tr_session * session ) { tr_peerMgr * m = tr_new0( tr_peerMgr, 1 ); - m->session = session; m->incomingHandshakes = TR_PTR_ARRAY_INIT; - m->bandwidthTimer = tr_timerNew( session, bandwidthPulse, m, BANDWIDTH_PERIOD_MSEC ); - m->rechokeTimer = tr_timerNew( session, rechokePulse, m, RECHOKE_PERIOD_MSEC ); - m->reconnectTimer = tr_timerNew( session, reconnectPulse, m, RECONNECT_PERIOD_MSEC ); - m->refillUpkeepTimer = tr_timerNew( session, refillUpkeep, m, REFILL_UPKEEP_PERIOD_MSEC ); - - rechokePulse( m ); - return m; } +static void +deleteTimers( struct tr_peerMgr * m ) +{ + if( m->bandwidthTimer ) + tr_timerFree( &m->bandwidthTimer ); + + if( m->rechokeTimer == NULL ) + tr_timerFree( &m->rechokeTimer ); + + if( m->reconnectTimer == NULL ) + tr_timerFree( &m->reconnectTimer ); + + if( m->refillUpkeepTimer == NULL ) + tr_timerFree( &m->refillUpkeepTimer ); +} + void tr_peerMgrFree( tr_peerMgr * manager ) { managerLock( manager ); - tr_timerFree( &manager->refillUpkeepTimer ); - tr_timerFree( &manager->reconnectTimer ); - tr_timerFree( &manager->rechokeTimer ); - tr_timerFree( &manager->bandwidthTimer ); + deleteTimers( manager ); /* free the handshakes. Abort invokes handshakeDoneCB(), which removes * the item from manager->handshakes, so this is a little roundabout... */ @@ -1568,14 +1573,32 @@ tr_peerMgrGetPeers( tr_torrent * tor, return peersReturning; } +static void +ensureMgrTimersExist( struct tr_peerMgr * m ) +{ + tr_session * s = m->session; + + if( m->bandwidthTimer == NULL ) + m->bandwidthTimer = tr_timerNew( s, bandwidthPulse, m, BANDWIDTH_PERIOD_MSEC ); + + if( m->rechokeTimer == NULL ) + m->rechokeTimer = tr_timerNew( s, rechokePulse, m, RECHOKE_PERIOD_MSEC ); + + if( m->reconnectTimer == NULL ) + m->reconnectTimer = tr_timerNew( s, reconnectPulse, m, RECONNECT_PERIOD_MSEC ); + + if( m->refillUpkeepTimer == NULL ) + m->refillUpkeepTimer = tr_timerNew( s, refillUpkeep, m, REFILL_UPKEEP_PERIOD_MSEC ); +} + void tr_peerMgrStartTorrent( tr_torrent * tor ) { Torrent * t = tor->torrentPeers; + assert( t != NULL ); managerLock( t->manager ); - - assert( t ); + ensureMgrTimersExist( t->manager ); if( !t->isRunning ) { @@ -1585,6 +1608,7 @@ tr_peerMgrStartTorrent( tr_torrent * tor ) refillSoon( t ); } + rechokePulse( t->manager ); managerUnlock( t->manager ); } diff --git a/libtransmission/tracker.c b/libtransmission/tracker.c index 33030a202..fadb91e2d 100644 --- a/libtransmission/tracker.c +++ b/libtransmission/tracker.c @@ -41,7 +41,7 @@ enum HTTP_OK = 200, /* seconds between tracker pulses */ - PULSE_INTERVAL_MSEC = 1000, + PULSE_INTERVAL_MSEC = 1500, /* unless the tracker says otherwise, rescrape this frequently */ DEFAULT_SCRAPE_INTERVAL_SEC = ( 60 * 15 ),