reiabreu commented on code in PR #8709:
URL: https://github.com/apache/storm/pull/8709#discussion_r3329115585
##########
storm-server/src/main/java/org/apache/storm/scheduler/IsolationScheduler.java:
##########
@@ -316,14 +321,36 @@ private LinkedList<HostAssignableSlots>
hostAssignableSlots(Cluster cluster) {
}
slots.add(slot);
}
+
+ final Map<String, Integer> hostFreeSlotCount = new HashMap<String,
Integer>();
+ for (WorkerSlot slot : cluster.getAvailableSlots()) {
+ String host = cluster.getHost(slot.getNodeId());
+ if (hostAssignableSlots.containsKey(host)) {
+ Integer count = hostFreeSlotCount.get(host);
+ hostFreeSlotCount.put(host, (count == null ? 0 : count) + 1);
+ }
+ }
+
List<HostAssignableSlots> sortHostAssignSlots = new
ArrayList<HostAssignableSlots>();
Review Comment:
ran this through an LLM.
Suggested approach to avoid doing Map lookup in every sort iteration
```
1. Add freeSlots to HostAssignableSlots:
1 class HostAssignableSlots {
2 private final int freeSlots;
3 // ... update constructor and add getter
4 }
2. Calculate once per host, then sort:
1 // Build objects with pre-calculated metadata
2 for (Map.Entry<String, List<WorkerSlot>> entry :
hostAssignableSlots.entrySet()) {
3 int free = (int)
entry.getValue().stream().filter(cluster::isSlotAvailable).count();
4 sortHostAssignSlots.add(new
HostAssignableSlots(entry.getKey(), entry.getValue(), free));
5 }
6
7 // Faster Comparator (Direct field access)
8 Collections.sort(sortHostAssignSlots, (o1, o2) -> {
9 int bySlots = o2.getWorkerSlots().size() -
o1.getWorkerSlots().size();
10 if (bySlots != 0) return bySlots;
11
12 int byFree = o2.getFreeSlots() - o1.getFreeSlots();
13 if (byFree != 0) return byFree;
14
15 return o1.getHostName().compareTo(o2.getHostName());
16 });
`
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]