]> arthur.barton.de Git - netdata.git/commitdiff
the parallel refresher now refreshes the charts de-coupled from each other, so that...
authorCosta Tsaousis (ktsaou) <costa@tsaousis.gr>
Sat, 23 Apr 2016 00:20:40 +0000 (03:20 +0300)
committerCosta Tsaousis (ktsaou) <costa@tsaousis.gr>
Sat, 23 Apr 2016 00:20:40 +0000 (03:20 +0300)
web/dashboard.js

index 96f2c23faa2fceb044a71a6d682a5d3cad3437aa..ca99aa1611770993c4a1cb647ae1d408a74f8a3c 100644 (file)
 
                last_resized: new Date().getTime(), // the timestamp of the last resize request
 
-               crossDomainAjax: false,                 // enable this to request crossDomain AJAX
-
                last_page_scroll: 0,                    // the timestamp the last time the page was scrolled
 
                // the current profile
                }
        };
 
+       NETDATA.statistics = {
+               refreshes_total: 0,
+               refreshes_active: 0,
+               refreshes_active_max: 0
+       };
+
 
        // ----------------------------------------------------------------------------------------------------------------
        // local storage options
 
                        $.ajax({
                                url: host + '/api/v1/charts',
-                               crossDomain: NETDATA.options.crossDomainAjax,
                                async: true,
                                cache: false
                        })
                this.units = self.data('units') || null;        // the units of the chart dimensions
                this.append_options = self.data('append-options') || null;      // the units of the chart dimensions
 
+               this.running = false;                                           // boolean - true when the chart is being refreshed now
                this.validated = false;                                         // boolean - has the chart been validated?
                this.enabled = true;                                            // boolean - is the chart enabled for refresh?
                this.paused = false;                                            // boolean - is the chart paused for any reason?
                        var lost = Math.max(h * 0.2, 5);
                        h -= lost;
 
-                       // center the text, verically
+                       // center the text, vertically
                        var paddingTop = (lost - 5) / 2;
 
                        // but check the width too
                        if(isHidden() === true) return;
 
                        if(that.chart_created === true) {
-                               // we should destroy it
                                if(NETDATA.options.current.destroy_on_hide === true) {
+                                       // we should destroy it
                                        init();
                                }
                                else {
                                        that.element_chart.style.display = 'none';
                                        if(that.element_legend !== null) that.element_legend.style.display = 'none';
                                        that.tm.last_hidden = new Date().getTime();
+
+                                       // de-allocate data
+                                       // This works, but I not sure there are no corner cases somewhere
+                                       // so it is commented - if the user has memory issues he can
+                                       // set Destroy on Hide for all charts
+                                       // that.data = null;
                                }
                        }
 
                        if(this.debug === true)
                                this.log('updateChartWithData() called.');
 
-                       this._updating = false;
-
                        // this may force the chart to be re-created
                        resizeChart();
 
                        if(NETDATA.globalPanAndZoom.isActive())
                                this.tm.last_autorefreshed = 0;
                        else {
-                               if(NETDATA.options.current.parallel_refresher === true && NETDATA.options.current.concurrent_refreshes)
-                                       this.tm.last_autorefreshed = Math.round(now / this.data_update_every) * this.data_update_every;
+                               if(NETDATA.options.current.parallel_refresher === true && NETDATA.options.current.concurrent_refreshes === true)
+                                       this.tm.last_autorefreshed = now - (now % this.data_update_every);
                                else
                                        this.tm.last_autorefreshed = now;
                        }
                        if(this.debug === true)
                                this.log('updating from ' + this.data_url);
 
+                       NETDATA.statistics.refreshes_total++;
+                       NETDATA.statistics.refreshes_active++;
+
+                       if(NETDATA.statistics.refreshes_active > NETDATA.statistics.refreshes_active_max)
+                               NETDATA.statistics.refreshes_active_max = NETDATA.statistics.refreshes_active;
+
                        this._updating = true;
 
                        this.xhr = $.ajax( {
                                url: this.data_url,
-                               crossDomain: NETDATA.options.crossDomainAjax,
                                cache: false,
                                async: true
                        })
                                error('data download failed for url: ' + that.data_url);
                        })
                        .always(function() {
+                               NETDATA.statistics.refreshes_active--;
                                that._updating = false;
                                if(typeof callback === 'function') callback();
                        });
                        }
                };
 
