Changeset 5980
- Timestamp:
- May 31, 2008, 12:16:26 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/libtransmission/peer-msgs.c
r5932 r5980 65 65 66 66 /* idle seconds before we send a keepalive */ 67 KEEPALIVE_INTERVAL_SECS = 90,67 KEEPALIVE_INTERVAL_SECS = 100, 68 68 69 69 PEX_INTERVAL = (90 * 1000), /* msec between sendPex() calls */ … … 85 85 /* how long a sent request can stay queued before it's returned 86 86 back to the peer-mgr's pool of requests */ 87 SENT_REQUEST_TTL_SECS = 120 87 SENT_REQUEST_TTL_SECS = 120, 88 89 /* used in lowering the outMessages queue period */ 90 IMMEDIATE_PRIORITY_INTERVAL_SECS = 0, 91 HIGH_PRIORITY_INTERVAL_SECS = 5, 92 LOW_PRIORITY_INTERVAL_SECS = 30 88 93 }; 89 94 … … 268 273 time_t clientSentPexAt; 269 274 time_t clientSentAnythingAt; 275 276 /* when we started batching the outMessages */ 277 time_t outMessagesBatchedAt; 278 279 /* how long the outMessages batch should be allowed to grow before 280 * it's flushed -- some messages (like requests >:) should be sent 281 * very quickly; others aren't as urgent. */ 282 int outMessagesBatchPeriod; 270 283 271 284 tr_bitfield * peerAllowedPieces; … … 316 329 317 330 static void 331 pokeBatchPeriod( tr_peermsgs * msgs, int interval ) 332 { 333 if( msgs->outMessagesBatchPeriod > interval ) 334 { 335 msgs->outMessagesBatchPeriod = interval; 336 dbgmsg( msgs, "lowering batch interval to %d seconds", interval ); 337 } 338 } 339 340 static void 318 341 protocolSendRequest( tr_peermsgs * msgs, const struct peer_request * req ) 319 342 { … … 327 350 tr_peerIoWriteUint32( io, out, req->offset ); 328 351 tr_peerIoWriteUint32( io, out, req->length ); 352 pokeBatchPeriod( msgs, HIGH_PRIORITY_INTERVAL_SECS ); 329 353 } 330 354 … … 341 365 tr_peerIoWriteUint32( io, out, req->offset ); 342 366 tr_peerIoWriteUint32( io, out, req->length ); 367 pokeBatchPeriod( msgs, IMMEDIATE_PRIORITY_INTERVAL_SECS ); 343 368 } 344 369 … … 353 378 tr_peerIoWriteUint8 ( io, out, BT_HAVE ); 354 379 tr_peerIoWriteUint32( io, out, index ); 380 pokeBatchPeriod( msgs, LOW_PRIORITY_INTERVAL_SECS ); 355 381 } 356 382 … … 364 390 tr_peerIoWriteUint32( io, out, sizeof(uint8_t) ); 365 391 tr_peerIoWriteUint8 ( io, out, choke ? BT_CHOKE : BT_UNCHOKE ); 392 pokeBatchPeriod( msgs, IMMEDIATE_PRIORITY_INTERVAL_SECS ); 366 393 } 367 394 … … 497 524 tr_peerIoWriteUint8 ( msgs->io, msgs->outMessages, 498 525 weAreInterested ? BT_INTERESTED : BT_NOT_INTERESTED ); 526 pokeBatchPeriod( msgs, HIGH_PRIORITY_INTERVAL_SECS ); 499 527 } 500 528 … … 596 624 tr_peerIoWriteUint32( msgs->io, msgs->outMessages, offset ); 597 625 tr_peerIoWriteUint32( msgs->io, msgs->outMessages, length ); 626 pokeBatchPeriod( msgs, LOW_PRIORITY_INTERVAL_SECS ); 598 627 } 599 628 } … … 625 654 tr_peerIoWriteUint8( msgs->io, msgs->outMessages, BT_ALLOWED_FAST ); 626 655 tr_peerIoWriteUint32( msgs->io, msgs->outMessages, pieceIndex ); 656 pokeBatchPeriod( msgs, LOW_PRIORITY_INTERVAL_SECS ); 627 657 } 628 658 } … … 1571 1601 dbgmsg( msgs, "sending a keepalive message" ); 1572 1602 tr_peerIoWriteUint32( msgs->io, msgs->outMessages, 0 ); 1603 pokeBatchPeriod( msgs, IMMEDIATE_PRIORITY_INTERVAL_SECS ); 1573 1604 } 1574 1605 … … 1657 1688 { 1658 1689 struct peer_request req; 1659 1660 if(( EVBUFFER_LENGTH( msgs->outMessages ) )) 1690 int haveMessages = EVBUFFER_LENGTH( msgs->outMessages ) != 0; 1691 1692 if( haveMessages && !msgs->outMessagesBatchedAt ) /* fresh batch */ 1661 1693 { 1662 dbgmsg( msgs, "flushing outMessages..." ); 1694 dbgmsg( msgs, "started an outMessages batch (length is %d)", (int)EVBUFFER_LENGTH( msgs->outMessages ) ); 1695 msgs->outMessagesBatchedAt = now; 1696 } 1697 else if( haveMessages 1698 && ( ( now - msgs->outMessagesBatchedAt ) > msgs->outMessagesBatchPeriod ) ) 1699 { 1700 dbgmsg( msgs, "flushing outMessages... (length is %d)", (int)EVBUFFER_LENGTH( msgs->outMessages ) ); 1663 1701 tr_peerIoWriteBuf( msgs->io, msgs->outMessages ); 1664 1702 msgs->clientSentAnythingAt = now; 1703 msgs->outMessagesBatchedAt = 0; 1704 msgs->outMessagesBatchPeriod = LOW_PRIORITY_INTERVAL_SECS; 1665 1705 } 1666 1706 else if( !EVBUFFER_LENGTH( msgs->outBlock ) … … 1687 1727 tr_free( buf ); 1688 1728 } 1689 else if( ( now - msgs->clientSentAnythingAt ) > KEEPALIVE_INTERVAL_SECS ) 1729 else if( ( !haveMessages ) 1730 && ( now - msgs->clientSentAnythingAt ) > KEEPALIVE_INTERVAL_SECS ) 1690 1731 { 1691 1732 sendKeepalive( msgs ); … … 1717 1758 tr_peerIoWriteUint8 ( msgs->io, out, BT_BITFIELD ); 1718 1759 tr_peerIoWriteBytes ( msgs->io, out, bitfield->bits, bitfield->len ); 1760 pokeBatchPeriod( msgs, IMMEDIATE_PRIORITY_INTERVAL_SECS ); 1719 1761 } 1720 1762 … … 1839 1881 tr_peerIoWriteUint8 ( msgs->io, msgs->outMessages, msgs->ut_pex_id ); 1840 1882 tr_peerIoWriteBytes ( msgs->io, msgs->outMessages, benc, bencLen ); 1883 pokeBatchPeriod( msgs, IMMEDIATE_PRIORITY_INTERVAL_SECS ); 1841 1884 1842 1885 /* cleanup */ … … 1890 1933 m->pexTimer = tr_timerNew( m->handle, pexPulse, m, PEX_INTERVAL ); 1891 1934 m->outMessages = evbuffer_new( ); 1935 m->outMessagesBatchedAt = 0; 1936 m->outMessagesBatchPeriod = LOW_PRIORITY_INTERVAL_SECS; 1892 1937 m->incoming.block = evbuffer_new( ); 1893 1938 m->outBlock = evbuffer_new( );
Note: See TracChangeset
for help on using the changeset viewer.