Changeset 9514


Ignore:
Timestamp:
Nov 10, 2009, 5:26:04 PM (11 years ago)
Author:
charles
Message:

(trunk libT) #2551: when uploading to peers, prefetch local data from disk

File:
1 edited

Legend:

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

    r9513 r9514  
    173173    int             desiredRequestCount;
    174174
     175    int             prefetchCount;
     176
    175177    /* how long the outMessages batch should be allowed to grow before
    176178     * it's flushed -- some messages (like requests >:) should be sent
     
    198200    struct peer_request    peerAskedFor[REQQ];
    199201    int                    peerAskedForCount;
    200     
     202 
    201203    tr_pex               * pex;
    202204    tr_pex               * pex6;
     
    837839        tr_bencDictAddRaw( &val, "ipv6", ipv6, 16 );
    838840    tr_bencDictAddInt( &val, "p", tr_sessionGetPeerPort( getSession(msgs) ) );
    839     tr_bencDictAddInt( &val, "reqq", REQQ ); 
     841    tr_bencDictAddInt( &val, "reqq", REQQ );
    840842    tr_bencDictAddInt( &val, "upload_only", tr_torrentIsSeed( msgs->torrent ) );
    841843    tr_bencDictAddStr( &val, "v", TR_NAME " " USERAGENT_PREFIX );
     
    15571559        double rate;
    15581560        const int floor = 16;
    1559         const int seconds = REQUEST_BUF_SECS; 
     1561        const int seconds = REQUEST_BUF_SECS;
    15601562
    15611563        /* Get the rate limit we should use.
     
    15951597        tr_block_index_t * blocks = tr_new( tr_block_index_t, numwant );
    15961598
    1597         tr_peerMgrGetNextRequests( msgs->torrent, msgs->peer, numwant, blocks, &n ); 
     1599        tr_peerMgrGetNextRequests( msgs->torrent, msgs->peer, numwant, blocks, &n );
    15981600
    15991601        for( i=0; i<n; ++i )
     
    16071609
    16081610        tr_free( blocks );
     1611    }
     1612}
     1613
     1614static void
     1615prefetchPieces( tr_peermsgs *msgs )
     1616{
     1617    int i;
     1618    uint64_t next = 0;
     1619
     1620    /* Maintain at least 8 prefetched blocks per unchoked peer, but allow
     1621       up to 4 extra blocks if that would cause sequential writes. */
     1622    for( i=msgs->prefetchCount; i<msgs->peerAskedForCount; ++i )
     1623    {
     1624        const struct peer_request * req = msgs->peerAskedFor + i;
     1625        const uint64_t begin = tr_pieceOffset( msgs->torrent, req->index, req->offset, 0 );
     1626        const uint64_t end = begin + req->length;
     1627        const tr_bool isSequential = next == begin;
     1628
     1629        if( ( i >= 12 ) || ( !isSequential && ( i >= 8 ) ) )
     1630            break;
     1631
     1632        tr_ioPrefetch( msgs->torrent, req->index, req->offset, req->length );
     1633        ++msgs->prefetchCount;
     1634
     1635        next = end;
    16091636    }
    16101637}
     
    16461673        && popNextRequest( msgs, &req ) )
    16471674    {
     1675        --msgs->prefetchCount;
     1676
    16481677        if( requestIsValid( msgs, &req )
    16491678            && tr_cpPieceIsComplete( &msgs->torrent->completion, req.index ) )
     
    16911720            protocolSendReject( msgs, &req );
    16921721        }
     1722
     1723        prefetchPieces( msgs );
    16931724    }
    16941725
Note: See TracChangeset for help on using the changeset viewer.