1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2025-03-03 18:25:35 +00:00

(libT) eliminate some duplicate calls to time(NULL) that showed a spike on vraa & softwareelves' shark profiles

This commit is contained in:
Charles Kerr 2008-10-27 04:12:42 +00:00
parent 90317da46e
commit a4bee061be

View file

@ -597,7 +597,8 @@ void
tr_peerMsgsSetChoke( tr_peermsgs * msgs, tr_peerMsgsSetChoke( tr_peermsgs * msgs,
int choke ) int choke )
{ {
const time_t fibrillationTime = time( NULL ) - MIN_CHOKE_PERIOD_SEC; const time_t now = time( NULL );
const time_t fibrillationTime = now - MIN_CHOKE_PERIOD_SEC;
assert( msgs ); assert( msgs );
assert( msgs->info ); assert( msgs->info );
@ -614,7 +615,7 @@ tr_peerMsgsSetChoke( tr_peermsgs * msgs,
if( choke ) if( choke )
cancelAllRequestsToClientExceptFast( msgs ); cancelAllRequestsToClientExceptFast( msgs );
protocolSendChoke( msgs, choke ); protocolSendChoke( msgs, choke );
msgs->info->chokeChangedAt = time( NULL ); msgs->info->chokeChangedAt = now;
} }
} }
@ -767,14 +768,14 @@ requestIsValid( const tr_peermsgs * msgs, const struct peer_request * req )
} }
static void static void
expireOldRequests( tr_peermsgs * msgs ) expireOldRequests( tr_peermsgs * msgs, const time_t now )
{ {
int i; int i;
time_t oldestAllowed; time_t oldestAllowed;
struct request_list tmp = REQUEST_LIST_INIT; struct request_list tmp = REQUEST_LIST_INIT;
/* cancel requests that have been queued for too long */ /* cancel requests that have been queued for too long */
oldestAllowed = time( NULL ) - QUEUED_REQUEST_TTL_SECS; oldestAllowed = now - QUEUED_REQUEST_TTL_SECS;
reqListCopy( &tmp, &msgs->clientWillAskFor ); reqListCopy( &tmp, &msgs->clientWillAskFor );
for( i = 0; i < tmp.count; ++i ) for( i = 0; i < tmp.count; ++i )
{ {
@ -785,7 +786,7 @@ expireOldRequests( tr_peermsgs * msgs )
reqListClear( &tmp ); reqListClear( &tmp );
/* cancel requests that were sent too long ago */ /* cancel requests that were sent too long ago */
oldestAllowed = time( NULL ) - SENT_REQUEST_TTL_SECS; oldestAllowed = now - SENT_REQUEST_TTL_SECS;
reqListCopy( &tmp, &msgs->clientAskedFor ); reqListCopy( &tmp, &msgs->clientAskedFor );
for( i = 0; i < tmp.count; ++i ) for( i = 0; i < tmp.count; ++i )
{ {
@ -797,11 +798,10 @@ expireOldRequests( tr_peermsgs * msgs )
} }
static void static void
pumpRequestQueue( tr_peermsgs * msgs ) pumpRequestQueue( tr_peermsgs * msgs, const time_t now )
{ {
const int max = msgs->maxActiveRequests; const int max = msgs->maxActiveRequests;
const int min = msgs->minActiveRequests; const int min = msgs->minActiveRequests;
const time_t now = time( NULL );
int sent = 0; int sent = 0;
int count = msgs->clientAskedFor.count; int count = msgs->clientAskedFor.count;
struct peer_request req; struct peer_request req;
@ -1535,9 +1535,10 @@ readBtMessage( tr_peermsgs * msgs,
static void static void
peerGotBytes( tr_peermsgs * msgs, peerGotBytes( tr_peermsgs * msgs,
uint32_t byteCount ) uint32_t byteCount,
const time_t now )
{ {
msgs->info->pieceDataActivityDate = time( NULL ); msgs->info->pieceDataActivityDate = now;
firePeerGotData( msgs, byteCount ); firePeerGotData( msgs, byteCount );
} }
@ -1706,8 +1707,8 @@ peerPulse( void * vmsgs )
ratePulse( msgs ); ratePulse( msgs );
/*tr_peerIoTryRead( msgs->io );*/ /*tr_peerIoTryRead( msgs->io );*/
pumpRequestQueue( msgs ); pumpRequestQueue( msgs, now );
expireOldRequests( msgs ); expireOldRequests( msgs, now );
if( msgs->sendingBlock ) if( msgs->sendingBlock )
{ {
@ -1719,10 +1720,9 @@ peerPulse( void * vmsgs )
if( outlen ) if( outlen )
{ {
tr_peerIoWrite( msgs->io, EVBUFFER_DATA( tr_peerIoWrite( msgs->io, EVBUFFER_DATA( msgs->outBlock ), outlen );
msgs->outBlock ), outlen );
evbuffer_drain( msgs->outBlock, outlen ); evbuffer_drain( msgs->outBlock, outlen );
peerGotBytes( msgs, outlen ); peerGotBytes( msgs, outlen, now );
len -= outlen; len -= outlen;
msgs->clientSentAnythingAt = now; msgs->clientSentAnythingAt = now;
@ -1733,15 +1733,13 @@ peerPulse( void * vmsgs )
} }
else dbgmsg( msgs, else dbgmsg( msgs,
"stalled writing block... uploadMax %lu, outlen %lu", "stalled writing block... uploadMax %lu, outlen %lu",
uploadMax, uploadMax, outlen );
outlen );
} }
if( !msgs->sendingBlock ) if( !msgs->sendingBlock )
{ {
struct peer_request req; struct peer_request req;
int haveMessages = EVBUFFER_LENGTH( const int haveMessages = EVBUFFER_LENGTH( msgs->outMessages ) != 0;
msgs->outMessages ) != 0;
if( haveMessages && !msgs->outMessagesBatchedAt ) /* fresh batch */ if( haveMessages && !msgs->outMessagesBatchedAt ) /* fresh batch */
{ {