Search in sources :

Example 1 with HistoryAffinityAssignment

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();
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) ConcurrentSkipListMap(java.util.concurrent.ConcurrentSkipListMap) GraphLayout(org.openjdk.jol.info.GraphLayout) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) ArrayList(java.util.ArrayList) HistoryAffinityAssignmentImpl(org.apache.ignite.internal.processors.affinity.HistoryAffinityAssignmentImpl) HistoryAffinityAssignment(org.apache.ignite.internal.processors.affinity.HistoryAffinityAssignment) GridAffinityAssignmentV2(org.apache.ignite.internal.processors.affinity.GridAffinityAssignmentV2) RendezvousAffinityFunction(org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

ArrayList (java.util.ArrayList)1 List (java.util.List)1 ConcurrentSkipListMap (java.util.concurrent.ConcurrentSkipListMap)1 RendezvousAffinityFunction (org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction)1 ClusterNode (org.apache.ignite.cluster.ClusterNode)1 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)1 GridAffinityAssignmentV2 (org.apache.ignite.internal.processors.affinity.GridAffinityAssignmentV2)1 HistoryAffinityAssignment (org.apache.ignite.internal.processors.affinity.HistoryAffinityAssignment)1 HistoryAffinityAssignmentImpl (org.apache.ignite.internal.processors.affinity.HistoryAffinityAssignmentImpl)1 GraphLayout (org.openjdk.jol.info.GraphLayout)1