Merge pull request #90 from cubedro/develop

Reduced update lag
This commit is contained in:
Marian OANCΞA 2015-04-28 08:40:06 +03:00
commit 918e2919a2

View File

@ -40,7 +40,7 @@ var socket = new Socket(process.env.WS_SERVER || 'ws://localhost:3000');
var WS_SECRET = process.env.WS_SECRET || "eth-net-stats-has-a-secret"; var WS_SECRET = process.env.WS_SECRET || "eth-net-stats-has-a-secret";
var PENDING_WORKS = true; var PENDING_WORKS = true;
var MAX_BLOCKS_HISTORY = 36; var MAX_BLOCKS_HISTORY = 40;
var UPDATE_INTERVAL = 5000; var UPDATE_INTERVAL = 5000;
var PING_INTERVAL = 2000; var PING_INTERVAL = 2000;
var MINERS_LIMIT = 5; var MINERS_LIMIT = 5;
@ -113,6 +113,9 @@ function Node()
this.updateInterval = false; this.updateInterval = false;
this.pingInterval = false; this.pingInterval = false;
this._lastLatestLog = 0;
this._lastPendingLog = 0;
socket.on('open', function open() { socket.on('open', function open() {
socket.emit('hello', { id: self.id, info: self.info, secret: WS_SECRET }); socket.emit('hello', { id: self.id, info: self.info, secret: WS_SECRET });
console.info('The connection has been opened.'); console.info('The connection has been opened.');
@ -487,10 +490,22 @@ Node.prototype.setWatches = function()
this.pendingFilter = web3.eth.filter('pending'); this.pendingFilter = web3.eth.filter('pending');
this.pendingFilter.watch( function(log) { this.pendingFilter.watch( function(log) {
if(PENDING_WORKS) { if(PENDING_WORKS) {
var now = (new Date()).getTime();
var time = now - self._lastPendingLog;
if(time > 50)
{
self.update();
}
else
{
debounce(function() { debounce(function() {
self.updatePending(); self.updatePending();
}, 50); }, 50);
} }
self._lastPendingLog = now;
}
}); });
} }
catch (err) catch (err)
@ -499,19 +514,32 @@ Node.prototype.setWatches = function()
console.error(err); console.error(err);
} }
try { // try {
this.chainFilter = web3.eth.filter('latest'); // this.chainFilter = web3.eth.filter('latest');
this.chainFilter.watch(function(log) { // this.chainFilter.watch(function(log)
debounce(function() { // {
self.update(); // var now = (new Date()).getTime();
}, 50); // var time = now - self._lastLatestLog;
});
} // if(time > 50)
catch (err) // {
{ // self.update();
console.error("Couldn't set up chain filter"); // }
console.error(err); // else
} // {
// debounce(function() {
// self.update();
// }, 50);
// }
// self._lastLatestLog = now;
// });
// }
// catch (err)
// {
// console.error("Couldn't set up chain filter");
// console.error(err);
// }
this.updateInterval = setInterval(function(){ this.updateInterval = setInterval(function(){
self.update(); self.update();