Ignore:
Timestamp:
Feb 3, 2010, 12:12:19 AM (12 years ago)
Author:
charles
Message:

(trunk libT) taper off the number of new connections per pulse per torrent based on how long the torrent's been running. Brand-new torrents get a higher burst of new peer connection attempts, but long-running torrents don't need that kind of activity.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/peer-mgr.c

    r10017 r10085  
    6161    MAX_UPLOAD_IDLE_SECS = ( 60 * 5 ),
    6262
    63     /* max # of peers to ask fer per torrent per reconnect pulse */
    64     MAX_RECONNECTIONS_PER_PULSE = 8,
    65 
    6663    /* max number of peers to ask for per second overall.
    6764    * this throttle is to avoid overloading the router */
     
    26862683}
    26872684
     2685/* Make a lot of slots available to newly-running torrents...
     2686 * once they reach steady state, they shouldn't need as many */
     2687static int
     2688maxNewPeersPerPulse( const Torrent * t )
     2689{
     2690    double runTime;
     2691    const tr_torrent * tor = t->tor;
     2692
     2693    assert( tr_isTorrent( tor ) );
     2694
     2695    runTime = difftime( tr_time( ), tor->startDate );
     2696    if( runTime > 480 ) return 1;
     2697    if( runTime > 240 ) return 2;
     2698    if( runTime > 120 ) return 3;
     2699    return 4;
     2700}
     2701
    26882702static void
    26892703reconnectTorrent( Torrent * t )
     
    27092723        int maxCandidates;
    27102724        struct tr_peer ** mustClose;
     2725        const int maxPerPulse = maxNewPeersPerPulse( t );
    27112726
    27122727        /* disconnect the really bad peers */
     
    27172732
    27182733        /* decide how many peers can we try to add in this pass */
    2719         maxCandidates = MAX_RECONNECTIONS_PER_PULSE;
     2734   
     2735        maxCandidates = maxPerPulse;
    27202736        if( tr_announcerHasBacklog( t->manager->session->announcer ) )
    27212737            maxCandidates /= 2;
     
    27312747                       t->tor->info.name, mustCloseCount,
    27322748                       tr_ptrArraySize( &t->pool ),
    2733                        MAX_RECONNECTIONS_PER_PULSE );
    2734 
    2735             tordbg( t, "maxCandidates is %d, MAX_RECONNECTIONS_PER_PULSE is %d, "
     2749                       maxPerPulse );
     2750
     2751            tordbg( t, "maxCandidates is %d, maxPerPulse is %d, "
    27362752                       "getPeerCount(t) is %d, getMaxPeerCount(t) is %d, "
    27372753                       "newConnectionsThisSecond is %d, MAX_CONNECTIONS_PER_SECOND is %d",
    2738                        maxCandidates, MAX_RECONNECTIONS_PER_PULSE,
     2754                       maxCandidates, maxPerPulse,
    27392755                       getPeerCount( t ), getMaxPeerCount( t->tor ),
    27402756                       newConnectionsThisSecond, MAX_CONNECTIONS_PER_SECOND );
     
    27632779                       t->tor->info.name, mustCloseCount,
    27642780                       canCloseCount, candidateCount,
    2765                        tr_ptrArraySize( &t->pool ), MAX_RECONNECTIONS_PER_PULSE );
    2766 
    2767             tordbg( t, "candidateCount is %d, MAX_RECONNECTIONS_PER_PULSE is %d,"
     2781                       tr_ptrArraySize( &t->pool ), maxPerPulse );
     2782
     2783            tordbg( t, "candidateCount is %d, maxPerPulse is %d,"
    27682784                       " getPeerCount(t) is %d, getMaxPeerCount(t) is %d, "
    27692785                       "newConnectionsThisSecond is %d, MAX_CONNECTIONS_PER_SECOND is %d",
    2770                        candidateCount, MAX_RECONNECTIONS_PER_PULSE,
     2786                       candidateCount, maxPerPulse,
    27712787                       getPeerCount( t ), getMaxPeerCount( t->tor ),
    27722788                       newConnectionsThisSecond, MAX_CONNECTIONS_PER_SECOND );
Note: See TracChangeset for help on using the changeset viewer.