use of com.biglybt.core.speedmanager.SpeedManagerPingSource in project BiglyBT by BiglySoftware.
the class TransferStatsView method periodicUpdate.
/* (non-Javadoc)
* @see com.biglybt.ui.swt.views.stats.PeriodicViewUpdate#periodicUpdate()
*/
public void periodicUpdate() {
if (speedManager == null) {
return;
}
if (speedManager.isAvailable()) {
// && speedManager.isEnabled()) {
SpeedManagerPingSource[] sources = speedManager.getPingSources();
if (sources.length > 0) {
int[] pings = new int[sources.length];
for (int i = 0; i < sources.length; i++) {
SpeedManagerPingSource source = sources[i];
if (source != null) {
int ping = source.getPingTime();
ping = Math.min(ping, MAX_DISPLAYED_PING_MILLIS);
pings[i] = ping;
}
}
pingGraph.addIntsValue(pings);
if (plot_views != null) {
for (plotView view : plot_views) {
if (view != null) {
view.update();
}
}
}
if (zone_views != null) {
for (zoneView view : zone_views) {
if (view != null) {
view.update();
}
}
}
}
}
}
use of com.biglybt.core.speedmanager.SpeedManagerPingSource in project BiglyBT by BiglySoftware.
the class PingSourceManager method forcePingSourceChange.
// checkPingSources
/**
* If one ping source is twice the fastest then replace it. Otherwise reset the timer.
* @param sources -
* @return - true is a souce has been changed.
*/
private boolean forcePingSourceChange(SpeedManagerPingSource[] sources) {
// We only apply this rule if nothing has been removed in the past 30 minutes.
long currTime = SystemTime.getCurrentTime();
if (currTime < lastPingRemoval + TIME_BETWEEN_FORCED_CYCLE_REMOVALS) {
return false;
}
if (sources.length < 3) {
return false;
}
// just find the slowest ping-source and remove it.
SpeedManagerPingSource slowestSource = null;
double slowestPing = 0.0;
double fastestPing = 10000.0;
int len = sources.length;
for (int i = 0; i < len; i++) {
PingSourceStats pss = (PingSourceStats) pingAverages.get(sources[i]);
Average ave = pss.getHistory();
double pingTime = ave.getAverage();
// find slowest
if (pingTime > slowestPing) {
slowestPing = pingTime;
slowestSource = sources[i];
}
// find sped of fastest.
if (pingTime < fastestPing) {
fastestPing = pingTime;
}
}
// for
// regardless of result, resetTimer the timer.
resetTimer();
// only replace the slowest if it is twice the fastest.
if (slowestPing > 2 * fastestPing) {
if (slowestSource != null) {
slowestSource.destroy();
return true;
}
}
return false;
}
use of com.biglybt.core.speedmanager.SpeedManagerPingSource in project BiglyBT by BiglySoftware.
the class PingSourceManager method checkForSlowSource.
// forcePingSourceChange
/**
* A slow source is something that is 2x the slower then the two fastest.
* @param sources -
* @return - true is a source has been removed.
*/
private boolean checkForSlowSource(SpeedManagerPingSource[] sources) {
// We only apply this rule if nothing has been removed in the past 15 minutes.
long currTime = SystemTime.getCurrentTime();
if (currTime < lastPingRemoval + TIME_BETWEEN_SLOW_PING_REMOVALS) {
return false;
}
SpeedManagerPingSource slowestSource = null;
if (sources.length < 3) {
return false;
}
double fastA = 10000.0;
double fastB = 10000.0;
double slowest = 0.0;
int len = sources.length;
for (int i = 0; i < len; i++) {
PingSourceStats pss = (PingSourceStats) pingAverages.get(sources[i]);
Average ave = pss.getHistory();
double pingTime = ave.getAverage();
// determine fastest or second fastest.
if (pingTime < fastA) {
fastB = fastA;
fastA = pingTime;
} else if (pingTime < fastB) {
fastB = pingTime;
}
// determine slowest.
if (pingTime > slowest) {
slowest = pingTime;
slowestSource = sources[i];
resetTimer();
}
}
// for
double sumFastest = fastA + fastB;
boolean removedSource = false;
if (sumFastest * 2 < slowest) {
// destroy this source. It is a bit too slow.
if (slowestSource != null) {
slowestSource.destroy();
SpeedManagerLogger.log("dropping ping source: " + slowestSource.getAddress() + " for being 2x slower then two fastest.");
removedSource = true;
resetTimer();
}
}
return removedSource;
}
use of com.biglybt.core.speedmanager.SpeedManagerPingSource in project BiglyBT by BiglySoftware.
the class PingSourceManager method checkForBadPing.
// checkForSlowSource
/**
* If the slowest ping in 10x the fastest then remove it.
* @param sources -
* @return - true is a source has been removed.
*/
private boolean checkForBadPing(SpeedManagerPingSource[] sources) {
// if we just recently removed a ping source then wait.
long currTime = SystemTime.getCurrentTime();
if (currTime < lastPingRemoval + TIME_BETWEEN_BAD_PING_REMOVALS) {
return false;
}
double highestLongTermPing = 0.0;
SpeedManagerPingSource highestSource = null;
double lowestLongTermPing = 10000.0;
int len = sources.length;
for (int i = 0; i < len; i++) {
PingSourceStats pss = (PingSourceStats) pingAverages.get(sources[i]);
if (pss == null) {
continue;
}
Average a = pss.getLongTermAve();
double avePingTime = a.getAverage();
// is this a new highest value?
if (avePingTime > highestLongTermPing) {
highestLongTermPing = avePingTime;
highestSource = sources[i];
}
// is this a new lowest value?
if (avePingTime < lowestLongTermPing) {
lowestLongTermPing = avePingTime;
}
}
// for
boolean removedSource = false;
// if the highest value is 8x the lowest then find another source.
if (lowestLongTermPing * 8 < highestLongTermPing) {
// remove the slow source we will get a new one to replace it.
if (highestSource != null) {
SpeedManagerLogger.log("dropping ping source: " + highestSource.getAddress() + " for being 8x greater then min source.");
highestSource.destroy();
removedSource = true;
resetTimer();
}
}
return removedSource;
}
Aggregations