* 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
private double _speedValueNew;
private double _capacityValueNew;
private double _integrationValueNew;
private boolean _isFailingNew;
// are we in coalescing state?
private boolean _coalescing;
// good vs bad behavior
@ -515,6 +513,10 @@ public class PeerProfile {
_log.debug("Coalesced: speed [" + _speedValue + "] capacity [" + _capacityValue + "] integration [" + _integrationValue + "] failing? [" + _isFailing + "]");
}
/**
* Caller must next call updateValues()
* @since 0.9.4
*/
void coalesceOnly() {
_coalescing = true;
@ -533,10 +535,18 @@ public class PeerProfile {
_speedValueNew = calculateSpeed();
_capacityValueNew = calculateCapacity();
_integrationValueNew = calculateIntegration();
_isFailingNew = calculateIsFailing();
// These two are not used by InverseCapacityComparator
// 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() {
if (!_coalescing) // can happen
coalesceOnly();
@ -544,8 +554,6 @@ public class PeerProfile {
_speedValue = _speedValueNew;
_capacityValue = _capacityValueNew;
_integrationValue = _integrationValueNew;
_isFailing = _isFailingNew;
}
private double calculateSpeed() { return SpeedCalculator.calc(this); }

View File

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