Skip to content
This repository has been archived by the owner on Mar 31, 2023. It is now read-only.

Improve performance by reducing map accesses #163

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions fenzo-core/src/main/java/com/netflix/fenzo/AssignableVMs.java
Original file line number Diff line number Diff line change
Expand Up @@ -302,13 +302,14 @@ private void resetTotalResources() {

private void addTotalResources(AssignableVirtualMachine avm) {
final Map<VMResource, Double> maxResources = avm.getMaxResources();
for (VMResource r: maxResources.keySet()) {
Double v = maxResources.get(r);
for (Map.Entry<VMResource, Double> r: maxResources.entrySet()) {
VMResource k = r.getKey();
Double v = r.getValue();
if (v != null) {
if (totalResourcesMap.get(r) == null)
totalResourcesMap.put(r, v);
if (totalResourcesMap.get(k) == null)
totalResourcesMap.put(k, v);
else
totalResourcesMap.put(r, totalResourcesMap.get(r) + v);
totalResourcesMap.put(k, totalResourcesMap.get(k) + v);
}
}
}
Expand Down
15 changes: 9 additions & 6 deletions fenzo-core/src/main/java/com/netflix/fenzo/VMCollection.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,13 @@ Map<String, List<String>> clonePseudoVMsForGroups(Map<String, Integer> groupCoun
InternalVMCloner vmCloner = new InternalVMCloner();
Map<String, List<String>> result = new HashMap<>();
long now = System.currentTimeMillis();
for (String g: groupCounts.keySet()) {
for (Map.Entry<String, Integer> g: groupCounts.entrySet()) {
List<String> hostnames = new LinkedList<>();
result.put(g, hostnames);
final ConcurrentMap<String, AssignableVirtualMachine> avmsMap = vms.get(g);
String k = g.getKey();
Integer v = g.getValue();

result.put(k, hostnames);
final ConcurrentMap<String, AssignableVirtualMachine> avmsMap = vms.get(k);
if (avmsMap != null) {
final List<AssignableVirtualMachine> vmsList = avmsMap.values()
.stream()
Expand All @@ -103,15 +106,15 @@ Map<String, List<String>> clonePseudoVMsForGroups(Map<String, Integer> groupCoun
(entry.getValue() == null ? "null" : entry.getValue().getText().getValue())
);
}
int n = groupCounts.get(g);
final AutoScaleRule rule = ruleGetter.call(g);
int n = groupCounts.get(k);
final AutoScaleRule rule = ruleGetter.call(k);
if (rule != null) {
int max = rule.getMaxSize();
if (max < Integer.MAX_VALUE && n > (max - vmsList.size()))
n = max - vmsList.size();
}
for (int i = 0; i < n; i++) {
final String hostname = createHostname(g, i);
final String hostname = createHostname(k, i);
addLease(vmCloner.cloneLease(lease, hostname, now));
if(logger.isDebugEnabled())
logger.debug("Added cloned lease for " + hostname);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -302,12 +302,13 @@ private boolean totalResMapChanged(Map<VMResource, Double> currTotalResourcesMap
if (currTotalResourcesMap.size() != totalResourcesMap.size())
return true;
Set<VMResource> curr = new HashSet<>(currTotalResourcesMap.keySet());
for (VMResource r : totalResourcesMap.keySet()) {
final Double c = currTotalResourcesMap.get(r);
final Double n = totalResourcesMap.get(r);
for (Map.Entry<VMResource, Double> r : totalResourcesMap.entrySet()) {
VMResource k = r.getKey();
final Double n = r.getValue();
final Double c = currTotalResourcesMap.get(k);
if ((c == null && n != null) || (c != null && n == null) || (n != null && !n.equals(c)))
return true;
curr.remove(r);
curr.remove(k);
}
return !curr.isEmpty();
}
Expand Down