Search in sources :

Example 1 with MigratablePipeline

use of com.hazelcast.internal.networking.nio.MigratablePipeline in project hazelcast by hazelcast.

the class LoadMigrationStrategy method findPipelineToMigrate.

/**
 * Attempt to find a pipeline to migrate to a new NioThread.
 *
 * @param imbalance describing a snapshot of NioThread load
 * @return the pipeline to migrate to a new NioThread or null if no
 * pipeline needs to be migrated.
 */
@Override
public MigratablePipeline findPipelineToMigrate(LoadImbalance imbalance) {
    Set<? extends MigratablePipeline> candidates = imbalance.getPipelinesOwnedBy(imbalance.srcOwner);
    long migrationThreshold = (long) ((imbalance.maximumLoad - imbalance.minimumLoad) * MAXIMUM_NO_OF_EVENTS_AFTER_MIGRATION_COEFFICIENT);
    MigratablePipeline candidate = null;
    long loadInSelectedPipeline = 0;
    for (MigratablePipeline pipeline : candidates) {
        long load = imbalance.getLoad(pipeline);
        if (load > loadInSelectedPipeline) {
            if (load < migrationThreshold) {
                loadInSelectedPipeline = load;
                candidate = pipeline;
            }
        }
    }
    return candidate;
}
Also used : MigratablePipeline(com.hazelcast.internal.networking.nio.MigratablePipeline)

Example 2 with MigratablePipeline

use of com.hazelcast.internal.networking.nio.MigratablePipeline in project hazelcast by hazelcast.

the class IOBalancerStressTest method assertBalanced.

/**
 * An owner thread is balanced if it has no more than one "active" pipeline
 * and several non-active pipelines
 */
private void assertBalanced(Map<NioThread, Map<MigratablePipeline, Long>> pipelinesLoadPerOwnerBeforeLoad, HazelcastInstance hz) {
    // get pipelines load, grouped by the owner-thread, after the load
    Map<NioThread, Map<MigratablePipeline, Long>> pipelinesLoadPerOwnerAfterLoad = getPipelinesLoadPerOwner(hz);
    Map<MigratablePipeline, Long> pipelinesLoadBeforeLoad = getPipelinesLoad(pipelinesLoadPerOwnerBeforeLoad);
    try {
        for (Map.Entry<NioThread, Map<MigratablePipeline, Long>> entry : pipelinesLoadPerOwnerAfterLoad.entrySet()) {
            NioThread owner = entry.getKey();
            Map<MigratablePipeline, Long> pipelinesLoad = entry.getValue();
            // In a case of a pipeline with no new load, it will be skipped by IOBalancer
            if (pipelinesLoad.size() > 1) {
                int activePipelines = 0;
                for (Map.Entry<MigratablePipeline, Long> pipelineEntry : pipelinesLoad.entrySet()) {
                    long loadAfterLoad = pipelineEntry.getValue();
                    long loadBeforeLoad = pipelinesLoadBeforeLoad.get(pipelineEntry.getKey());
                    // as an active pipeline, if the load value hasn't changed - we skip it
                    if (loadBeforeLoad < loadAfterLoad) {
                        activePipelines++;
                    }
                }
                // Selector threads should have no more than one "active" pipeline
                assertTrue("The number of active pipelines for the owner " + owner + " is: " + activePipelines, activePipelines <= 1);
            }
        }
    } catch (AssertionError e) {
        // if something fails, we want to see the debug output
        System.out.println(debug(hz, pipelinesLoadPerOwnerBeforeLoad));
        throw e;
    }
}
Also used : NioThread(com.hazelcast.internal.networking.nio.NioThread) MigratablePipeline(com.hazelcast.internal.networking.nio.MigratablePipeline) Collectors.toMap(java.util.stream.Collectors.toMap) Map(java.util.Map) IMap(com.hazelcast.map.IMap)

Example 3 with MigratablePipeline

use of com.hazelcast.internal.networking.nio.MigratablePipeline in project hazelcast by hazelcast.

the class IOBalancerStressTest method debug.

private StringBuilder debug(Map<NioThread, Map<MigratablePipeline, Long>> pipelinesLoadPerOwnerBeforeLoad) {
    StringBuilder sbIn = new StringBuilder();
    sbIn.append("in owners\n");
    StringBuilder sbOut = new StringBuilder();
    sbOut.append("out owners\n");
    for (Map.Entry<NioThread, Map<MigratablePipeline, Long>> entry : pipelinesLoadPerOwnerBeforeLoad.entrySet()) {
        NioThread nioThread = entry.getKey();
        StringBuilder sb = nioThread.getName().contains("thread-in") ? sbIn : sbOut;
        sb.append(entry.getKey()).append("\n");
        for (Map.Entry<MigratablePipeline, Long> pipelineEntry : entry.getValue().entrySet()) {
            MigratablePipeline pipeline = pipelineEntry.getKey();
            sb.append("\t").append(pipeline).append(" load: ").append(pipelineEntry.getValue()).append("\n");
        }
    }
    return sbIn.append(sbOut);
}
Also used : NioThread(com.hazelcast.internal.networking.nio.NioThread) MigratablePipeline(com.hazelcast.internal.networking.nio.MigratablePipeline) Collectors.toMap(java.util.stream.Collectors.toMap) Map(java.util.Map) IMap(com.hazelcast.map.IMap)

Example 4 with MigratablePipeline

use of com.hazelcast.internal.networking.nio.MigratablePipeline in project hazelcast by hazelcast.

the class MonkeyMigrationStrategyTest method assertFairSelection.

private void assertFairSelection(int iterationCount, double toleranceFactor, MigratablePipeline pipeline1, MigratablePipeline pipeline2) {
    int pipeline1Count = 0;
    int pipeline2Count = 0;
    for (int i = 0; i < iterationCount; i++) {
        MigratablePipeline candidate = strategy.findPipelineToMigrate(imbalance);
        if (candidate == pipeline1) {
            pipeline1Count++;
        } else if (candidate == pipeline2) {
            pipeline2Count++;
        } else {
            fail("No pipeline selected");
        }
    }
    int diff = abs(pipeline1Count - pipeline2Count);
    assertTrue(diff < (iterationCount * toleranceFactor));
}
Also used : MigratablePipeline(com.hazelcast.internal.networking.nio.MigratablePipeline)

Example 5 with MigratablePipeline

use of com.hazelcast.internal.networking.nio.MigratablePipeline in project hazelcast by hazelcast.

the class MonkeyMigrationStrategyTest method findPipelineToMigrate_shouldBeFair.

@Test
public void findPipelineToMigrate_shouldBeFair() {
    int iterationCount = 10000;
    double toleranceFactor = 0.25d;
    MigratablePipeline pipeline1 = mock(MigratablePipeline.class);
    MigratablePipeline pipeline2 = mock(MigratablePipeline.class);
    ownerPipelines.put(imbalance.srcOwner, setOf(pipeline1, pipeline2));
    assertFairSelection(iterationCount, toleranceFactor, pipeline1, pipeline2);
}
Also used : MigratablePipeline(com.hazelcast.internal.networking.nio.MigratablePipeline) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

MigratablePipeline (com.hazelcast.internal.networking.nio.MigratablePipeline)14 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)8 QuickTest (com.hazelcast.test.annotation.QuickTest)8 Test (org.junit.Test)8 NioThread (com.hazelcast.internal.networking.nio.NioThread)4 IMap (com.hazelcast.map.IMap)2 Map (java.util.Map)2 Collectors.toMap (java.util.stream.Collectors.toMap)2