Changeset 11425


Ignore:
Timestamp:
Nov 16, 2010, 3:17:34 PM (11 years ago)
Author:
charles
Message:

(trunk libT) #3682 "reduce memory footprint caused by tr_history" -- done. Patch by Longinus00

Location:
trunk/libtransmission
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/history.c

    r11280 r11425  
    1111 */
    1212
     13#include <assert.h>
     14
    1315#include "transmission.h"
    1416#include "history.h"
     
    1820{
    1921    unsigned int n;
    20     uint64_t date;
     22    time_t date;
    2123};
    2224
     
    2527    int newest;
    2628    int sliceCount;
    27     unsigned int precision_msec;
     29    unsigned int precision;
    2830    struct history_slice * slices;
    2931};
    3032
    3133void
    32 tr_historyAdd( tr_recentHistory * h, uint64_t now, unsigned int n )
     34tr_historyAdd( tr_recentHistory * h, time_t now, unsigned int n )
    3335{
    34     if( h->slices[h->newest].date + h->precision_msec >= now )
     36    if( h->slices[h->newest].date + h->precision >= now )
    3537        h->slices[h->newest].n += n;
    3638    else {
     
    4244
    4345unsigned int
    44 tr_historyGet( const tr_recentHistory * h, uint64_t now, unsigned int msec )
     46tr_historyGet( const tr_recentHistory * h, time_t now, unsigned int sec )
    4547{
    4648    unsigned int n = 0;
    47     const uint64_t cutoff = (now?now:tr_time_msec()) - msec;
     49    const time_t cutoff = (now?now:tr_time()) - sec;
    4850    int i = h->newest;
    4951
     
    6365
    6466tr_recentHistory *
    65 tr_historyNew( unsigned int seconds, unsigned int bins_per_second )
     67tr_historyNew( unsigned int seconds, unsigned int precision )
    6668{
    6769    tr_recentHistory * h;
    6870
     71    assert( precision <= seconds );
     72
    6973    h = tr_new0( tr_recentHistory, 1 );
    70     h->precision_msec = 1000 / bins_per_second;
    71     h->sliceCount = (int)(seconds * bins_per_second);
     74    h->precision = precision;
     75    h->sliceCount = seconds / precision;
    7276    h->slices = tr_new0( struct history_slice, h->sliceCount );
    7377
  • trunk/libtransmission/history.h

    r11280 r11425  
    3030 * @brief create a new tr_recentHistory object.
    3131 * @param seconds how many seconds of history this object should remember
    32  * @param precision how precise the history should be, in fractions of a second.
    33  *        For a precision of 1/20th of a second, use a precision of 20.
     32 * @param precision how precise the history should be, in seconds
     33 *        For a precision of 10 seconds and a history of 2 minutes, makes 12 bins.
    3434 */
    3535tr_recentHistory * tr_historyNew( unsigned int seconds, unsigned int precision );
     
    4040/**
    4141 * @brief add a counter to the recent history object.
    42  * @param when the current time in msec, such as from tr_time_msec()
     42 * @param when the current time in sec, such as from tr_time()
    4343 * @param n how many items to add to the history's counter
    4444 */
    45 void tr_historyAdd( tr_recentHistory *, uint64_t when, unsigned int n );
     45void tr_historyAdd( tr_recentHistory *, time_t when, unsigned int n );
    4646
    4747/**
    4848 * @brief count how many events have occurred in the last N seconds.
    49  * @param when the current time in msec, such as from tr_time_msec()
     49 * @param when the current time in sec, such as from tr_time()
    5050 * @param seconds how many seconds to count back through.
    5151 */
    52 unsigned int tr_historyGet( const tr_recentHistory *, uint64_t when, unsigned int seconds );
     52unsigned int tr_historyGet( const tr_recentHistory *, time_t when, unsigned int seconds );
    5353
    5454#endif
  • trunk/libtransmission/peer-mgr.c

    r11349 r11425  
    9595    REQUEST_TTL_SECS = 120,
    9696
    97     CANCEL_HISTORY_SEC = 120
     97    NO_BLOCKS_CANCEL_HISTORY = 120,
     98
     99    CANCEL_HISTORY_SEC = 60
    98100};
    99101
     
    367369    atom->peer = peer;
    368370
    369     peer->blocksSentToClient  = tr_historyNew( CANCEL_HISTORY_SEC, 1 );
    370     peer->blocksSentToPeer    = tr_historyNew( CANCEL_HISTORY_SEC, 1 );
    371     peer->cancelsSentToClient = tr_historyNew( CANCEL_HISTORY_SEC, 1 );
    372     peer->cancelsSentToPeer   = tr_historyNew( CANCEL_HISTORY_SEC, 1 );
     371    peer->blocksSentToClient  = tr_historyNew( CANCEL_HISTORY_SEC, ( RECHOKE_PERIOD_MSEC / 1000 ) );
     372    peer->blocksSentToPeer    = tr_historyNew( CANCEL_HISTORY_SEC, ( RECHOKE_PERIOD_MSEC / 1000 ) );
     373    peer->cancelsSentToClient = tr_historyNew( CANCEL_HISTORY_SEC, ( RECHOKE_PERIOD_MSEC / 1000 ) );
     374    peer->cancelsSentToPeer   = tr_historyNew( CANCEL_HISTORY_SEC, ( REFILL_UPKEEP_PERIOD_MSEC / 1000 ) );
    373375
    374376    return peer;
     
    482484    t->webseeds = TR_PTR_ARRAY_INIT;
    483485    t->outgoingHandshakes = TR_PTR_ARRAY_INIT;
    484     t->noBlocksCancelsCount = tr_historyNew( CANCEL_HISTORY_SEC, 1 );
     486    t->noBlocksCancelsCount = tr_historyNew( NO_BLOCKS_CANCEL_HISTORY, ( RECHOKE_PERIOD_MSEC / 1000 ) );
    485487
    486488    for( i = 0; i < tor->info.webseedCount; ++i )
     
    11821184{
    11831185    time_t now;
    1184     uint64_t now_msec;
    11851186    time_t too_old;
    11861187    tr_torrent * tor;
     
    11891190
    11901191    now = tr_time( );
    1191     now_msec = tr_time_msec( );
    11921192    too_old = now - REQUEST_TTL_SECS;
    11931193
     
    12231223            for( it=cancel, end=it+cancelCount; it!=end; ++it ) {
    12241224                if( ( it->peer != NULL ) && ( it->peer->msgs != NULL ) ) {
    1225                     tr_historyAdd( it->peer->cancelsSentToPeer, now_msec, 1 );
     1225                    tr_historyAdd( it->peer->cancelsSentToPeer, now, 1 );
    12261226                    tr_peerMsgsCancel( it->peer->msgs, it->block );
    12271227                    decrementPendingReqCount( it );
     
    14431443
    14441444            if( peer != NULL )
    1445                 tr_historyAdd( peer->blocksSentToClient, tr_time_msec( ), 1 );
     1445                tr_historyAdd( peer->blocksSentToClient, tr_time( ), 1 );
    14461446
    14471447            if( tr_cpBlockIsComplete( &tor->completion, block ) )
     
    23212321    const tr_peer ** peers;
    23222322    tr_peer_stat * ret;
    2323     uint64_t now;
    2324     static const int CANCEL_HISTORY_MSEC = CANCEL_HISTORY_SEC * 1000;
     2323    uint64_t now_msec;
     2324    time_t now;
    23252325
    23262326    assert( t->manager );
     
    23302330    peers = (const tr_peer**) tr_ptrArrayBase( &t->peers );
    23312331    ret = tr_new0( tr_peer_stat, size );
    2332     now = tr_time_msec( );
     2332    now_msec = tr_time_msec( );
     2333    now = tr_time();
    23332334
    23342335    for( i=0; i<size; ++i )
     
    23462347        stat->progress            = peer->progress;
    23472348        stat->isEncrypted         = tr_peerIoIsEncrypted( peer->io ) ? 1 : 0;
    2348         stat->rateToPeer_KBps     = toSpeedKBps( tr_peerGetPieceSpeed_Bps( peer, now, TR_CLIENT_TO_PEER ) );
    2349         stat->rateToClient_KBps   = toSpeedKBps( tr_peerGetPieceSpeed_Bps( peer, now, TR_PEER_TO_CLIENT ) );
     2349        stat->rateToPeer_KBps     = toSpeedKBps( tr_peerGetPieceSpeed_Bps( peer, now_msec, TR_CLIENT_TO_PEER ) );
     2350        stat->rateToClient_KBps   = toSpeedKBps( tr_peerGetPieceSpeed_Bps( peer, now_msec, TR_PEER_TO_CLIENT ) );
    23502351        stat->peerIsChoked        = peer->peerIsChoked;
    23512352        stat->peerIsInterested    = peer->peerIsInterested;
     
    23572358        stat->isSeed              = ( atom->uploadOnly == UPLOAD_ONLY_YES ) || ( peer->progress >= 1.0 );
    23582359
    2359         stat->blocksToPeer        = tr_historyGet( peer->blocksSentToPeer,    now, CANCEL_HISTORY_MSEC );
    2360         stat->blocksToClient      = tr_historyGet( peer->blocksSentToClient,  now, CANCEL_HISTORY_MSEC );
    2361         stat->cancelsToPeer       = tr_historyGet( peer->cancelsSentToPeer,   now, CANCEL_HISTORY_MSEC );
    2362         stat->cancelsToClient     = tr_historyGet( peer->cancelsSentToClient, now, CANCEL_HISTORY_MSEC );
     2360        stat->blocksToPeer        = tr_historyGet( peer->blocksSentToPeer,    now, CANCEL_HISTORY_SEC );
     2361        stat->blocksToClient      = tr_historyGet( peer->blocksSentToClient,  now, CANCEL_HISTORY_SEC );
     2362        stat->cancelsToPeer       = tr_historyGet( peer->cancelsSentToPeer,   now, CANCEL_HISTORY_SEC );
     2363        stat->cancelsToClient     = tr_historyGet( peer->cancelsSentToClient, now, CANCEL_HISTORY_SEC );
    23632364
    23642365        stat->pendingReqsToPeer   = peer->pendingReqsToPeer;
     
    24472448{
    24482449    int i;
    2449     const uint64_t now = tr_time_msec( );
    2450     const int msec = 60 * 1000;
     2450    const time_t now = tr_time( );
    24512451    const int MIN_INTERESTING_PEERS = 5;
    24522452    const int peerCount = tr_ptrArraySize( &t->peers );
     
    24822482        {
    24832483            const tr_peer * peer = tr_ptrArrayNth( &t->peers, i );
    2484             const int b = tr_historyGet( peer->blocksSentToClient, now, msec );
    2485             const int c = tr_historyGet( peer->cancelsSentToPeer, now, msec );
     2484            const int b = tr_historyGet( peer->blocksSentToClient, now, CANCEL_HISTORY_SEC );
     2485            const int c = tr_historyGet( peer->cancelsSentToPeer, now, CANCEL_HISTORY_SEC );
    24862486
    24872487            if( b == 0 ) /* ignore unresponsive peers, as described above */
     
    25302530            const unsigned maxCount = 10; /* maximum times in this block in the past two minutes */
    25312531            tr_historyAdd( t->noBlocksCancelsCount, now, 1 );
    2532             if( tr_historyGet( t->noBlocksCancelsCount, now, msec * 2 ) < maxCount )
     2532            if( tr_historyGet( t->noBlocksCancelsCount, now, NO_BLOCKS_CANCEL_HISTORY ) < maxCount )
    25332533            {
    25342534                /* no blocks and no cancels means either that the torrent
     
    25742574            else
    25752575            {
    2576                 const int blocks = tr_historyGet( peer->blocksSentToClient, now, msec );
    2577                 const int cancels = tr_historyGet( peer->cancelsSentToPeer, now, msec );
     2576                const int blocks = tr_historyGet( peer->blocksSentToClient, now, CANCEL_HISTORY_SEC );
     2577                const int cancels = tr_historyGet( peer->cancelsSentToPeer, now, CANCEL_HISTORY_SEC );
    25782578
    25792579                if( !blocks && !cancels )
  • trunk/libtransmission/peer-msgs.c

    r11349 r11425  
    14591459            tr_peerIoReadUint32( msgs->peer->io, inbuf, &r.offset );
    14601460            tr_peerIoReadUint32( msgs->peer->io, inbuf, &r.length );
    1461             tr_historyAdd( msgs->peer->cancelsSentToClient, tr_time_msec( ), 1 );
     1461            tr_historyAdd( msgs->peer->cancelsSentToClient, tr_time( ), 1 );
    14621462            dbgmsg( msgs, "got a Cancel %u:%u->%u", r.index, r.offset, r.length );
    14631463
     
    19341934                bytesWritten += EVBUFFER_LENGTH( out );
    19351935                msgs->clientSentAnythingAt = now;
    1936                 tr_historyAdd( msgs->peer->blocksSentToPeer, tr_time_msec( ), 1 );
     1936                tr_historyAdd( msgs->peer->blocksSentToPeer, tr_time( ), 1 );
    19371937            }
    19381938
Note: See TracChangeset for help on using the changeset viewer.