use of com.biglybt.core.speedmanager.SpeedManagerPingMapper in project BiglyBT by BiglySoftware.
the class SpeedLimitMonitor method logPingMapData.
// hadChockingPing
/**
* Just log this data until we decide if it is useful.
*/
public void logPingMapData() {
if (!useVariancePingMap) {
int downLimGuess = pingMapOfDownloadMode.guessDownloadLimit();
int upLimGuess = pingMapOfDownloadMode.guessUploadLimit();
int seedingUpLimGuess = pingMapOfSeedingMode.guessUploadLimit();
StringBuilder sb = new StringBuilder("ping-map: ");
sb.append(":down=").append(downLimGuess);
sb.append(":up=").append(upLimGuess);
sb.append(":(seed)up=").append(seedingUpLimGuess);
SpeedManagerLogger.log(sb.toString());
} else {
SMInstance pm = SMInstance.getInstance();
SpeedManagerAlgorithmProviderAdapter adapter = pm.getAdapter();
SpeedManagerPingMapper persistentMap = adapter.getPingMapper();
SpeedManagerLimitEstimate estUp = persistentMap.getEstimatedUploadLimit(false);
SpeedManagerLimitEstimate estDown = persistentMap.getEstimatedDownloadLimit(false);
int downLimGuess = estDown.getBytesPerSec();
float downConf = estDown.getMetricRating();
int upLimGuess = estUp.getBytesPerSec();
float upConf = estUp.getMetricRating();
String name = persistentMap.getName();
StringBuilder sb = new StringBuilder("new-ping-map: ");
sb.append(" name=").append(name);
sb.append(", down=").append(downLimGuess);
sb.append(", down-conf=").append(downConf);
sb.append(", up=").append(upLimGuess);
sb.append(", up-conf=").append(upConf);
SpeedManagerLogger.log(sb.toString());
}
}
use of com.biglybt.core.speedmanager.SpeedManagerPingMapper in project BiglyBT by BiglySoftware.
the class SpeedLimitMonitor method guessUploadLimit.
// guessDownloadLimit
public int guessUploadLimit() {
if (!useVariancePingMap) {
int dmUpLimitGuess = pingMapOfDownloadMode.guessUploadLimit();
int smUpLimitGuess = pingMapOfSeedingMode.guessUploadLimit();
return Math.max(dmUpLimitGuess, smUpLimitGuess);
} else {
boolean wasChocked = true;
SpeedManagerLimitEstimate transientEst = null;
if (transientPingMap != null) {
transientEst = transientPingMap.getLastBadUploadLimit();
if (transientEst == null) {
wasChocked = false;
transientEst = transientPingMap.getEstimatedUploadLimit(false);
}
}
// NOTE: Currently just getting the persistentMap for temp logging purposes.
SMInstance pm = SMInstance.getInstance();
SpeedManagerAlgorithmProviderAdapter adapter = pm.getAdapter();
SpeedManagerPingMapper persistentMap = adapter.getPingMapper();
SpeedManagerLimitEstimate persistentEst = persistentMap.getEstimatedUploadLimit(false);
// log the different ping-mappers for beta.
betaLogPingMapperEstimates("up", transientEst, wasChocked, persistentEst, pingMapOfDownloadMode, pingMapOfSeedingMode);
if (transientEst != null) {
return choseBestLimit(transientEst, uploadLimitMax, uploadLimitConf);
} else {
return uploadLimitMax;
}
}
}
use of com.biglybt.core.speedmanager.SpeedManagerPingMapper in project BiglyBT by BiglySoftware.
the class PingSpaceMon method getDownloadLimit.
/**
* Get the current estimated download limit from the ping mapper.
* @return - SpeedManagerLimitEstimate
*/
public static SpeedManagerLimitEstimate getDownloadLimit() {
try {
SMInstance pm = SMInstance.getInstance();
SpeedManagerAlgorithmProviderAdapter adapter = pm.getAdapter();
SpeedManagerPingMapper persistentMap = adapter.getPingMapper();
SpeedManagerLimitEstimate downEst = persistentMap.getEstimatedDownloadLimit(true);
return downEst;
} catch (Throwable t) {
// log this event and
SpeedManagerLogger.log(t.toString());
t.printStackTrace();
// something to return 0 and -1.0f results.
return new DefaultLimitEstimate();
}
}
use of com.biglybt.core.speedmanager.SpeedManagerPingMapper in project BiglyBT by BiglySoftware.
the class DownloadManagerRateController method update.
static void update() {
tick_count++;
if ((!enable_limit_handling) || pm_map.size() == 0 || NetworkManager.isSeedingOnlyUploadRate() || NetworkManager.getMaxUploadRateBPSNormal() != 0 || core == null || speed_manager == null || speed_manager.getSpeedTester() == null) {
rate_limit = 0;
return;
}
int num_complete = 0;
int num_incomplete = 0;
int num_interesting = 0;
int i_up_total = 0;
int c_up_total = 0;
long mono_now = SystemTime.getMonotonousTime();
for (Map.Entry<PEPeerManager, PMState> entry : pm_map.entrySet()) {
PEPeerManager pm = entry.getKey();
PMState state = entry.getValue();
boolean is_complete = !pm.hasDownloadablePiece();
PEPeerManagerStats pm_stats = pm.getStats();
long up_bytes = pm_stats.getTotalDataBytesSentNoLan() + pm_stats.getTotalProtocolBytesSentNoLan();
long diff = state.setBytesUp(up_bytes);
if (is_complete) {
num_complete++;
c_up_total += diff;
} else {
num_incomplete++;
i_up_total += diff;
if (state.isInteresting(mono_now)) {
num_interesting++;
}
}
if (state.isComplete() != is_complete) {
if (is_complete) {
pm.addRateLimiter(limiter, true);
} else {
pm.removeRateLimiter(limiter, true);
}
state.setComplete(is_complete);
}
}
if (num_incomplete == 0 || num_complete == 0 || num_interesting == 0) {
rate_limit = 0;
return;
}
boolean skipped_tick = false;
if (last_tick_processed != tick_count - 1) {
pm_last_bad_limit = 0;
latest_choke = 0;
wait_until_tick = 0;
ticks_to_sample_start = 0;
sample_num = 0;
incomplete_samples = 0;
complete_samples = 0;
skipped_tick = true;
}
last_tick_processed = tick_count;
if (skipped_tick || tick_count < wait_until_tick) {
return;
}
try {
long real_now = SystemTime.getCurrentTime();
SpeedManagerPingMapper mapper = speed_manager.getActiveMapper();
if (rate_limit == 0) {
rate_limit = speed_manager.getEstimatedUploadCapacityBytesPerSec().getBytesPerSec();
if (rate_limit == 0) {
rate_limit = DEFAULT_UP_LIMIT;
}
}
SpeedManagerLimitEstimate last_bad = mapper.getLastBadUploadLimit();
if (last_bad != null) {
int last_bad_limit = last_bad.getBytesPerSec();
if (last_bad_limit != pm_last_bad_limit) {
pm_last_bad_limit = last_bad_limit;
SpeedManagerLimitEstimate[] bad_ups = mapper.getBadUploadHistory();
int total = last_bad.getBytesPerSec();
int count = 1;
for (SpeedManagerLimitEstimate bad : bad_ups) {
long t = bad.getWhen();
if (real_now - t <= 30 * 1000 && bad.getBytesPerSec() != last_bad_limit) {
total += bad.getBytesPerSec();
count++;
}
}
latest_choke = total / count;
int new_rate_limit;
if (rate_limit == 0) {
new_rate_limit = latest_choke / 2;
} else {
new_rate_limit = rate_limit / 2;
}
if (new_rate_limit < slack_bytes_per_sec) {
new_rate_limit = slack_bytes_per_sec;
}
rate_limit = new_rate_limit;
wait_until_tick = tick_count + WAIT_AFTER_CHOKE_TICKS;
ticks_to_sample_start = 0;
sample_num = 0;
complete_samples = 0;
incomplete_samples = 0;
last_rate_limit = 0;
return;
}
}
if (ticks_to_sample_start > 0) {
ticks_to_sample_start--;
} else if (sample_num < SAMPLE_COUNT) {
complete_samples += c_up_total;
incomplete_samples += i_up_total;
sample_num++;
} else {
double incomplete_average = incomplete_samples / SAMPLE_COUNT;
double complete_average = complete_samples / SAMPLE_COUNT;
double overall_average = (complete_samples + incomplete_samples) / SAMPLE_COUNT;
int action = -1;
try {
if (last_rate_limit == 0) {
action = 1;
} else {
double overall_change = overall_average - last_overall_average;
if (overall_change < 0) {
if (rate_limit < last_rate_limit) {
// System.out.println( "average decreased" );
action = 1;
} else {
action = 0;
}
} else {
double last_ratio = last_incomplete_average / last_complete_average;
double ratio = incomplete_average / complete_average;
if (rate_limit < last_rate_limit && ratio >= last_ratio) {
action = -1;
} else if (rate_limit > last_rate_limit && ratio <= last_ratio) {
double i_up_change = incomplete_average - last_incomplete_average;
if (i_up_change >= 1024) {
action = -1;
} else {
action = 1;
}
} else {
action = 1;
}
}
}
} finally {
int new_rate_limit;
if (action > 0) {
int ceiling = latest_choke == 0 ? DEFAULT_UP_LIMIT : latest_choke;
int diff = (ceiling - rate_limit) / 4;
if (diff > MAX_UP_DIFF) {
diff = MAX_UP_DIFF;
} else if (diff < MIN_DIFF) {
diff = MIN_DIFF;
}
new_rate_limit = rate_limit + diff;
if (new_rate_limit > 100 * 1024 * 1024) {
new_rate_limit = 100 * 1024 * 1024;
}
} else if (action < 0) {
int diff = rate_limit / 5;
if (diff > MAX_DOWN_DIFF) {
diff = MAX_DOWN_DIFF;
} else if (diff < MIN_DIFF) {
diff = MIN_DIFF;
}
new_rate_limit = rate_limit - diff;
if (new_rate_limit < slack_bytes_per_sec) {
new_rate_limit = slack_bytes_per_sec;
}
} else {
new_rate_limit = rate_limit;
}
last_rate_limit = rate_limit;
last_overall_average = overall_average;
last_complete_average = complete_average;
last_incomplete_average = incomplete_average;
rate_limit = new_rate_limit;
sample_num = 0;
complete_samples = 0;
incomplete_samples = 0;
}
}
} finally {
// System.out.println( "rate=" + DisplayFormatters.formatByteCountToKiBEtcPerSec( rate_limit ) + ", last_choke=" + latest_choke );
}
}
use of com.biglybt.core.speedmanager.SpeedManagerPingMapper in project BiglyBT by BiglySoftware.
the class SpeedLimitMonitor method guessDownloadLimit.
// betaLogPingMapperEstimates
public int guessDownloadLimit() {
if (!useVariancePingMap) {
return pingMapOfDownloadMode.guessDownloadLimit();
} else {
boolean wasChocked = true;
SpeedManagerLimitEstimate transientEst = null;
if (transientPingMap != null) {
transientEst = transientPingMap.getLastBadDownloadLimit();
if (transientEst == null) {
wasChocked = false;
transientEst = transientPingMap.getEstimatedDownloadLimit(false);
}
}
// NOTE: Currently just getting the persistentMap for temp logging purposes.
SMInstance pm = SMInstance.getInstance();
SpeedManagerAlgorithmProviderAdapter adapter = pm.getAdapter();
SpeedManagerPingMapper persistentMap = adapter.getPingMapper();
SpeedManagerLimitEstimate persistentEst = persistentMap.getEstimatedDownloadLimit(false);
// log the different ping-mappers for beta.
betaLogPingMapperEstimates("down", transientEst, wasChocked, persistentEst, pingMapOfDownloadMode, pingMapOfSeedingMode);
if (transientEst != null) {
return choseBestLimit(transientEst, downloadLimitMax, downloadLimitConf);
} else {
return downloadLimitMax;
}
}
}
Aggregations