use of org.apache.ignite.internal.processors.affinity.GridAffinityAssignmentV2 in project ignite by apache.
the class GridAffinityAssignmentJolBenchmark method measure.
/**
* @param aff Aff.
* @param parts Parts.
* @param nodeCnt Node count.
* @param backups Backups.
*/
private static void measure(RendezvousAffinityFunction aff, int parts, int nodeCnt, int backups) throws Exception {
List<ClusterNode> nodes = new ArrayList<>();
for (int i = 0; i < nodeCnt; i++) {
ClusterNode node = node(i);
nodes.add(node);
}
AffinityFunctionContext ctx = new GridAffinityFunctionContextImpl(nodes, new ArrayList<>(), new DiscoveryEvent(), new AffinityTopologyVersion(), backups);
List<List<ClusterNode>> assignment = aff.assignPartitions(ctx);
setOptimization(false);
GridAffinityAssignmentV2 ga = new GridAffinityAssignmentV2(new AffinityTopologyVersion(1, 0), assignment, new ArrayList<>());
System.gc();
long totalSize = GraphLayout.parseInstance(ga).totalSize();
System.out.println("Optimized, parts " + parts + " nodeCount " + nodeCnt + " backups " + backups + " " + totalSize);
setOptimization(true);
GridAffinityAssignmentV2 ga2 = new GridAffinityAssignmentV2(new AffinityTopologyVersion(1, 0), assignment, new ArrayList<>());
System.gc();
long totalSize2 = GraphLayout.parseInstance(ga2).totalSize();
System.out.println("Deoptimized, parts " + parts + " nodeCount " + nodeCnt + " backups " + backups + " " + totalSize2);
if (totalSize > totalSize2)
throw new Exception("Optimized AffinityAssignment size " + totalSize + " is more than deoptimized " + totalSize2);
}
use of org.apache.ignite.internal.processors.affinity.GridAffinityAssignmentV2 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