Changeset 9044


Ignore:
Timestamp:
Sep 6, 2009, 2:05:06 PM (13 years ago)
Author:
charles
Message:

(trunk libT) #2383: Faster verification for local data with small piece size

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/verify.c

    r8931 r9044  
    3636***/
    3737
     38enum
     39{
     40    MSEC_TO_SLEEP_PER_SECOND_DURING_VERIFY = 200
     41};
     42
    3843/* #define STOPWATCH */
    3944
     
    4651    tr_bool changed = 0;
    4752    tr_bool hadPiece = 0;
     53    time_t lastSleptAt = 0;
    4854    uint32_t piecePos = 0;
    4955    uint32_t pieceBytesRead = 0;
     
    5359    uint8_t * buffer = tr_new( uint8_t, buflen );
    5460#ifdef STOPWATCH
    55     time_t now = time( NULL );
     61    const time_t begin = time( NULL );
    5662#endif
    5763
     
    106112        if( leftInPiece == 0 )
    107113        {
     114            time_t now;
    108115            tr_bool hasPiece;
    109116            uint8_t hash[SHA_DIGEST_LENGTH];
     
    122129            }
    123130            tr_torrentSetPieceChecked( tor, pieceIndex, TRUE );
    124             tor->anyDate = time( NULL );
    125 
    126             /* going full-throttle on a verify can choke other processes'
    127              * disk IO, so wait a fwe msec between pieces.
    128              * The msec is arbitrary, and the "if" clause is to make sure we
    129              * don't slow down verification of files that don't exist */
    130             if( pieceBytesRead == tr_torPieceCountBytes( tor, pieceIndex ) )
    131                 tr_wait( 50 );
     131            now = time( NULL );
     132            tor->anyDate = now;
     133
     134            /* sleeping even just a few msec per second goes a long
     135             * way towards reducing IO load... */
     136            if( lastSleptAt != now ) {
     137                lastSleptAt = now;
     138                tr_wait( MSEC_TO_SLEEP_PER_SECOND_DURING_VERIFY );
     139            }
    132140
    133141            SHA1_Init( &sha );
     
    154162#ifdef STOPWATCH
    155163{
    156     time_t now2 = time( NULL );
     164    const time_t end = time( NULL );
    157165    fprintf( stderr, "it took %d seconds to verify %"PRIu64" bytes (%"PRIu64" bytes per second)\n",
    158              (int)(now2-now), tor->info.totalSize, (uint64_t)(tor->info.totalSize/(1+(now2-now))) );
     166             (int)(end-begin), tor->info.totalSize, (uint64_t)(tor->info.totalSize/(1+(end-begin))) );
    159167}
    160168#endif
Note: See TracChangeset for help on using the changeset viewer.