Changeset 11283


Ignore:
Timestamp:
Oct 1, 2010, 6:16:01 PM (11 years ago)
Author:
charles
Message:

(trunk libT) #3329 "connection problems when downloading" -- apply Longinus00's fixSlowStart.diff

File:
1 edited

Legend:

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

    r11265 r11283  
    194194
    195195    int                        interestedCount;
     196    int                        maxPeers;
     197    tr_recentHistory         * noBlocksCancelsCount;
    196198
    197199    /* An arbitrary metric of how congested the downloads are.
     
    451453    tr_ptrArrayDestruct( &t->outgoingHandshakes, NULL );
    452454    tr_ptrArrayDestruct( &t->peers, NULL );
     455    tr_historyFree( t->noBlocksCancelsCount );
    453456
    454457    tr_free( t->requests );
     
    473476    t->webseeds = TR_PTR_ARRAY_INIT;
    474477    t->outgoingHandshakes = TR_PTR_ARRAY_INIT;
     478    t->noBlocksCancelsCount = tr_historyNew( CANCEL_HISTORY_SEC, 1 );
    475479
    476480    for( i = 0; i < tor->info.webseedCount; ++i )
     
    24872491        }
    24882492
    2489         if( !t->interestedCount )
     2493        if( !t->maxPeers )
    24902494        {
    24912495            /* this is the torrent's first time to call this function...
     
    24932497            maxPeers = t->tor->maxConnectedPeers;
    24942498        }
    2495         else if( !blocks )
     2499        else if( !blocks && cancels )
    24962500        {
    24972501            /* we've gotten cancels but zero blocks...
     
    24992503            maxPeers = t->interestedCount * 0.5;
    25002504        }
    2501         else
     2505        else if( blocks )
    25022506        {
    2503             const double cancelRate = cancels / (double)(cancels + blocks);
     2507            const double cancelRate = cancels / (double)(cancels + blocks );
     2508
     2509            /* if we're getting cancels then use interestedCount instead of
     2510             * maxPeers to scale faster */
    25042511                 if( cancelRate >= 0.20 ) maxPeers = t->interestedCount * 0.7;
    25052512            else if( cancelRate >= 0.10 ) maxPeers = t->interestedCount * 0.8;
    25062513            else if( cancelRate >= 0.05 ) maxPeers = t->interestedCount * 0.9;
    25072514            else if( cancelRate >= 0.01 ) maxPeers = t->interestedCount;
    2508             else                          maxPeers = t->interestedCount + 1;
     2515            else                          maxPeers = t->maxPeers + 1;
    25092516
    25102517            /* if things are getting worse, don't add more peers */
    25112518            if( ( t->cancelRate > 0.01 ) && ( cancelRate > t->cancelRate ) )
    2512                 maxPeers = MIN( maxPeers, t->interestedCount );
     2519                maxPeers = MIN( maxPeers, t->maxPeers );
    25132520
    25142521            t->cancelRate = cancelRate;
     
    25162523            tordbg( t, "cancel rate is %.3f -- changing the "
    25172524                       "number of peers we're interested in from %d to %d",
    2518                        cancelRate, t->interestedCount, maxPeers );
     2525                       cancelRate, t->maxPeers, maxPeers );
     2526        }
     2527        else
     2528        {
     2529            const unsigned maxCount = 10; /* maximum times in this block in the past two minutes */
     2530            tr_historyAdd( t->noBlocksCancelsCount, now, 1 );
     2531            if( tr_historyGet( t->noBlocksCancelsCount, now, msec * 2 ) < maxCount )
     2532            {
     2533                /* no blocks and no cancels means either that the torrent
     2534                 * just started or peers are unresponsive/nonexistent,
     2535                 * either way there's nothing to do */
     2536                maxPeers = t->maxPeers;
     2537            }
     2538            else
     2539            {
     2540                /* we've been in here for a while so maybe the network is down or there are no
     2541                 * good peers. maximize the chance of connecting to a good peer
     2542                 * if/when they show up */
     2543                maxPeers = t->tor->maxConnectedPeers;
     2544            }
    25192545        }
    25202546    }
     
    25252551    if( maxPeers > t->tor->maxConnectedPeers )
    25262552        maxPeers = t->tor->maxConnectedPeers;
     2553
     2554    t->maxPeers = maxPeers;
    25272555
    25282556    /* separate the peers into "good" (ones with a low cancel-to-block ratio),
Note: See TracChangeset for help on using the changeset viewer.