-               this.isAutoRefreshed = function() {
+               this.isAutoRefreshable = function() {
                        return (this.current.autorefresh);
                };
 
                this.canBeAutoRefreshed = function() {
                        var now = new Date().getTime();
 
+                       if(this.running === true) {
+                               if(this.debug === true)
+                                       this.log('I am already running');
+
+                               return false;
+                       }
+
                        if(this.enabled === false) {
                                if(this.debug === true)
                                        this.log('I am not enabled');
                                return true;
                        }
 
-                       if(this.isAutoRefreshed() === true) {
+                       if(this.isAutoRefreshable() === true) {
                                // allow the first update, even if the page is not visible
                                if(this.updates_counter && this.updates_since_last_unhide && NETDATA.options.page_is_visible === false) {
                                        if(NETDATA.options.debug.focus === true || this.debug === true)
                };
 
                this.autoRefresh = function(callback) {
-                       if(this.canBeAutoRefreshed() === true) {
-                               this.updateChart(callback);
+                       if(this.canBeAutoRefreshed() === true && this.running === false) {
+                               var state = this;
+
+                               state.running = true;
+                               state.updateChart(function() {
+                                       state.running = false;
+
+                                       if(typeof callback !== 'undefined')
+                                               callback();
+                               });
                        }
                        else {
                                if(typeof callback !== 'undefined')
 
                                $.ajax( {
                                        url:  this.host + this.chart_url,
-                                       crossDomain: NETDATA.options.crossDomainAjax,
                                        cache: false,
                                        async: true
                                })
                var parallel = new Array();
                var targets = NETDATA.options.targets;
                var len = targets.length;
+               var state;
                while(len--) {
-                       if(targets[len].isVisible() === false)
+                       state = targets[len];
+                       if(state.isVisible() === false || state.running === true)
                                continue;
 
-                       var state = targets[len];
                        if(state.library.initialized === false) {
                                if(state.library.enabled === true) {
                                        state.library.initialize(NETDATA.chartRefresher);
                }
 
                if(parallel.length > 0) {
-                       var parallel_jobs = parallel.length;
-
                        // this will execute the jobs in parallel
                        $(parallel).each(function() {
-                               this.autoRefresh(function() {
-                                       parallel_jobs--;
-
-                                       if(parallel_jobs === 0) {
-                                               setTimeout(NETDATA.chartRefresher,
-                                                       NETDATA.chartRefresherWaitTime());
-                                       }
-                               });
+                               this.autoRefresh();
                        })
                }
-               else {
-                       setTimeout(NETDATA.chartRefresher,
-                               NETDATA.chartRefresherWaitTime());
-               }
+
+               // run the next refresh iteration
+               setTimeout(NETDATA.chartRefresher,
+                       NETDATA.chartRefresherWaitTime());
        };
 
        NETDATA.parseDom = function(callback) {
                        state.easyPieChartEvent.timer = null;
                }
 
-               if(state.isAutoRefreshed() === true && state.data !== null) {
+               if(state.isAutoRefreshable() === true && state.data !== null) {
                        NETDATA.easypiechartChartUpdate(state, state.data);
                }
                else {
        NETDATA.easypiechartChartUpdate = function(state, data) {
                var value, max, pcent;
 
-               if(NETDATA.globalPanAndZoom.isActive() === true || state.isAutoRefreshed() === false) {
+               if(NETDATA.globalPanAndZoom.isActive() === true || state.isAutoRefreshable() === false) {
                        value = null;
                        max = 0;
                        pcent = 0;
                        state.gaugeEvent.timer = null;
                }
 
-               if(state.isAutoRefreshed() === true && state.data !== null) {
+               if(state.isAutoRefreshable() === true && state.data !== null) {
                        NETDATA.gaugeChartUpdate(state, state.data);
                }
                else {
        NETDATA.gaugeChartUpdate = function(state, data) {
                var value, min, max;
 
-               if(NETDATA.globalPanAndZoom.isActive() === true || state.isAutoRefreshed() === false) {
+               if(NETDATA.globalPanAndZoom.isActive() === true || state.isAutoRefreshable() === false) {
                        value = 0;
                        min = 0;
                        max = 1;