added debounce strategy for chain download
This commit is contained in:
parent
354222a1e0
commit
24ba9f5030
37
lib/node.js
37
lib/node.js
@ -114,10 +114,14 @@ function Node ()
|
|||||||
this.pingInterval = false;
|
this.pingInterval = false;
|
||||||
this.connectionInterval = false;
|
this.connectionInterval = false;
|
||||||
|
|
||||||
|
this._lastBlockSentAt = 0;
|
||||||
this._lastChainLog = 0;
|
this._lastChainLog = 0;
|
||||||
this._lastPendingLog = 0;
|
this._lastPendingLog = 0;
|
||||||
this._chainDebouncer = 0;
|
this._chainDebouncer = 0;
|
||||||
this._connection_attempts = 0
|
this._chan_min_time = 50;
|
||||||
|
this._max_chain_debouncer = 20;
|
||||||
|
this._chain_debouncer_cnt = 0;
|
||||||
|
this._connection_attempts = 0;
|
||||||
this._timeOffset = null;
|
this._timeOffset = null;
|
||||||
|
|
||||||
this.startWeb3Connection();
|
this.startWeb3Connection();
|
||||||
@ -651,6 +655,7 @@ Node.prototype.prepareStats = function ()
|
|||||||
|
|
||||||
Node.prototype.sendBlockUpdate = function()
|
Node.prototype.sendBlockUpdate = function()
|
||||||
{
|
{
|
||||||
|
this._lastBlockSentAt = _.now();
|
||||||
console.info("wsc", "Sending", chalk.reset.red("block"), chalk.bold.white("update"));
|
console.info("wsc", "Sending", chalk.reset.red("block"), chalk.bold.white("update"));
|
||||||
this.emit('block', this.prepareBlock());
|
this.emit('block', this.prepareBlock());
|
||||||
}
|
}
|
||||||
@ -718,23 +723,43 @@ Node.prototype.setWatches = function()
|
|||||||
|
|
||||||
console.info('>>>', 'Chain Filter triggered: ', chalk.reset.red(hash), '- last trigger:', chalk.reset.cyan(time));
|
console.info('>>>', 'Chain Filter triggered: ', chalk.reset.red(hash), '- last trigger:', chalk.reset.cyan(time));
|
||||||
|
|
||||||
if(time < 50)
|
if(time < self._chan_min_time)
|
||||||
{
|
{
|
||||||
self._chainDebouncer++;
|
self._chainDebouncer++;
|
||||||
} else {
|
self._chain_debouncer_cnt++;
|
||||||
|
|
||||||
|
if(self._chain_debouncer_cnt > 100)
|
||||||
|
{
|
||||||
|
self._chan_min_time = Math.max(self._chan_min_time + 1, 200);
|
||||||
|
self._max_chain_debouncer = Math.max(self._max_chain_debouncer - 1, 5);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if(time > 5000)
|
||||||
|
{
|
||||||
|
self._chan_min_time = 50;
|
||||||
|
self._max_chain_debouncer = 20;
|
||||||
|
self._chain_debouncer_cnt = 0;
|
||||||
|
}
|
||||||
|
// reset local chain debouncer
|
||||||
self._chainDebouncer = 0;
|
self._chainDebouncer = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(self._chainDebouncer < 10)
|
if(self._chainDebouncer < self._max_chain_debouncer || now - self._lastBlockSentAt > 5000)
|
||||||
{
|
{
|
||||||
|
if(now - self._lastBlockSentAt > 5000)
|
||||||
|
{
|
||||||
|
self._lastBlockSentAt = now;
|
||||||
|
}
|
||||||
|
|
||||||
self._latestQueue.push(hash);
|
self._latestQueue.push(hash);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
debounce(function() {
|
debounce(function() {
|
||||||
self._latestQueue.push(hash);
|
self._latestQueue.push(hash);
|
||||||
self._chainDebouncer = 0;
|
}, self._chan_min_time);
|
||||||
}, 50);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user