Merge pull request #1036 from rags22489664/master

CLOUDSTACK-9038 - Infrastructure tab is slow because of synchronous API callsMaking parallel asynchronous calls to speed up the infrastructure page.

* pr/1036:
  CLOUDSTACK-9038 - Infrastructure tab is slow because of synchronous API calls

Signed-off-by: Remi Bergsma <github@remi.nl>
This commit is contained in:
Remi Bergsma 2015-11-09 15:13:42 +01:00
commit b1c29d5ed5

View File

@ -225,60 +225,64 @@
$.ajax({ $.ajax({
url: createURL('listZones'), url: createURL('listZones'),
data: { data: {
listAll: true,
page: 1, page: 1,
pagesize: 1 //specifying pagesize as 1 because we don't need any embedded objects to be returned here. The only thing we need from API response is "count" property. pagesize: 1 //specifying pagesize as 1 because we don't need any embedded objects to be returned here. The only thing we need from API response is "count" property.
}, },
success: function (json) { success: function (json) {
dataFns.podCount($.extend(data, { args.response.success({
data: {
zoneCount: json.listzonesresponse.count ? json.listzonesresponse.count: 0, zoneCount: json.listzonesresponse.count ? json.listzonesresponse.count: 0,
zones: json.listzonesresponse.zone zones: json.listzonesresponse.zone
}));
} }
}); });
}
});
dataFns.podCount();
}, },
podCount: function (data) { podCount: function (data) {
$.ajax({ $.ajax({
url: createURL('listPods'), url: createURL('listPods'),
data: { data: {
listAll: true,
page: 1, page: 1,
pagesize: 1 //specifying pagesize as 1 because we don't need any embedded objects to be returned here. The only thing we need from API response is "count" property. pagesize: 1 //specifying pagesize as 1 because we don't need any embedded objects to be returned here. The only thing we need from API response is "count" property.
}, },
success: function (json) { success: function (json) {
dataFns.clusterCount($.extend(data, { args.response.success({
data: {
podCount: json.listpodsresponse.count ? json.listpodsresponse.count: 0 podCount: json.listpodsresponse.count ? json.listpodsresponse.count: 0
}));
} }
}); });
}
});
dataFns.clusterCount();
}, },
clusterCount: function (data) { clusterCount: function (data) {
$.ajax({ $.ajax({
url: createURL('listClusters'), url: createURL('listClusters'),
data: { data: {
listAll: true,
page: 1, page: 1,
pagesize: 1 //specifying pagesize as 1 because we don't need any embedded objects to be returned here. The only thing we need from API response is "count" property. pagesize: 1 //specifying pagesize as 1 because we don't need any embedded objects to be returned here. The only thing we need from API response is "count" property.
}, },
success: function (json) { success: function (json) {
dataFns.hostCount($.extend(data, { args.response.success({
data: {
clusterCount: json.listclustersresponse.count ? json.listclustersresponse.count: 0 clusterCount: json.listclustersresponse.count ? json.listclustersresponse.count: 0
}));
//comment the 4 lines above and uncomment the following 4 lines if listHosts API still responds slowly.
/*
dataFns.primaryStorageCount($.extend(data, {
clusterCount: json.listclustersresponse.count ?
json.listclustersresponse.count : 0
}));
*/
} }
}); });
}
});
dataFns.hostCount();
}, },
hostCount: function (data) { hostCount: function (data) {
var data2 = { var data2 = {
type: 'routing', type: 'routing',
listAll: true,
page: 1, page: 1,
pagesize: 1 //specifying pagesize as 1 because we don't need any embedded objects to be returned here. The only thing we need from API response is "count" property. pagesize: 1 //specifying pagesize as 1 because we don't need any embedded objects to be returned here. The only thing we need from API response is "count" property.
}; };
@ -286,15 +290,19 @@
url: createURL('listHosts'), url: createURL('listHosts'),
data: data2, data: data2,
success: function (json) { success: function (json) {
dataFns.primaryStorageCount($.extend(data, { args.response.success({
data: {
hostCount: json.listhostsresponse.count ? json.listhostsresponse.count: 0 hostCount: json.listhostsresponse.count ? json.listhostsresponse.count: 0
}));
} }
}); });
}
});
dataFns.primaryStorageCount();
}, },
primaryStorageCount: function (data) { primaryStorageCount: function (data) {
var data2 = { var data2 = {
listAll: true,
page: 1, page: 1,
pagesize: 1 //specifying pagesize as 1 because we don't need any embedded objects to be returned here. The only thing we need from API response is "count" property. pagesize: 1 //specifying pagesize as 1 because we don't need any embedded objects to be returned here. The only thing we need from API response is "count" property.
}; };
@ -302,15 +310,20 @@
url: createURL('listStoragePools'), url: createURL('listStoragePools'),
data: data2, data: data2,
success: function (json) { success: function (json) {
dataFns.secondaryStorageCount($.extend(data, { args.response.success({
data: {
primaryStorageCount: json.liststoragepoolsresponse.count ? json.liststoragepoolsresponse.count: 0 primaryStorageCount: json.liststoragepoolsresponse.count ? json.liststoragepoolsresponse.count: 0
}));
} }
}); });
}
});
dataFns.secondaryStorageCount();
}, },
secondaryStorageCount: function (data) { secondaryStorageCount: function (data) {
var data2 = { var data2 = {
type: 'SecondaryStorage',
listAll: true,
page: 1, page: 1,
pagesize: 1 //specifying pagesize as 1 because we don't need any embedded objects to be returned here. The only thing we need from API response is "count" property. pagesize: 1 //specifying pagesize as 1 because we don't need any embedded objects to be returned here. The only thing we need from API response is "count" property.
}; };
@ -318,26 +331,33 @@
url: createURL('listImageStores'), url: createURL('listImageStores'),
data: data2, data: data2,
success: function (json) { success: function (json) {
dataFns.systemVmCount($.extend(data, { args.response.success({
data: {
secondaryStorageCount: json.listimagestoresresponse.imagestore ? json.listimagestoresresponse.count: 0 secondaryStorageCount: json.listimagestoresresponse.imagestore ? json.listimagestoresresponse.count: 0
}));
} }
}); });
}
});
dataFns.systemVmCount();
}, },
systemVmCount: function (data) { systemVmCount: function (data) {
$.ajax({ $.ajax({
url: createURL('listSystemVms'), url: createURL('listSystemVms'),
data: { data: {
listAll: true,
page: 1, page: 1,
pagesize: 1 //specifying pagesize as 1 because we don't need any embedded objects to be returned here. The only thing we need from API response is "count" property. pagesize: 1 //specifying pagesize as 1 because we don't need any embedded objects to be returned here. The only thing we need from API response is "count" property.
}, },
success: function (json) { success: function (json) {
dataFns.virtualRouterCount($.extend(data, { args.response.success({
data: {
systemVmCount: json.listsystemvmsresponse.count ? json.listsystemvmsresponse.count: 0 systemVmCount: json.listsystemvmsresponse.count ? json.listsystemvmsresponse.count: 0
}));
} }
}); });
}
});
dataFns.virtualRouterCount();
}, },
virtualRouterCount: function (data) { virtualRouterCount: function (data) {
@ -375,20 +395,22 @@
}); });
} }
dataFns.capacity($.extend(data, { args.response.success({
data: {
virtualRouterCount: (total1 + total2) virtualRouterCount: (total1 + total2)
}));
} }
}); });
}
});
dataFns.capacity();
}, },
capacity: function (data) { capacity: function (data) {
if (data.zoneCount) {
$.ajax({ $.ajax({
url: createURL('listCapacity'), url: createURL('listCapacity'),
success: function (json) { success: function (json) {
var capacities = json.listcapacityresponse.capacity; var capacities = json.listcapacityresponse.capacity;
if(capacities) {
var capacityTotal = function (id, converter) { var capacityTotal = function (id, converter) {
var capacity = $.grep(capacities, function (capacity) { var capacity = $.grep(capacities, function (capacity) {
return capacity.type == id; return capacity.type == id;
@ -403,47 +425,53 @@
return total; return total;
}; };
dataFns.socketInfo($.extend(data, { args.response.success({
data: {
cpuCapacityTotal: capacityTotal(1, cloudStack.converters.convertHz), cpuCapacityTotal: capacityTotal(1, cloudStack.converters.convertHz),
memCapacityTotal: capacityTotal(0, cloudStack.converters.convertBytes), memCapacityTotal: capacityTotal(0, cloudStack.converters.convertBytes),
storageCapacityTotal: capacityTotal(2, cloudStack.converters.convertBytes) storageCapacityTotal: capacityTotal(2, cloudStack.converters.convertBytes)
}));
} }
}); });
} else { } else {
dataFns.socketInfo($.extend(data, {
args.response.success({
data: {
cpuCapacityTotal: cloudStack.converters.convertHz(0), cpuCapacityTotal: cloudStack.converters.convertHz(0),
memCapacityTotal: cloudStack.converters.convertBytes(0), memCapacityTotal: cloudStack.converters.convertBytes(0),
storageCapacityTotal: cloudStack.converters.convertBytes(0) storageCapacityTotal: cloudStack.converters.convertBytes(0)
}));
} }
});
}
}
});
dataFns.socketInfo();
}, },
socketInfo: function (data) { socketInfo: function (data) {
var socketCount = 0; var socketCount = 0;
$.ajax({
url: createURL('listHypervisors'), function listHostFunction(hypervisor, pageSizeValue) {
async: false, var deferred = $.Deferred();
success: function (json) {
args.response.success({
data: $(json.listhypervisorsresponse.hypervisor).map(function (index, hypervisor) {
var totalHostCount = 0; var totalHostCount = 0;
var currentPage = 1;
var returnedHostCount = 0; var returnedHostCount = 0;
var returnedHostCpusocketsSum = 0; var returnedHostCpusocketsSum = 0;
var callListHostsWithPage = function() { var callListHostsWithPage = function(page) {
$.ajax({ $.ajax({
url: createURL('listHosts'), url: createURL('listHosts'),
async: false,
data: { data: {
type: 'routing', type: 'routing',
hypervisor: hypervisor.name, hypervisor: hypervisor,
page: currentPage, page: page,
pagesize: pageSize //global variable details: 'min',
pagesize: pageSizeValue
}, },
success: function (json) { success: function (json) {
if (json.listhostsresponse.count == undefined) { if (json.listhostsresponse.count == undefined) {
deferred.resolve();
return; return;
} }
@ -458,35 +486,56 @@
} }
if (returnedHostCount < totalHostCount) { if (returnedHostCount < totalHostCount) {
currentPage++; callListHostsWithPage(++page);
callListHostsWithPage(); } else {
}
}
});
}
callListHostsWithPage();
socketCount += returnedHostCpusocketsSum; socketCount += returnedHostCpusocketsSum;
}) deferred.resolve();
}); }
} }
}); });
complete($.extend(data, {
socketCount: socketCount
}));
} }
};
var complete = function (data) { callListHostsWithPage(1);
return deferred;
}
$.ajax({
url: createURL('listConfigurations'),
data: {
name : 'default.page.size'
},
success: function (json) {
pageSizeValue = json.listconfigurationsresponse.configuration[0].value;
if(!pageSizeValue) {
return;
}
$.ajax({
url: createURL('listHypervisors'),
success: function (json) {
var deferredArray = [];
$(json.listhypervisorsresponse.hypervisor).map(function (index, hypervisor) {
deferredArray.push(listHostFunction(hypervisor.name, pageSizeValue));
});
$.when.apply(null, deferredArray).then(function(){
args.response.success({ args.response.success({
data: data data: {
socketCount: socketCount
}
}); });
});
}
});
}
});
}
}; };
dataFns.zoneCount({ dataFns.zoneCount();
});
} }
}, },