Skip to content

Commit eeac80e

Browse files
committed
CLOUDSTACK-4350: [Performance Testing] Adding hosts take much longer time than baselines
During host connect multiple listeners gets invoked, one of them is the download listener. As part of processConnect() method, it checks if templates needs to be downloaded to secondary store for a particular HV type. As part of that check it computes list of HVs present in the zone. The earlier logic was to query all hosts (excluding current one) and iterate over them to make the list. This is not optimal and is bound to have some latency as the number of hosts increases. Optimized the logic by querying the list of HVs from the db. directly instead of iterating over all hosts in the zone. Conflicts: server/src/com/cloud/resource/ResourceManagerImpl.java
1 parent 02e7630 commit eeac80e

1 file changed

Lines changed: 26 additions & 12 deletions

File tree

‎server/src/com/cloud/resource/ResourceManagerImpl.java‎

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,10 @@
3131
import javax.inject.Inject;
3232
import javax.naming.ConfigurationException;
3333

34-
import org.apache.log4j.Logger;
35-
import org.springframework.stereotype.Component;
36-
3734
import com.google.gson.Gson;
3835

36+
import org.apache.log4j.Logger;
37+
import org.springframework.stereotype.Component;
3938
import org.apache.cloudstack.api.ApiConstants;
4039
import org.apache.cloudstack.api.command.admin.cluster.AddClusterCmd;
4140
import org.apache.cloudstack.api.command.admin.cluster.DeleteClusterCmd;
@@ -147,9 +146,11 @@
147146
import com.cloud.utils.component.Manager;
148147
import com.cloud.utils.component.ManagerBase;
149148
import com.cloud.utils.db.DB;
149+
import com.cloud.utils.db.GenericSearchBuilder;
150150
import com.cloud.utils.db.GlobalLock;
151151
import com.cloud.utils.db.SearchBuilder;
152152
import com.cloud.utils.db.SearchCriteria;
153+
import com.cloud.utils.db.SearchCriteria.Func;
153154
import com.cloud.utils.db.SearchCriteria.Op;
154155
import com.cloud.utils.db.SearchCriteria2;
155156
import com.cloud.utils.db.SearchCriteriaService;
@@ -262,6 +263,8 @@ public void setPodAllocators(List<PodAllocator> _podAllocators) {
262263

263264
private static final int ACQUIRE_GLOBAL_LOCK_TIMEOUT_FOR_COOPERATION = 30; // seconds
264265

266+
private GenericSearchBuilder<HostVO, String> _hypervisorsInDC;
267+
265268
private void insertListener(Integer event, ResourceListener listener) {
266269
List<ResourceListener> lst = _lifeCycleListeners.get(event);
267270
if (lst == null) {
@@ -1338,6 +1341,15 @@ public Cluster getCluster(Long clusterId) {
13381341
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
13391342
_defaultSystemVMHypervisor = HypervisorType.getType(_configDao.getValue(Config.SystemVMDefaultHypervisor.toString()));
13401343
_gson = GsonHelper.getGson();
1344+
1345+
_hypervisorsInDC = _hostDao.createSearchBuilder(String.class);
1346+
_hypervisorsInDC.select(null, Func.DISTINCT, _hypervisorsInDC.entity().getHypervisorType());
1347+
_hypervisorsInDC.and("hypervisorType", _hypervisorsInDC.entity().getHypervisorType(), SearchCriteria.Op.NNULL);
1348+
_hypervisorsInDC.and("dataCenter", _hypervisorsInDC.entity().getDataCenterId(), SearchCriteria.Op.EQ);
1349+
_hypervisorsInDC.and("id", _hypervisorsInDC.entity().getId(), SearchCriteria.Op.NEQ);
1350+
_hypervisorsInDC.and("type", _hypervisorsInDC.entity().getType(), SearchCriteria.Op.EQ);
1351+
_hypervisorsInDC.done();
1352+
13411353
return true;
13421354
}
13431355

@@ -2418,23 +2430,25 @@ public List<HostVO> listAllHostsInAllZonesByType(Type type) {
24182430

24192431
@Override
24202432
public List<HypervisorType> listAvailHypervisorInZone(Long hostId, Long zoneId) {
2421-
SearchCriteriaService<HostVO, HostVO> sc = SearchCriteria2.create(HostVO.class);
2433+
SearchCriteria<String> sc = _hypervisorsInDC.create();
24222434
if (zoneId != null) {
2423-
sc.addAnd(sc.getEntity().getDataCenterId(), Op.EQ, zoneId);
2435+
sc.setParameters("dataCenter", zoneId);
24242436
}
24252437
if (hostId != null) {
24262438
// exclude the given host, since we want to check what hypervisor is already handled
24272439
// in adding this new host
2428-
sc.addAnd(sc.getEntity().getId(), Op.NEQ, hostId);
2440+
sc.setParameters("id", hostId);
24292441
}
2430-
sc.addAnd(sc.getEntity().getType(), Op.EQ, Host.Type.Routing);
2431-
List<HostVO> hosts = sc.list();
2442+
sc.setParameters("type", Host.Type.Routing);
24322443

2433-
List<HypervisorType> hypers = new ArrayList<HypervisorType>(5);
2434-
for (HostVO host : hosts) {
2435-
hypers.add(host.getHypervisorType());
2444+
// The search is not able to return list of enums, so getting
2445+
// list of hypervisors as strings and then converting them to enum
2446+
List<String> hvs = _hostDao.customSearch(sc, null);
2447+
List<HypervisorType> hypervisors = new ArrayList<HypervisorType>();
2448+
for (String hv : hvs) {
2449+
hypervisors.add(HypervisorType.getType(hv));
24362450
}
2437-
return hypers;
2451+
return hypervisors;
24382452
}
24392453

24402454
@Override

0 commit comments

Comments
 (0)