mirror of
https://github.com/Qortal/altcoinj.git
synced 2025-07-31 20:11:23 +00:00
PeerGroup: Improve logging in ChainDownloadSpeedCalculator.
This commit is contained in:
@@ -1774,6 +1774,8 @@ public class PeerGroup implements TransactionBroadcaster {
|
||||
|
||||
private boolean syncDone;
|
||||
|
||||
private final Logger log = LoggerFactory.getLogger(ChainDownloadSpeedCalculator.class);
|
||||
|
||||
@Override
|
||||
public synchronized void onBlocksDownloaded(Peer peer, Block block, @Nullable FilteredBlock filteredBlock, int blocksLeft) {
|
||||
blocksInLastSecond++;
|
||||
@@ -1822,48 +1824,58 @@ public class PeerGroup implements TransactionBroadcaster {
|
||||
warmupSeconds = 15;
|
||||
}
|
||||
|
||||
int chainHeight = chain != null ? chain.getBestChainHeight() : -1;
|
||||
int mostCommonChainHeight = getMostCommonChainHeight();
|
||||
if (chain != null && mostCommonChainHeight > 0 && chain.getBestChainHeight() >= mostCommonChainHeight)
|
||||
if (!syncDone && mostCommonChainHeight > 0 && chainHeight >= mostCommonChainHeight) {
|
||||
log.info("End of sync detected.");
|
||||
syncDone = true;
|
||||
}
|
||||
|
||||
if (!syncDone) {
|
||||
if (warmupSeconds < 0) {
|
||||
// Calculate the moving average.
|
||||
samples[cursor++] = bytesInLastSecond;
|
||||
if (cursor == samples.length) cursor = 0;
|
||||
long average = 0;
|
||||
for (long sample : samples) average += sample;
|
||||
average /= samples.length;
|
||||
// Calculate the moving average.
|
||||
samples[cursor++] = bytesInLastSecond;
|
||||
if (cursor == samples.length) cursor = 0;
|
||||
long average = 0;
|
||||
for (long sample : samples) average += sample;
|
||||
average /= samples.length;
|
||||
|
||||
log.info(String.format(Locale.US, "%d blocks/sec, %d tx/sec, %d pre-filtered tx/sec, avg/last %.2f/%.2f kilobytes per sec (stall threshold <%.2f KB/sec for %d seconds)",
|
||||
blocksInLastSecond, txnsInLastSecond, origTxnsInLastSecond, average / 1024.0, bytesInLastSecond / 1024.0,
|
||||
minSpeedBytesPerSec / 1024.0, samples.length));
|
||||
|
||||
if (average < minSpeedBytesPerSec && maxStalls > 0) {
|
||||
maxStalls--;
|
||||
if (maxStalls == 0) {
|
||||
// We could consider starting to drop the Bloom filtering FP rate at this point, because
|
||||
// we tried a bunch of peers and no matter what we don't seem to be able to go any faster.
|
||||
// This implies we're bandwidth bottlenecked and might want to start using bandwidth
|
||||
// more effectively. Of course if there's a MITM that is deliberately throttling us,
|
||||
// this is a good way to make us take away all the FPs from our Bloom filters ... but
|
||||
// as they don't give us a whole lot of privacy either way that's not inherently a big
|
||||
// deal.
|
||||
log.warn("This network seems to be slower than the requested stall threshold - won't do stall disconnects any more.");
|
||||
} else {
|
||||
Peer peer = getDownloadPeer();
|
||||
log.warn(String.format(Locale.US, "Chain download stalled: received %.2f KB/sec for %d seconds, require average of %.2f KB/sec, disconnecting %s", average / 1024.0, samples.length, minSpeedBytesPerSec / 1024.0, peer));
|
||||
peer.close();
|
||||
// Reset the sample buffer and give the next peer time to get going.
|
||||
samples = null;
|
||||
warmupSeconds = period;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
String statsString = String.format(Locale.US,
|
||||
"%d blocks/sec, %d tx/sec, %d pre-filtered tx/sec, avg/last %.2f/%.2f kilobytes per sec, chain/common height %d/%d",
|
||||
blocksInLastSecond, txnsInLastSecond, origTxnsInLastSecond, average / 1024.0,
|
||||
bytesInLastSecond / 1024.0, chainHeight, mostCommonChainHeight);
|
||||
String thresholdString = String.format(Locale.US, "(threshold <%.2f KB/sec for %d seconds)",
|
||||
minSpeedBytesPerSec / 1024.0, samples.length);
|
||||
if (maxStalls <= 0) {
|
||||
log.info(statsString + ", stall disabled " + thresholdString);
|
||||
} else if (warmupSeconds > 0) {
|
||||
warmupSeconds--;
|
||||
if (bytesInLastSecond > 0)
|
||||
log.info(String.format(Locale.US, "%d blocks/sec, %d tx/sec, %d pre-filtered tx/sec, last %.2f kilobytes per sec",
|
||||
blocksInLastSecond, txnsInLastSecond, origTxnsInLastSecond, bytesInLastSecond / 1024.0));
|
||||
log.info(statsString
|
||||
+ String.format(Locale.US, " (warming up %d more seconds)", warmupSeconds));
|
||||
} else if (average < minSpeedBytesPerSec) {
|
||||
log.info(statsString + ", STALLED " + thresholdString);
|
||||
maxStalls--;
|
||||
if (maxStalls == 0) {
|
||||
// We could consider starting to drop the Bloom filtering FP rate at this point, because
|
||||
// we tried a bunch of peers and no matter what we don't seem to be able to go any faster.
|
||||
// This implies we're bandwidth bottlenecked and might want to start using bandwidth
|
||||
// more effectively. Of course if there's a MITM that is deliberately throttling us,
|
||||
// this is a good way to make us take away all the FPs from our Bloom filters ... but
|
||||
// as they don't give us a whole lot of privacy either way that's not inherently a big
|
||||
// deal.
|
||||
log.warn("This network seems to be slower than the requested stall threshold - won't do stall disconnects any more.");
|
||||
} else {
|
||||
Peer peer = getDownloadPeer();
|
||||
log.warn(String.format(Locale.US,
|
||||
"Chain download stalled: received %.2f KB/sec for %d seconds, require average of %.2f KB/sec, disconnecting %s, %d stalls left",
|
||||
average / 1024.0, samples.length, minSpeedBytesPerSec / 1024.0, peer, maxStalls));
|
||||
peer.close();
|
||||
// Reset the sample buffer and give the next peer time to get going.
|
||||
samples = null;
|
||||
warmupSeconds = period;
|
||||
}
|
||||
} else {
|
||||
log.info(statsString + ", not stalled " + thresholdString);
|
||||
}
|
||||
}
|
||||
blocksInLastSecond = 0;
|
||||
|
Reference in New Issue
Block a user