use of org.apache.ignite.internal.processors.affinity.HistoryAffinityAssignment in project ignite by apache.
the class GridAffinityAssignmentJolBenchmark method measureHistory0.
/**
* @param parts Parts.
* @param nodeCnt Node count.
* @param disableOptimization Disable optimization.
*/
private static long measureHistory0(int parts, int nodeCnt, boolean disableOptimization, int backups) throws Exception {
System.gc();
setOptimization(disableOptimization);
RendezvousAffinityFunction aff = new RendezvousAffinityFunction(true, parts);
List<ClusterNode> nodes = new ArrayList<>(nodeCnt);
nodes.add(node(0));
Map<AffinityTopologyVersion, HistoryAffinityAssignment> affCache = new ConcurrentSkipListMap<>();
List<List<ClusterNode>> prevAssignment = new ArrayList<>();
prevAssignment = aff.assignPartitions(context(new ArrayList<>(nodes), prevAssignment, 1));
for (int i = 1; i < nodeCnt; i++) {
ClusterNode newNode = node(i);
nodes.add(newNode);
List<List<ClusterNode>> idealAssignment = aff.assignPartitions(context(new ArrayList<>(nodes), prevAssignment, backups));
List<List<ClusterNode>> lateAssignmemnt = new ArrayList<>(parts);
for (int j = 0; j < idealAssignment.size(); j++) {
List<ClusterNode> ideal0 = idealAssignment.get(j);
List<ClusterNode> prev = prevAssignment.get(j);
ClusterNode curPrimary = prev.get(0);
if (!curPrimary.equals(ideal0.get(0))) {
List<ClusterNode> cpy = new ArrayList<>(ideal0);
cpy.remove(curPrimary);
cpy.add(0, curPrimary);
lateAssignmemnt.add(cpy);
} else
lateAssignmemnt.add(ideal0);
}
AffinityTopologyVersion topVer = new AffinityTopologyVersion(i + 1, 0);
GridAffinityAssignmentV2 a = new GridAffinityAssignmentV2(topVer, lateAssignmemnt, idealAssignment);
HistoryAffinityAssignment h = new HistoryAffinityAssignmentImpl(a, backups);
if (!lateAssignmemnt.equals(h.assignment()))
throw new RuntimeException();
if (!idealAssignment.equals(h.idealAssignment()))
throw new RuntimeException();
affCache.put(topVer, h);
AffinityTopologyVersion topVer0 = new AffinityTopologyVersion(i + 1, 1);
List<List<ClusterNode>> assignment = new ArrayList<>(parts);
for (int j = 0; j < idealAssignment.size(); j++) {
List<ClusterNode> clusterNodes = idealAssignment.get(j);
assignment.add(clusterNodes);
}
GridAffinityAssignmentV2 a0 = new GridAffinityAssignmentV2(topVer0, assignment, idealAssignment);
HistoryAffinityAssignment h0 = new HistoryAffinityAssignmentImpl(a0, backups);
if (!assignment.equals(h0.assignment()))
throw new RuntimeException();
if (!idealAssignment.equals(h0.idealAssignment()))
throw new RuntimeException();
affCache.put(topVer0, h0);
prevAssignment = idealAssignment;
}
System.gc();
GraphLayout l = GraphLayout.parseInstance(affCache);
// Exclude nodes from estimation.
GraphLayout l2 = GraphLayout.parseInstance(nodes.toArray(new Object[nodes.size()]));
GraphLayout l3 = l.subtract(l2);
System.out.println("Heap usage [optimized=" + !disableOptimization + ", parts=" + parts + ", nodeCnt=" + nodeCnt + ", backups=" + backups + ", " + l3.toFootprint() + ']');
return l3.totalSize();
}
Aggregations