Ticket #2551: prefetch.3.patch
File prefetch.3.patch, 3.2 KB (added by charles, 11 years ago) |
---|
-
peer-msgs.c
172 172 int activeRequestCount; 173 173 int desiredRequestCount; 174 174 175 int prefetchCount; 176 175 177 /* how long the outMessages batch should be allowed to grow before 176 178 * it's flushed -- some messages (like requests >:) should be sent 177 179 * very quickly; others aren't as urgent. */ … … 197 199 198 200 struct peer_request peerAskedFor[REQQ]; 199 201 int peerAskedForCount; 200 202 201 203 tr_pex * pex; 202 204 tr_pex * pex6; 203 205 … … 833 835 tr_bencInitDict( &val, 5 ); 834 836 tr_bencDictAddInt( &val, "e", getSession(msgs)->encryptionMode != TR_CLEAR_PREFERRED ); 835 837 tr_bencDictAddInt( &val, "p", tr_sessionGetPeerPort( getSession(msgs) ) ); 836 tr_bencDictAddInt( &val, "reqq", REQQ ); 838 tr_bencDictAddInt( &val, "reqq", REQQ ); 837 839 tr_bencDictAddInt( &val, "upload_only", tr_torrentIsSeed( msgs->torrent ) ); 838 840 tr_bencDictAddStr( &val, "v", TR_NAME " " USERAGENT_PREFIX ); 839 841 m = tr_bencDictAddDict( &val, "m", 1 ); … … 1529 1531 int estimatedBlocksInPeriod; 1530 1532 double rate; 1531 1533 const int floor = 16; 1532 const int seconds = REQUEST_BUF_SECS; 1534 const int seconds = REQUEST_BUF_SECS; 1533 1535 1534 1536 /* Get the rate limit we should use. 1535 1537 * FIXME: this needs to consider all the other peers as well... */ … … 1567 1569 int n; 1568 1570 tr_block_index_t * blocks = tr_new( tr_block_index_t, numwant ); 1569 1571 1570 tr_peerMgrGetNextRequests( msgs->torrent, msgs->peer, numwant, blocks, &n ); 1572 tr_peerMgrGetNextRequests( msgs->torrent, msgs->peer, numwant, blocks, &n ); 1571 1573 1572 1574 for( i=0; i<n; ++i ) 1573 1575 { … … 1582 1584 } 1583 1585 } 1584 1586 1587 static void 1588 prefetchPieces( tr_peermsgs *msgs ) 1589 { 1590 int i; 1591 uint64_t next = 0; 1592 1593 /* Maintain at least 8 prefetched blocks per unchoked peer, but allow 1594 up to 4 extra blocks if that would cause sequential writes. */ 1595 for( i=msgs->prefetchCount; i<msgs->peerAskedForCount; ++i ) 1596 { 1597 const struct peer_request * req = msgs->peerAskedFor + i; 1598 const uint64_t begin = tr_pieceOffset( msgs->torrent, req->index, req->offset, 0 ); 1599 const uint64_t end = begin + req->length; 1600 const tr_bool isSequential = next == begin; 1601 1602 if( ( i >= 12 ) || ( !isSequential && ( i >= 8 ) ) ) 1603 break; 1604 1605 tr_ioPrefetch( msgs->torrent, req->index, req->offset, req->length ); 1606 ++msgs->prefetchCount; 1607 1608 next = end; 1609 } 1610 } 1611 1585 1612 static size_t 1586 1613 fillOutputBuffer( tr_peermsgs * msgs, time_t now ) 1587 1614 { … … 1618 1645 if( ( tr_peerIoGetWriteBufferSpace( msgs->peer->io, now ) >= msgs->torrent->blockSize ) 1619 1646 && popNextRequest( msgs, &req ) ) 1620 1647 { 1648 --msgs->prefetchCount; 1649 1621 1650 if( requestIsValid( msgs, &req ) 1622 1651 && tr_cpPieceIsComplete( &msgs->torrent->completion, req.index ) ) 1623 1652 { … … 1663 1692 { 1664 1693 protocolSendReject( msgs, &req ); 1665 1694 } 1695 1696 prefetchPieces( msgs ); 1666 1697 } 1667 1698 1668 1699 /**