Changeset 9651


Ignore:
Timestamp:
Dec 2, 2009, 5:30:46 AM (12 years ago)
Author:
charles
Message:

(trunk libT) experimental: Reduce SO_SNDBUF and SO_RCVBUF for tracker announce/scrape messages. Reduce SO_RCVBUF for outgoing peer connections on seeding torrents.

Location:
trunk/libtransmission
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/announcer.c

    r9626 r9651  
    5858
    5959    /* how many scrapes we allow at one time */
    60     MAX_CONCURRENT_SCRAPES = 16,
     60    MAX_CONCURRENT_SCRAPES = 96,
    6161
    6262    /* how many announces we allow at one time */
    63     MAX_CONCURRENT_ANNOUNCES = 48,
     63    MAX_CONCURRENT_ANNOUNCES = 96,
    6464
    6565    /* if a tracker takes more than this long to respond,
     
    209209}
    210210tr_announcer;
     211
     212tr_bool
     213tr_announcerHasBacklog( const struct tr_announcer * announcer )
     214{
     215    return ( announcer->scrapeSlotsAvailable < 1 )
     216        || ( announcer->announceSlotsAvailable < 1 );
     217}
    211218
    212219static tr_host *
     
    16431650        }
    16441651
     1652#if 0
     1653char timebuf[64];
     1654tr_getLogTimeStr( timebuf, 64 );
     1655fprintf( stderr, "[%s] announce.c has %d requests ready to send (announce: %d, scrape: %d)\n", timebuf, (int)(tr_ptrArraySize(&announceMe)+tr_ptrArraySize(&scrapeMe)), (int)tr_ptrArraySize(&announceMe), (int)tr_ptrArraySize(&scrapeMe) );
     1656#endif
     1657
    16451658        /* cleanup */
    16461659        tr_ptrArrayDestruct( &scrapeMe, NULL );
  • trunk/libtransmission/announcer.h

    r9230 r9651  
    6767                                                  tr_torrent           * );
    6868
     69tr_bool tr_announcerHasBacklog( const struct tr_announcer * );
     70
    6971void tr_announcerResetTorrent( struct tr_announcer*, tr_torrent* );
    7072
  • trunk/libtransmission/net.c

    r9593 r9651  
    290290tr_netOpenTCP( tr_session        * session,
    291291               const tr_address  * addr,
    292                tr_port             port )
     292               tr_port             port,
     293               tr_bool             isSeed )
    293294{
    294295    static const int domains[NUM_TR_AF_INET_TYPES] = { AF_INET, AF_INET6 };
     
    308309    if( s < 0 )
    309310        return -1;
     311
     312    /* seeds don't need much of a read buffer... */
     313    if( isSeed ) {
     314        int n = 1024 * 2;
     315        if( setsockopt( s, SOL_SOCKET, SO_RCVBUF, &n, sizeof(n) ) )
     316            tr_inf( "Unable to set SO_RCVBUF on socket %d: %s", s, tr_strerror( sockerrno ) );
     317    }
    310318
    311319    if( evutil_make_socket_nonblocking( s ) < 0 ) {
  • trunk/libtransmission/net.h

    r9513 r9651  
    101101int  tr_netOpenTCP( tr_session       * session,
    102102                    const tr_address * addr,
    103                     tr_port            port );
     103                    tr_port            port,
     104                    tr_bool            isSeed );
    104105
    105106int  tr_netBindTCP( const tr_address * addr,
  • trunk/libtransmission/peer-io.c

    r9593 r9651  
    364364              tr_port            port,
    365365              const uint8_t    * torrentHash,
    366               int                isIncoming,
     366              tr_bool            isIncoming,
     367              tr_bool            isSeed,
    367368              int                socket )
    368369{
     
    371372    assert( session != NULL );
    372373    assert( session->events != NULL );
     374    assert( tr_isBool( isIncoming ) );
     375    assert( tr_isBool( isSeed ) );
    373376    assert( tr_amInEventThread( session ) );
    374377
     
    406409                      const tr_address  * addr,
    407410                      tr_port             port,
    408                       int                 socket )
     411                      int                 fd )
    409412{
    410413    assert( session );
    411414    assert( tr_isAddress( addr ) );
    412     assert( socket >= 0 );
    413 
    414     return tr_peerIoNew( session, parent, addr, port, NULL, 1, socket );
     415    assert( fd >= 0 );
     416
     417    return tr_peerIoNew( session, parent, addr, port, NULL, TRUE, FALSE, fd );
    415418}
    416419
     
    420423                      const tr_address  * addr,
    421424                      tr_port             port,
    422                       const uint8_t     * torrentHash )
    423 {
    424     int socket;
     425                      const uint8_t     * torrentHash,
     426                      tr_bool             isSeed )
     427{
     428    int fd;
    425429
    426430    assert( session );
     
    428432    assert( torrentHash );
    429433
    430     socket = tr_netOpenTCP( session, addr, port );
    431     dbgmsg( NULL, "tr_netOpenTCP returned fd %d", socket );
    432 
    433     return socket < 0
    434            ? NULL
    435            : tr_peerIoNew( session, parent, addr, port, torrentHash, 0, socket );
     434    fd = tr_netOpenTCP( session, addr, port, isSeed );
     435    dbgmsg( NULL, "tr_netOpenTCP returned fd %d", fd );
     436
     437    return fd < 0 ? NULL
     438                  : tr_peerIoNew( session, parent, addr, port, torrentHash, FALSE, isSeed, fd );
    436439}
    437440
     
    559562        tr_netClose( session, io->socket );
    560563
    561     io->socket = tr_netOpenTCP( session, &io->addr, io->port );
     564    io->socket = tr_netOpenTCP( session, &io->addr, io->port, io->isSeed );
    562565    if( io->socket >= 0 )
    563566    {
  • trunk/libtransmission/peer-io.h

    r8903 r9651  
    8383
    8484    uint8_t               encryptionMode;
     85    tr_bool               isSeed;
    8586
    8687    tr_port               port;
     
    121122                                  const struct tr_address * addr,
    122123                                  tr_port                   port,
    123                                   const  uint8_t          * torrentHash );
     124                                  const  uint8_t          * torrentHash,
     125                                  tr_bool                   isSeed );
    124126
    125127tr_peerIo*  tr_peerIoNewIncoming( tr_session              * session,
  • trunk/libtransmission/peer-mgr.c

    r9633 r9651  
    2020
    2121#include "transmission.h"
     22#include "announcer.h"
    2223#include "bandwidth.h"
    2324#include "bencode.h"
     
    26092610        /* decide how many peers can we try to add in this pass */
    26102611        maxCandidates = MAX_RECONNECTIONS_PER_PULSE;
     2612        if( tr_announcerHasBacklog( t->manager->session->announcer ) )
     2613            maxCandidates /= 2;
    26112614        maxCandidates = MIN( maxCandidates, getMaxPeerCount( t->tor ) - getPeerCount( t ) );
    26122615        maxCandidates = MIN( maxCandidates, MAX_CONNECTIONS_PER_SECOND - newConnectionsThisSecond );
     
    26752678                                           &atom->addr,
    26762679                                           atom->port,
    2677                                            t->tor->info.hash );
     2680                                           t->tor->info.hash,
     2681                                           t->tor->completeness == TR_SEED );
    26782682
    26792683                if( io == NULL )
  • trunk/libtransmission/web.c

    r9626 r9651  
    183183
    184184static void
     185sockoptfunction( void * vtask, curl_socket_t fd, curlsocktype purpose UNUSED )
     186{
     187    struct tr_web_task * task = vtask;
     188    const tr_bool isScrape = strstr( task->url, "scrape" ) != NULL;
     189    const tr_bool isAnnounce = strstr( task->url, "announce" ) != NULL;
     190
     191    /* announce and scrape requests have tiny payloads...
     192     * which have very small payloads */
     193    if( isScrape || isAnnounce )
     194    {
     195        int sndbuf = 1024;
     196        int rcvbuf = isScrape ? 2048 : 3072;
     197
     198        if( setsockopt( fd, SOL_SOCKET, SO_SNDBUF, &sndbuf, sizeof(sndbuf) ) )
     199            tr_inf( "Unable to set SO_SNDBUF on socket %d: %s", fd, tr_strerror( sockerrno ) );
     200
     201        if( setsockopt( fd, SOL_SOCKET, SO_RCVBUF, &rcvbuf, sizeof(rcvbuf) ) )
     202            tr_inf( "Unable to set SO_RCVBUF on socket %d: %s", fd, tr_strerror( sockerrno ) );
     203    }
     204}
     205
     206static void
    185207addTask( void * vtask )
    186208{
     
    225247        dbgmsg( "new task's timeout is %ld\n", timeout );
    226248
    227         curl_easy_setopt( easy, CURLOPT_DNS_CACHE_TIMEOUT, 600L );
     249        curl_easy_setopt( easy, CURLOPT_SOCKOPTFUNCTION, sockoptfunction );
     250        curl_easy_setopt( easy, CURLOPT_SOCKOPTDATA, task );
     251        curl_easy_setopt( easy, CURLOPT_DNS_CACHE_TIMEOUT, 1800L );
    228252        curl_easy_setopt( easy, CURLOPT_FOLLOWLOCATION, 1L );
    229253        curl_easy_setopt( easy, CURLOPT_AUTOREFERER, 1L );
Note: See TracChangeset for help on using the changeset viewer.