mirror of
https://github.com/Qortal/altcoinj.git
synced 2025-11-01 21:17:13 +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,12 +1824,14 @@ 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;
|
||||
@@ -1835,11 +1839,21 @@ public class PeerGroup implements TransactionBroadcaster {
|
||||
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) {
|
||||
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(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
|
||||
@@ -1852,18 +1866,16 @@ public class PeerGroup implements TransactionBroadcaster {
|
||||
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));
|
||||
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 {
|
||||
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 + ", not stalled " + thresholdString);
|
||||
}
|
||||
}
|
||||
blocksInLastSecond = 0;
|
||||
|
||||
Reference in New Issue
Block a user