Changeset 7159


Ignore:
Timestamp:
Nov 26, 2008, 3:58:26 PM (12 years ago)
Author:
charles
Message:

(libT) slightly more accurate reporting of piece data vs. raw data

Location:
trunk/libtransmission
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/bandwidth.c

    r7157 r7159  
    242242
    243243#if 0
    244 #define DEBUG_DIRECTION TR_DOWN
     244#define DEBUG_DIRECTION TR_UP
    245245#endif
    246246
     
    250250                      int             period_msec )
    251251{
    252     const double currentSpeed = tr_bandwidthGetPieceSpeed( b, dir ); /* KiB/s */
    253     const double desiredSpeed = b->band[dir].desiredSpeed;           /* KiB/s */
    254     const double seconds_per_pulse = period_msec / 1000.0;
    255     const double current_bytes_per_pulse = currentSpeed * 1024.0 * seconds_per_pulse;
    256     const double desired_bytes_per_pulse = desiredSpeed * 1024.0 * seconds_per_pulse;
    257     const double pulses_per_history = (double)HISTORY_MSEC / period_msec;
    258     const double min = desired_bytes_per_pulse * 0.90;
    259     const double max = desired_bytes_per_pulse * 1.20;
    260     const double next_pulse_bytes = desired_bytes_per_pulse * ( pulses_per_history + 1 )
    261                                   - ( current_bytes_per_pulse * pulses_per_history );
    262     double clamped;
    263 
    264     /* clamp the return value to lessen oscillation */
    265     clamped = next_pulse_bytes;
    266     clamped = MAX( clamped, min );
    267     clamped = MIN( clamped, max );
    268     b->band[dir].bytesLeft = clamped;
     252    double clamped = 0;
     253
     254    assert( isBandwidth( b ) );
     255    assert( isDirection( dir ) );
     256
     257    if( b->band[dir].isLimited )
     258    {
     259        const double currentSpeed = tr_bandwidthGetPieceSpeed( b, dir ); /* KiB/s */
     260        const double desiredSpeed = b->band[dir].desiredSpeed;           /* KiB/s */
     261        const double seconds_per_pulse = period_msec / 1000.0;
     262        const double current_bytes_per_pulse = currentSpeed * 1024.0 * seconds_per_pulse;
     263        const double desired_bytes_per_pulse = desiredSpeed * 1024.0 * seconds_per_pulse;
     264        const double pulses_per_history = (double)HISTORY_MSEC / period_msec;
     265        const double min = desired_bytes_per_pulse * 0.85;
     266        const double max = desired_bytes_per_pulse * 1.15;
     267        const double next_pulse_bytes = desired_bytes_per_pulse * ( pulses_per_history + 1 )
     268                                      - ( current_bytes_per_pulse * pulses_per_history );
     269
     270        /* clamp the return value to lessen oscillation */
     271        clamped = next_pulse_bytes;
     272        clamped = MAX( clamped, min );
     273        clamped = MIN( clamped, max );
     274
     275        b->band[dir].bytesLeft = clamped;
    269276
    270277#ifdef DEBUG_DIRECTION
    271 if( dir == DEBUG_DIRECTION )
    272 fprintf( stderr, "bandwidth %p currentSpeed(%5.2f) desiredSpeed(%5.2f), allocating %5.2f (unclamped: %5.2f)\n",
    273          b, currentSpeed, desiredSpeed,
    274          clamped/1024.0, next_pulse_bytes/1024.0 );
     278        if( dir == DEBUG_DIRECTION )
     279                fprintf( stderr, "bandwidth %p currentPieceSpeed(%5.2f of %5.2f) desiredSpeed(%5.2f), allocating %5.2f (unclamped: %5.2f)\n",
     280                         b, currentSpeed, tr_bandwidthGetRawSpeed( b, dir ), desiredSpeed,
     281                         clamped/1024.0, next_pulse_bytes/1024.0 );
    275282#endif
     283    }
    276284
    277285    /* notify the io buffers that there's more bandwidth available */
    278     if( !b->band[dir].isLimited || ( clamped > 0 ) ) {
     286    if( !b->band[dir].isLimited || ( clamped > 0.001 ) )
     287    {
    279288        int i, n=0;
    280289        short what = dir==TR_UP ? EV_WRITE : EV_READ;
    281290        struct tr_iobuf ** iobufs = (struct tr_iobuf**) tr_ptrArrayPeek( b->iobufs, &n );
    282291#ifdef DEBUG_DIRECTION
    283 if( dir == DEBUG_DIRECTION )
     292if( ( dir == DEBUG_DIRECTION ) && ( n > 1 ) )
    284293fprintf( stderr, "bandwidth %p has %d iobufs\n", b, n );
    285294#endif
     
    370379{
    371380    struct tr_band * band;
     381    size_t oldBytesLeft;
    372382
    373383    assert( isBandwidth( b ) );
     
    375385
    376386    band = &b->band[dir];
     387
     388    oldBytesLeft = band->bytesLeft;
    377389
    378390    if( band->isLimited && isPieceData )
     
    380392
    381393#ifdef DEBUG_DIRECTION
    382 if( ( dir == DEBUG_DIRECTION ) && band->isLimited && isPieceData )
    383 fprintf( stderr, "%p consumed %zu bytes of piece data... %zu left\n", b, byteCount, band->bytesLeft );
     394if( ( dir == DEBUG_DIRECTION ) && ( band->isLimited ) )
     395fprintf( stderr, "%p consumed %5zu bytes of %5s data... was %6zu, now %6zu left\n",
     396         b, byteCount, (isPieceData?"piece":"raw"), oldBytesLeft, band->bytesLeft );
    384397#endif
    385398
  • trunk/libtransmission/peer-io.c

    r7156 r7159  
    4040
    4141static size_t
    42 addPacketOverhead( size_t d )
     42getPacketOverhead( size_t d )
    4343{
    4444    /**
     
    6060    static const double assumed_payload_data_rate = 94.0;
    6161
    62     return (size_t)( d * ( 100.0 / assumed_payload_data_rate ) );
     62    return (size_t)( d * ( 100.0 / assumed_payload_data_rate ) - d );
    6363}
    6464
     
    128128    {
    129129        struct tr_datatype * next = io->output_datatypes->data;
    130         const size_t chunk_length = MIN( next->length, bytes_transferred );
    131         const size_t n = addPacketOverhead( chunk_length );
    132 
    133         tr_bandwidthUsed( io->bandwidth, TR_UP, n, next->isPieceData );
     130        const size_t payload = MIN( next->length, bytes_transferred );
     131        const size_t overhead = getPacketOverhead( payload );
     132
     133        tr_bandwidthUsed( io->bandwidth, TR_UP, payload, next->isPieceData );
     134
     135        if( overhead > 0 )
     136            tr_bandwidthUsed( io->bandwidth, TR_UP, overhead, FALSE );
    134137
    135138        if( io->didWrite )
    136             io->didWrite( io, n, next->isPieceData, io->userData );
    137 
    138         bytes_transferred -= chunk_length;
    139         next->length -= chunk_length;
     139            io->didWrite( io, payload, next->isPieceData, io->userData );
     140
     141        bytes_transferred -= payload;
     142        next->length -= payload;
    140143        if( !next->length )
    141144            tr_free( tr_list_pop_front( &io->output_datatypes ) );
  • trunk/libtransmission/peer-mgr.c

    r7154 r7159  
    5858   
    5959    /* how frequently to reallocate bandwidth */
    60     BANDWIDTH_PERIOD_MSEC = 200,
     60    BANDWIDTH_PERIOD_MSEC = 250,
    6161
    6262    /* max # of peers to ask fer per torrent per reconnect pulse */
Note: See TracChangeset for help on using the changeset viewer.