@cryptotaxi247 / netdata-1 / commits / 286b7d218

added support for parallel ajax queries to netdata

Costa Tsaousis (ktsaou) committed Dec 11, 2015 at 02:56 UTC 286b7d218d019de87a6e021935491fe149be9c18
1 file changed +79 -9
web/dashboard.js
+79 -9
@@ -159,7 +159,7 @@
159 idle_lost_focus: 500, // ms - when the window does not have focus, check
160 // if focus has been regained, every this time
161
162 - global_pan_sync_time: 500, // ms - when you pan or zoon a chart, the background
162 + global_pan_sync_time: 1000, // ms - when you pan or zoon a chart, the background
163 // autorefreshing of charts is paused for this amount
164 // of time
165
@@ -173,6 +173,8 @@
173
174 update_only_visible: true, // enable or disable visibility management
175
176 + parallel_refresher: true, // enable parallel refresh of charts
177 +
178 color_fill_opacity: {
179 line: 1.0,
180 area: 0.2,
@@ -359,7 +361,7 @@
361 chartState = function(element) {
362 self = $(element);
363
362 - Object.assign(this, {
364 + $.extend(this, {
365 uuid: NETDATA.guid(), // GUID - a unique identifier for the chart
366 id: self.data('netdata'), // string - the name of chart
367
@@ -1460,14 +1462,14 @@
1462
1463 // ----------------------------------------------------------------------------------------------------------------
1464
1463 - NETDATA.chartRefresher = function(index) {
1465 + NETDATA.chartRefresher1 = function(index) {
1466 // if(NETDATA.options.debug.mail_loop) console.log('NETDATA.chartRefresher(<targets, ' + index + ')');
1467
1468 if(NETDATA.options.updated_dom) {
1469 // the dom has been updated
1470 // get the dom parts again
1471 NETDATA.getDomCharts(function() {
1470 - NETDATA.chartRefresher(0);
1472 + NETDATA.chartRefresher1(0);
1473 });
1474
1475 return;
@@ -1478,7 +1480,7 @@
1480 NETDATA.options.auto_refresher_fast_weight = 0;
1481
1482 setTimeout(function() {
1481 - NETDATA.chartRefresher(0);
1483 + NETDATA.chartRefresher1(0);
1484 }, NETDATA.options.current.idle_between_loops);
1485 }
1486 else {
@@ -1488,8 +1490,8 @@
1490 if(NETDATA.options.debug.main_loop) console.log('fast rendering...');
1491
1492 state.autoRefresh(function() {
1491 - NETDATA.chartRefresher(++index);
1492 - }, false);
1493 + NETDATA.chartRefresher1(++index);
1494 + });
1495 }
1496 else {
1497 if(NETDATA.options.debug.main_loop) console.log('waiting for next refresh...');
@@ -1497,13 +1499,81 @@
1499
1500 setTimeout(function() {
1501 state.autoRefresh(function() {
1500 - NETDATA.chartRefresher(++index);
1501 - }, false);
1502 + NETDATA.chartRefresher1(++index);
1503 + });
1504 }, NETDATA.options.current.idle_between_charts);
1505 }
1506 }
1507 }
1508
1509 + NETDATA.chartRefresher_sequencial = function() {
1510 + if(NETDATA.options.updated_dom) {
1511 + // the dom has been updated
1512 + // get the dom parts again
1513 + NETDATA.getDomCharts(NETDATA.chartRefresher);
1514 + return;
1515 + }
1516 +
1517 + if(NETDATA.options.sequencial.length == 0)
1518 + NETDATA.chartRefresher();
1519 + else {
1520 + var state = NETDATA.options.sequencial.pop();
1521 + if(state.library.initialized)
1522 + NETDATA.chartRefresher();
1523 + else
1524 + state.autoRefresh(NETDATA.chartRefresher_sequencial);
1525 + }
1526 + }
1527 +
1528 + NETDATA.chartRefresher = function() {
1529 + if(!NETDATA.options.current.parallel_refresher) {
1530 + NETDATA.chartRefresher1(0);
1531 + return;
1532 + }
1533 +
1534 + if(NETDATA.options.updated_dom) {
1535 + // the dom has been updated
1536 + // get the dom parts again
1537 + NETDATA.getDomCharts(function() {
1538 + NETDATA.chartRefresher();
1539 + });
1540 +
1541 + return;
1542 + }
1543 +
1544 + NETDATA.options.parallel = new Array();
1545 + NETDATA.options.sequencial = new Array();
1546 +
1547 + for(var i = 0; i < NETDATA.options.targets.length ; i++) {
1548 + var target = NETDATA.options.targets.get(i);
1549 + var state = NETDATA.chartState(target);
1550 +
1551 + if(!state.library.initialized)
1552 + NETDATA.options.sequencial.push(state);
1553 + else
1554 + NETDATA.options.parallel.push(state);
1555 + }
1556 +
1557 + if(NETDATA.options.parallel.length > 0) {
1558 + NETDATA.options.parallel_jobs = NETDATA.options.parallel.length;
1559 + console.log('PARALLEL: ' + NETDATA.options.parallel.length);
1560 +
1561 + $(NETDATA.options.parallel).each(function() {
1562 + this.autoRefresh(function() {
1563 + NETDATA.options.parallel_jobs--;
1564 + if(NETDATA.options.parallel_jobs == 0) {
1565 + setTimeout(NETDATA.chartRefresher_sequencial,
1566 + NETDATA.options.current.idle_between_charts);
1567 + }
1568 + });
1569 + })
1570 + }
1571 + else {
1572 + setTimeout(NETDATA.chartRefresher_sequencial,
1573 + NETDATA.options.current.idle_between_charts);
1574 + }
1575 + }
1576 +
1577 NETDATA.getDomCharts = function(callback) {
1578 NETDATA.options.updated_dom = false;
1579