Changed superbuffer to rollover and client improvements

master
Ringo Watanabe 6 years ago
parent 19c440d978
commit 05d5ee0279

@ -11,7 +11,7 @@ var config = {
BACKEND_SOCKET: "./backend/rtbw.sock", BACKEND_SOCKET: "./backend/rtbw.sock",
BUFFER_PURGE_TIME: 1800000, //30 minutes BUFFER_PURGE_TIME: 1800000, //30 minutes
SUPERBUFFER_PURGE_TIME: 43200000 //12 hours SUPERBUFFER_SIZE: 24
}; };
module.exports = config; module.exports = config;

@ -2,15 +2,21 @@ const Cycle = require("./cycle").Cycle;
const logger = require("./logger"); const logger = require("./logger");
class CycleBuffer { class CycleBuffer {
constructor(purgeTime) { constructor(purgeTime, fixed=false) {
this.time = purgeTime; this.time = purgeTime;
this.buffer=[]; this.buffer=[];
var th = this; var th = this;
this.onclear = function(sp) {}; this.onclear = function(sp) {};
if(fixed) {
this.fixed=true;
}
else {
this.inter = setInterval(function() { this.inter = setInterval(function() {
th.purge(); th.purge();
}, this.time); }, this.time);
} }
}
purge() purge()
{ {
@ -20,6 +26,8 @@ class CycleBuffer {
add(cycle) { add(cycle) {
this.buffer.push(cycle); this.buffer.push(cycle);
if(this.fixed && this.buffer.length>=this.time)
this.buffer.shift();
} }
all() { all() {
@ -31,6 +39,7 @@ class CycleBuffer {
return ret; return ret;
} }
close() { close() {
if(this.inter)
clearInterval(this.inter); clearInterval(this.inter);
this.buffer.length=0; this.buffer.length=0;
} }

@ -75,7 +75,7 @@ var allTime = new _cycle.Cycle();
var allTimeAverage = new _cycle.Cycle(); var allTimeAverage = new _cycle.Cycle();
var allTimeAverageN = 0; var allTimeAverageN = 0;
var buffer = new CycleBuffer(config.BUFFER_PURGE_TIME); var buffer = new CycleBuffer(config.BUFFER_PURGE_TIME);
var superbuffer = new CycleBuffer(config.SUPERBUFFER_PURGE_TIME); var superbuffer = new CycleBuffer(config.SUPERBUFFER_SIZE, true);
var beInfo = null; var beInfo = null;
var upSince = new Date(); var upSince = new Date();
@ -96,7 +96,7 @@ superbuffer.onclear = function(bu) {
}; };
logger.log("Buffer set to clear every "+(config.BUFFER_PURGE_TIME/1000/60)+" minutes"); logger.log("Buffer set to clear every "+(config.BUFFER_PURGE_TIME/1000/60)+" minutes");
logger.log("Superbuffer set to clear every "+(config.SUPERBUFFER_PURGE_TIME/1000/60)+" minutes"); logger.log("Superbuffer set to fill at "+(config.SUPERBUFFER_SIZE)+" entries");
process.execFile(config.PYTHON_EXECUTABLE, [config.RTBWCTL_FILENAME, config.BACKEND_SOCKET, "info"], function(error,stdout,stderr) { process.execFile(config.PYTHON_EXECUTABLE, [config.RTBWCTL_FILENAME, config.BACKEND_SOCKET, "info"], function(error,stdout,stderr) {
@ -128,7 +128,7 @@ var server = http.createServer(function(req, res) {
res.end(JSON.stringify({ res.end(JSON.stringify({
interval: config.POLL_INTERVAL, interval: config.POLL_INTERVAL,
purgeInterval: config.BUFFER_PURGE_TIME, purgeInterval: config.BUFFER_PURGE_TIME,
superPurgeInterval: config.SUPERBUFFER_PURGE_TIME, superPurgeInterval: config.SUPERBUFFER_SIZE,
backendInterval: beInfo.timeout, backendInterval: beInfo.timeout,
board: beInfo.board, board: beInfo.board,
upSince: upSince upSince: upSince
@ -213,10 +213,6 @@ wss.on('request', function(req) { //why isn't this getting called?
}); });
wss.on('connection', function (ws) { wss.on('connection', function (ws) {
/*ws.on('message', function (message) {
ws.send("Received: " + message);
});*/
var f = function(cycle) { var f = function(cycle) {
ws.send(JSON.stringify({type: "cycle", data: cycle})); ws.send(JSON.stringify({type: "cycle", data: cycle}));
}; };

@ -19,7 +19,7 @@
Cycle interval: <em id='interval'></em><br /> Cycle interval: <em id='interval'></em><br />
Archiver interval: <em id='binterval'></em><br /> Archiver interval: <em id='binterval'></em><br />
Server buffer purge interval: <em id='pinterval'></em><br /> Server buffer purge interval: <em id='pinterval'></em><br />
Server aggregate buffer purge interval: <em id='spinterval'></em><br /> Server aggregate buffer max size: <em id='spinterval'></em><br />
</p> </p>
<hr></hr> <hr></hr>
<h2>Total uptime stats</h2> <h2>Total uptime stats</h2>

@ -31,6 +31,8 @@ const maxEntries= client.preloadCycles;
var cycleTableRollover = null; var cycleTableRollover = null;
var sessionAverageRollover = null; var sessionAverageRollover = null;
var cyTotal=0;
function setStatus(str) function setStatus(str)
{ {
$('#status').text(str); $('#status').text(str);
@ -74,7 +76,7 @@ function createNewCandle(charts, close)
function createNewLinePoint(charts, data) function createNewLinePoint(charts, data)
{ {
if(charts.agline.data.datasets[0].data[charts.agline.data.datasets[0].data.length-1]) { if(charts.agline.data.datasets[0].data[charts.agline.data.datasets[0].data.length-1] !==undefined) {
charts.agline.data.datasets[0].data[charts.agline.data.datasets[0].data.length-1] = data.number; charts.agline.data.datasets[0].data[charts.agline.data.datasets[0].data.length-1] = data.number;
charts.agline.data.datasets[1].data[charts.agline.data.datasets[0].data.length-1] = data.number/data._cycles; charts.agline.data.datasets[1].data[charts.agline.data.datasets[0].data.length-1] = data.number/data._cycles;
} }
@ -305,12 +307,18 @@ function graphCycle(data, charts,update=true)
//Line //Line
//Total posts //Total posts
if(charts.agline.data.datasets[0].data[charts.agline.data.datasets[0].data.length-1]) { var lgc = charts.agline.data.datasets[0].data[charts.agline.data.datasets[0].data.length-1];
charts.agline.data.datasets[0].data[charts.agline.data.datasets[0].data.length-1] += data.number; //console.log(lgc+" "+data.number);
if(client.superBuffer.length>0) if(lgc || lgc===0) {
charts.agline.data.datasets[1].data[charts.agline.data.datasets[0].data.length-1] = charts.agline.data.datasets[0].data[charts.agline.data.datasets[0].data.length-1] /client.superBuffer[client.superBuffer.length-1]._cycles; charts.agline.data.datasets[0].data[charts.agline.data.datasets[0].data.length-1]= lgc+ data.number;
if(update) if(cyTotal>0)
{
charts.agline.data.datasets[1].data[charts.agline.data.datasets[1].data.length-1] = (lgc+ data.number)/cyTotal;
}
if(update) {
charts.agline.update(); charts.agline.update();
//console.log("Update to "+charts.agline.data.datasets[0].data[charts.agline.data.datasets[0].data.length-1]);
}
} }
} }
@ -782,13 +790,15 @@ function begin() {
client.superGrapher = function(data) { client.superGrapher = function(data) {
//TODO: new supercycle //TODO: new supercycle
//add_new_candle(g_chartsSuper(), data); //add_new_candle(g_chartsSuper(), data)
cyTotal = 0;
createNewCandle(g_chartsSuper(), data._candle.number.c); createNewCandle(g_chartsSuper(), data._candle.number.c);
createNewLinePoint(g_chartsSuper(), data); createNewLinePoint(g_chartsSuper(), data);
}; };
client.start(function(data) { client.start(function(data) {
//on message function //on message function
cyTotal += 1;
updateAllTime(g_charts(),data); updateAllTime(g_charts(),data);
graphCycle(data, g_chartsSession()); graphCycle(data, g_chartsSession());
@ -797,7 +807,7 @@ function begin() {
$('#interval').text(client.info.interval+" ms"); $('#interval').text(client.info.interval+" ms");
$('#binterval').text(client.info.backendInterval+" s"); $('#binterval').text(client.info.backendInterval+" s");
$('#pinterval').text((client.info.purgeInterval/1000/60).toFixed(2)+" m"); $('#pinterval').text((client.info.purgeInterval/1000/60).toFixed(2)+" m");
$('#spinterval').text((client.info.superPurgeInterval/1000/60/60).toFixed(2)+" h"); $('#spinterval').text( (((client.info.purgeInterval/1000/60)*client.info.superPurgeInterval)/60).toFixed(2)+" h");
$('#board').text(client.info.board); $('#board').text(client.info.board);
$('#uptime').text(fixtime2(new Date(client.info.upSince))); $('#uptime').text(fixtime2(new Date(client.info.upSince)));
$('#s_started').text(fixtime2(new Date())); $('#s_started').text(fixtime2(new Date()));
@ -902,6 +912,7 @@ function begin() {
chartAGLine.data.labels.shift(); chartAGLine.data.labels.shift();
chartAGLine.data.datasets[0].data.shift(); chartAGLine.data.datasets[0].data.shift();
chartAGLine.data.datasets[1].data.shift();
chartAGLine.update(); chartAGLine.update();
}); });

Loading…
Cancel
Save