mirror of
https://github.com/Qortal/altcoinj.git
synced 2025-02-13 10:45:51 +00:00
Experiment: disconnect a peer if it falls below 10 blocks per second for at least 6 seconds. This is an attempt to speed up chain sync by load balancing off slow peers.
This commit is contained in:
parent
3e1f615853
commit
c4a49eeb85
@ -1464,6 +1464,10 @@ public class PeerGroup implements TransactionBroadcaster {
|
|||||||
private class ChainDownloadSpeedCalculator extends AbstractPeerEventListener implements Runnable {
|
private class ChainDownloadSpeedCalculator extends AbstractPeerEventListener implements Runnable {
|
||||||
private int blocksInLastSecond, txnsInLastSecond, origTxnsInLastSecond, stallWarning;
|
private int blocksInLastSecond, txnsInLastSecond, origTxnsInLastSecond, stallWarning;
|
||||||
|
|
||||||
|
private static final int STALL_PERIOD_SECONDS = 6;
|
||||||
|
private static final int STALL_MIN_SPEED = 10;
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized void onBlocksDownloaded(Peer peer, Block block, @Nullable FilteredBlock filteredBlock, int blocksLeft) {
|
public synchronized void onBlocksDownloaded(Peer peer, Block block, @Nullable FilteredBlock filteredBlock, int blocksLeft) {
|
||||||
blocksInLastSecond++;
|
blocksInLastSecond++;
|
||||||
@ -1480,15 +1484,16 @@ public class PeerGroup implements TransactionBroadcaster {
|
|||||||
public synchronized void run() {
|
public synchronized void run() {
|
||||||
if (blocksInLastSecond > 1) {
|
if (blocksInLastSecond > 1) {
|
||||||
log.info("{} blocks/sec, {} tx/sec, {} pre-filtered tx/sec", blocksInLastSecond, txnsInLastSecond, origTxnsInLastSecond);
|
log.info("{} blocks/sec, {} tx/sec, {} pre-filtered tx/sec", blocksInLastSecond, txnsInLastSecond, origTxnsInLastSecond);
|
||||||
|
if (blocksInLastSecond > STALL_MIN_SPEED)
|
||||||
stallWarning = 0;
|
stallWarning = 0;
|
||||||
}
|
}
|
||||||
if (chain != null && chain.getBestChainHeight() < getMostCommonChainHeight() && blocksInLastSecond == 0 && stallWarning > -1) {
|
if (chain != null && chain.getBestChainHeight() < getMostCommonChainHeight() && blocksInLastSecond < STALL_MIN_SPEED && stallWarning > -1) {
|
||||||
stallWarning++;
|
stallWarning++;
|
||||||
final int STALL_PERIOD_SECONDS = 3;
|
|
||||||
if (stallWarning == STALL_PERIOD_SECONDS) {
|
if (stallWarning == STALL_PERIOD_SECONDS) {
|
||||||
stallWarning = -1;
|
stallWarning = -1;
|
||||||
log.warn("Chain download stalled: no progress for {} seconds", STALL_PERIOD_SECONDS);
|
Peer peer = getDownloadPeer();
|
||||||
// TODO: Consider disconnecting the stalled peer here.
|
log.warn("Chain download stalled: no progress for {} seconds, disconnecting {}", STALL_PERIOD_SECONDS, peer);
|
||||||
|
peer.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
blocksInLastSecond = 0;
|
blocksInLastSecond = 0;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user