* Profiles: Small optimization in coalesceOnly() (ticket #765)

javadoc, detab
This commit is contained in:
zzz
2012-11-24 16:41:12 +00:00
parent 1d3bbfd250
commit b2e335fbba
2 changed files with 21 additions and 13 deletions

View File

@ -57,8 +57,6 @@ public class PeerProfile {
// new calculation values, to be updated // new calculation values, to be updated
private double _speedValueNew; private double _speedValueNew;
private double _capacityValueNew; private double _capacityValueNew;
private double _integrationValueNew;
private boolean _isFailingNew;
// are we in coalescing state? // are we in coalescing state?
private boolean _coalescing; private boolean _coalescing;
// good vs bad behavior // good vs bad behavior
@ -515,6 +513,10 @@ public class PeerProfile {
_log.debug("Coalesced: speed [" + _speedValue + "] capacity [" + _capacityValue + "] integration [" + _integrationValue + "] failing? [" + _isFailing + "]"); _log.debug("Coalesced: speed [" + _speedValue + "] capacity [" + _capacityValue + "] integration [" + _integrationValue + "] failing? [" + _isFailing + "]");
} }
/**
* Caller must next call updateValues()
* @since 0.9.4
*/
void coalesceOnly() { void coalesceOnly() {
_coalescing = true; _coalescing = true;
@ -533,10 +535,18 @@ public class PeerProfile {
_speedValueNew = calculateSpeed(); _speedValueNew = calculateSpeed();
_capacityValueNew = calculateCapacity(); _capacityValueNew = calculateCapacity();
_integrationValueNew = calculateIntegration(); // These two are not used by InverseCapacityComparator
_isFailingNew = calculateIsFailing(); // to sort _strictCapacityOrder in ProfileOrganizer
// (in fact aren't really used at all), so we can
// update them directly
_integrationValue = calculateIntegration();
_isFailing = calculateIsFailing();
} }
/**
* Copy over the new values generated by coalesceOnly()
* @since 0.9.4
*/
void updateValues() { void updateValues() {
if (!_coalescing) // can happen if (!_coalescing) // can happen
coalesceOnly(); coalesceOnly();
@ -544,8 +554,6 @@ public class PeerProfile {
_speedValue = _speedValueNew; _speedValue = _speedValueNew;
_capacityValue = _capacityValueNew; _capacityValue = _capacityValueNew;
_integrationValue = _integrationValueNew;
_isFailing = _isFailingNew;
} }
private double calculateSpeed() { return SpeedCalculator.calc(this); } private double calculateSpeed() { return SpeedCalculator.calc(this); }

View File

@ -782,9 +782,9 @@ public class ProfileOrganizer {
} }
if (shouldCoalesce) { if (shouldCoalesce) {
getReadLock(); getReadLock();
try { try {
for (Iterator<PeerProfile> iter = _strictCapacityOrder.iterator(); iter.hasNext(); ) { for (Iterator<PeerProfile> iter = _strictCapacityOrder.iterator(); iter.hasNext(); ) {
PeerProfile prof = iter.next(); PeerProfile prof = iter.next();
if ( (expireOlderThan > 0) && (prof.getLastSendSuccessful() <= expireOlderThan) ) { if ( (expireOlderThan > 0) && (prof.getLastSendSuccessful() <= expireOlderThan) ) {
continue; continue;
@ -792,10 +792,10 @@ public class ProfileOrganizer {
long coalesceStart = System.currentTimeMillis(); long coalesceStart = System.currentTimeMillis();
prof.coalesceOnly(); prof.coalesceOnly();
coalesceTime += (int)(System.currentTimeMillis()-coalesceStart); coalesceTime += (int)(System.currentTimeMillis()-coalesceStart);
} }
} finally { } finally {
releaseReadLock(); releaseReadLock();
} }
} }
if (!getWriteLock()) if (!getWriteLock())