Browse Source

AMBARI-12313. Service config pages load extremely slowly (especially on big clusters). (atkach via yusaku)

Yusaku Sako 10 years ago
parent
commit
4d71f7540a

+ 18 - 17
ambari-web/app/mappers/component_config_mapper.js

@@ -42,7 +42,7 @@ App.componentConfigMapper = App.QuickDataMapper.create({
     // We do not want to parse JSON if there is no need to
     var hostComponentJsonMap = {};
     var hostComponentJsonIds = [];
-    var hostComponentJsonsToRemove = {};
+    var hostComponentLoaded = {};
 
     if (json.items.length > 0 || this.get('model').find().someProperty('staleConfigs', true)) {
       json.items.forEach(function (item) {
@@ -54,31 +54,32 @@ App.componentConfigMapper = App.QuickDataMapper.create({
       });
       this.get('model').find().forEach(function (hostComponent) {
         var hostComponentJson = hostComponentJsonMap[hostComponent.get('id')];
-        if (!hostComponentJson && !hostComponent.get('isMaster')) {
-          hostComponent.set('staleConfigs', false);
-        }
-        if (hostComponentJson != null && hostComponent.get('staleConfigs') &&
-          hostComponentJson.HostRoles.state == hostComponent.get('workStatus') &&
-          hostComponentJson.HostRoles.maintenance_state == hostComponent.get('passiveState')) {
-          // A component already exists with correct stale_configs flag and other values - no need to load again
-          hostComponentJsonsToRemove[hostComponentJson.id] = hostComponentJson;
+        var currentStaleConfigsState = Boolean(hostComponentJson);
+        var stateChanged = hostComponent.get('staleConfigs') !== currentStaleConfigsState;
+
+        if (stateChanged && !hostComponent.get('isMaster')) {
+          hostComponent.set('staleConfigs', currentStaleConfigsState);
         }
+        //delete load host-components, so only new ones left
+        delete hostComponentJsonMap[hostComponent.get('id')];
       });
       hostComponentJsonIds.forEach(function (hcId) {
-        if (!hostComponentJsonsToRemove[hcId]) {
-          var host_component = hostComponentJsonMap[hcId];
-          var serviceName = host_component.HostRoles.service_name;
-          hostComponents.push(this.parseIt(host_component, mapConfig));
+        var newHostComponent = hostComponentJsonMap[hcId];
+        if (newHostComponent) {
+          var serviceName = newHostComponent.HostRoles.service_name;
+          hostComponents.push(this.parseIt(newHostComponent, mapConfig));
           if (!newHostComponentsMap[serviceName]) {
             newHostComponentsMap[serviceName] = [];
           }
-          if (!currentServiceComponentsMap[serviceName][host_component.id]) {
-            newHostComponentsMap[serviceName].push(host_component.id);
+          if (!currentServiceComponentsMap[serviceName][newHostComponent.id]) {
+            newHostComponentsMap[serviceName].push(newHostComponent.id);
           }
         }
       }, this);
-      App.store.loadMany(this.get('model'), hostComponents);
-      this.addNewHostComponents(newHostComponentsMap, cacheServices);
+      if (hostComponents.length > 0) {
+        App.store.loadMany(this.get('model'), hostComponents);
+        this.addNewHostComponents(newHostComponentsMap, cacheServices);
+      }
     }
     console.timeEnd('App.componentConfigMapper execution time');
   },

+ 5 - 0
ambari-web/app/mixins/common/table_server_mixin.js

@@ -59,6 +59,11 @@ App.TableServerMixin = Em.Mixin.create({
    * @return {array}
    */
   getPaginationProps: function () {
+    var displayLength = App.db.getDisplayLength(this.get('name'));
+    if (displayLength) {
+      this.get('paginationProps').findProperty('name', 'displayLength').value = displayLength;
+    }
+
     var startIndex = App.db.getStartIndex(this.get('name'));
     if (!Em.isNone(startIndex)) {
       startIndex = (startIndex > 0) ? startIndex - 1 : startIndex;

+ 40 - 19
ambari-web/app/utils/blueprint.js

@@ -248,13 +248,15 @@ module.exports = {
         host_groups: []
       }
     };
+    var hostsMap = this.getComponentForHosts();
 
-    for (var i = 1; i <= hostNames.length; i++) {
+    for (var i = 0; i <= hostNames.length; i++) {
       var host_group = {
-        name: "host-group-" + i,
+        name: "host-group-" + (i + 1),
         components: []
       };
-      var hcFiltered = this.getComponentForHost(hostNames[i-1]);
+      var hcFiltered = hostsMap[hostNames[i]];
+      if (Em.isNone(hcFiltered)) continue;
       for (var j = 0; j < hcFiltered.length; j++) {
         host_group.components.push({
           name: hcFiltered[j]
@@ -262,9 +264,9 @@ module.exports = {
       }
       recommendations.blueprint.host_groups.push(host_group);
       recommendations.blueprint_cluster_binding.host_groups.push({
-        name: "host-group-" + i,
+        name: "host-group-" + (i + 1),
         hosts: [{
-          fqdn: hostNames[i-1]
+          fqdn: hostNames[i]
         }]
       });
     }
@@ -272,20 +274,39 @@ module.exports = {
   },
 
   /**
-   * gets all component names that are present on current host
-   * @param {String} hostName
-   * @returns {Array}
+   * collect all component names that are present on hosts
+   * @returns {object}
    */
-  getComponentForHost: function(hostName) {
-    var clients = App.ClientComponent.find().filter(function(c) {
-      return c.get('hostNames').contains(hostName);
-    }).mapProperty('componentName');
-    var slaves = App.SlaveComponent.find().filter(function(s) {
-      return s.get('hostNames').contains(hostName);
-    }).mapProperty('componentName');
-    var masters = App.HostComponent.find().filter(function(m) {
-      return m.get('isMaster') && m.get('hostName') === hostName;
-    }).mapProperty('componentName');
-    return masters.concat(slaves).concat(clients);
+  getComponentForHosts: function() {
+    var hostsMap = {};
+    App.ClientComponent.find().forEach(function(c) {
+      var componentName = c.get('componentName');
+      c.get('hostNames').forEach(function(hostName){
+        if (hostsMap[hostName]) {
+          hostsMap[hostName].push(componentName);
+        } else {
+          hostsMap[hostName] = [componentName];
+        }
+      });
+    });
+    App.SlaveComponent.find().forEach(function (c) {
+      var componentName = c.get('componentName');
+      c.get('hostNames').forEach(function (hostName) {
+        if (hostsMap[hostName]) {
+          hostsMap[hostName].push(componentName);
+        } else {
+          hostsMap[hostName] = [componentName];
+        }
+      });
+    });
+    App.HostComponent.find().forEach(function (c) {
+      var hostName = c.get('hostName');
+      if (hostsMap[hostName]) {
+        hostsMap[hostName].push(c.get('componentName'));
+      } else {
+        hostsMap[hostName] = [c.get('componentName')];
+      }
+    });
+    return hostsMap;
   }
 };

+ 53 - 5
ambari-web/test/utils/blueprint_test.js

@@ -334,15 +334,17 @@ describe('utils/blueprint', function() {
     });
   });
 
-  describe('#generateHostGroups', function () {
+  describe('#generateHostGroups()', function () {
     beforeEach(function() {
-      sinon.stub(blueprintUtils, 'getComponentForHost' ,function(host) {
-        return host == "host1" ? ["C1","C2"] : ["C1","C3"];
+      sinon.stub(blueprintUtils, 'getComponentForHosts').returns({
+        "host1": ["C1", "C2"],
+        "host2": ["C1", "C3"]
       });
     });
     afterEach(function() {
-      blueprintUtils.getComponentForHost.restore();
-    })
+      blueprintUtils.getComponentForHosts.restore();
+    });
+
     var tests = [
       {
         "hostNames": ["host1", "host2"],
@@ -420,4 +422,50 @@ describe('utils/blueprint', function() {
       });
     });
   });
+
+  describe("#getComponentForHosts()", function() {
+
+    beforeEach(function() {
+      sinon.stub(App.ClientComponent, 'find').returns([
+        Em.Object.create({
+          componentName: "C1",
+          hostNames: ["host1", "host2"]
+        })
+      ]);
+      sinon.stub(App.SlaveComponent, 'find').returns([
+        Em.Object.create({
+          componentName: "C2",
+          hostNames: ["host2", "host3"]
+        })
+      ]);
+      sinon.stub(App.HostComponent, 'find').returns([
+        Em.Object.create({
+          componentName: "C3",
+          hostName: "host3",
+          isMaster: true
+        })
+      ]);
+    });
+    afterEach(function() {
+      App.ClientComponent.find.restore();
+      App.SlaveComponent.find.restore();
+      App.HostComponent.find.restore();
+    });
+
+    it("", function() {
+      expect(blueprintUtils.getComponentForHosts()).to.eql({
+        "host1": [
+          "C1"
+        ],
+        "host2": [
+          "C1",
+          "C2"
+        ],
+        "host3": [
+          "C2",
+          "C3"
+        ]
+      });
+    });
+  });
 });