Changeset 7159
- Timestamp:
- Nov 26, 2008, 3:58:26 PM (12 years ago)
- Location:
- trunk/libtransmission
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/libtransmission/bandwidth.c
r7157 r7159 242 242 243 243 #if 0 244 #define DEBUG_DIRECTION TR_ DOWN244 #define DEBUG_DIRECTION TR_UP 245 245 #endif 246 246 … … 250 250 int period_msec ) 251 251 { 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; 269 276 270 277 #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 ); 275 282 #endif 283 } 276 284 277 285 /* 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 { 279 288 int i, n=0; 280 289 short what = dir==TR_UP ? EV_WRITE : EV_READ; 281 290 struct tr_iobuf ** iobufs = (struct tr_iobuf**) tr_ptrArrayPeek( b->iobufs, &n ); 282 291 #ifdef DEBUG_DIRECTION 283 if( dir == DEBUG_DIRECTION)292 if( ( dir == DEBUG_DIRECTION ) && ( n > 1 ) ) 284 293 fprintf( stderr, "bandwidth %p has %d iobufs\n", b, n ); 285 294 #endif … … 370 379 { 371 380 struct tr_band * band; 381 size_t oldBytesLeft; 372 382 373 383 assert( isBandwidth( b ) ); … … 375 385 376 386 band = &b->band[dir]; 387 388 oldBytesLeft = band->bytesLeft; 377 389 378 390 if( band->isLimited && isPieceData ) … … 380 392 381 393 #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 ); 394 if( ( dir == DEBUG_DIRECTION ) && ( band->isLimited ) ) 395 fprintf( stderr, "%p consumed %5zu bytes of %5s data... was %6zu, now %6zu left\n", 396 b, byteCount, (isPieceData?"piece":"raw"), oldBytesLeft, band->bytesLeft ); 384 397 #endif 385 398 -
trunk/libtransmission/peer-io.c
r7156 r7159 40 40 41 41 static size_t 42 addPacketOverhead( size_t d )42 getPacketOverhead( size_t d ) 43 43 { 44 44 /** … … 60 60 static const double assumed_payload_data_rate = 94.0; 61 61 62 return (size_t)( d * ( 100.0 / assumed_payload_data_rate ) );62 return (size_t)( d * ( 100.0 / assumed_payload_data_rate ) - d ); 63 63 } 64 64 … … 128 128 { 129 129 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 ); 134 137 135 138 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; 140 143 if( !next->length ) 141 144 tr_free( tr_list_pop_front( &io->output_datatypes ) ); -
trunk/libtransmission/peer-mgr.c
r7154 r7159 58 58 59 59 /* how frequently to reallocate bandwidth */ 60 BANDWIDTH_PERIOD_MSEC = 2 00,60 BANDWIDTH_PERIOD_MSEC = 250, 61 61 62 62 /* max # of peers to ask fer per torrent per reconnect pulse */
Note: See TracChangeset
for help on using the changeset viewer.