Search in sources :

Example 1 with MigratableHandler

use of com.hazelcast.internal.networking.nonblocking.MigratableHandler in project hazelcast by hazelcast.

the class EventCountBasicMigrationStrategy method findHandlerToMigrate.

/**
     * Attempt to find a handler to migrate to a new NonBlockingIOThread.
     *
     * @param imbalance describing a snapshot of NonBlockingIOThread load
     * @return the handler to migrate to a new NonBlockingIOThread or null if no handler needs to be migrated.
     */
@Override
public MigratableHandler findHandlerToMigrate(LoadImbalance imbalance) {
    Set<? extends MigratableHandler> candidates = imbalance.getHandlersOwnerBy(imbalance.sourceSelector);
    long migrationThreshold = (long) ((imbalance.maximumEvents - imbalance.minimumEvents) * MAXIMUM_NO_OF_EVENTS_AFTER_MIGRATION_COEFFICIENT);
    MigratableHandler candidate = null;
    long eventCountInSelectedHandler = 0;
    for (MigratableHandler handler : candidates) {
        long eventCount = imbalance.getEventCount(handler);
        if (eventCount > eventCountInSelectedHandler) {
            if (eventCount < migrationThreshold) {
                eventCountInSelectedHandler = eventCount;
                candidate = handler;
            }
        }
    }
    return candidate;
}
Also used : MigratableHandler(com.hazelcast.internal.networking.nonblocking.MigratableHandler)

Example 2 with MigratableHandler

use of com.hazelcast.internal.networking.nonblocking.MigratableHandler in project hazelcast by hazelcast.

the class IOBalancerStressTest method getHandlersPerSelector.

private Map<NonBlockingIOThread, Set<MigratableHandler>> getHandlersPerSelector(TcpIpConnectionManager connectionManager) {
    Map<NonBlockingIOThread, Set<MigratableHandler>> handlersPerSelector = new HashMap<NonBlockingIOThread, Set<MigratableHandler>>();
    for (TcpIpConnection connection : connectionManager.getActiveConnections()) {
        add(handlersPerSelector, (MigratableHandler) connection.getSocketReader());
        add(handlersPerSelector, (MigratableHandler) connection.getSocketWriter());
    }
    return handlersPerSelector;
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) NonBlockingIOThread(com.hazelcast.internal.networking.nonblocking.NonBlockingIOThread) HashMap(java.util.HashMap) TcpIpConnection(com.hazelcast.nio.tcp.TcpIpConnection) MigratableHandler(com.hazelcast.internal.networking.nonblocking.MigratableHandler)

Example 3 with MigratableHandler

use of com.hazelcast.internal.networking.nonblocking.MigratableHandler in project hazelcast by hazelcast.

the class LoadTrackerTest method testUpdateImbalance.

@Test
public void testUpdateImbalance() throws Exception {
    MigratableHandler selector1Handler1 = mock(MigratableHandler.class);
    when(selector1Handler1.getEventCount()).thenReturn(0l).thenReturn(100l);
    when(selector1Handler1.getOwner()).thenReturn(selector1);
    loadTracker.addHandler(selector1Handler1);
    MigratableHandler selector2Handler1 = mock(MigratableHandler.class);
    when(selector2Handler1.getEventCount()).thenReturn(0l).thenReturn(200l);
    when(selector2Handler1.getOwner()).thenReturn(selector2);
    loadTracker.addHandler(selector2Handler1);
    MigratableHandler selector2Handler3 = mock(MigratableHandler.class);
    when(selector2Handler3.getEventCount()).thenReturn(0l).thenReturn(100l);
    when(selector2Handler3.getOwner()).thenReturn(selector2);
    loadTracker.addHandler(selector2Handler3);
    LoadImbalance loadImbalance = loadTracker.updateImbalance();
    assertEquals(0, loadImbalance.minimumEvents);
    assertEquals(0, loadImbalance.maximumEvents);
    loadTracker.updateImbalance();
    assertEquals(100, loadImbalance.minimumEvents);
    assertEquals(300, loadImbalance.maximumEvents);
    assertEquals(selector1, loadImbalance.destinationSelector);
    assertEquals(selector2, loadImbalance.sourceSelector);
}
Also used : MigratableHandler(com.hazelcast.internal.networking.nonblocking.MigratableHandler) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 4 with MigratableHandler

use of com.hazelcast.internal.networking.nonblocking.MigratableHandler in project hazelcast by hazelcast.

the class MonkeyMigrationStrategyTest method findHandlerToMigrate_shouldWorkEvenWithASingleHandlerAvailable.

@Test
public void findHandlerToMigrate_shouldWorkEvenWithASingleHandlerAvailable() {
    MigratableHandler handler = mock(MigratableHandler.class);
    selectorToHandlers.put(imbalance.sourceSelector, setOf(handler));
    MigratableHandler handlerToMigrate = strategy.findHandlerToMigrate(imbalance);
    assertEquals(handler, handlerToMigrate);
}
Also used : MigratableHandler(com.hazelcast.internal.networking.nonblocking.MigratableHandler) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 5 with MigratableHandler

use of com.hazelcast.internal.networking.nonblocking.MigratableHandler in project hazelcast by hazelcast.

the class MonkeyMigrationStrategyTest method findHandlerToMigrate_shouldBeFair.

@Test
public void findHandlerToMigrate_shouldBeFair() {
    int iterationCount = 10000;
    double toleranceFactor = 0.25d;
    MigratableHandler handler1 = mock(MigratableHandler.class);
    MigratableHandler handler2 = mock(MigratableHandler.class);
    selectorToHandlers.put(imbalance.sourceSelector, setOf(handler1, handler2));
    assertFairSelection(iterationCount, toleranceFactor, handler1, handler2);
}
Also used : MigratableHandler(com.hazelcast.internal.networking.nonblocking.MigratableHandler) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

MigratableHandler (com.hazelcast.internal.networking.nonblocking.MigratableHandler)14 ParallelTest (com.hazelcast.test.annotation.ParallelTest)6 QuickTest (com.hazelcast.test.annotation.QuickTest)6 Test (org.junit.Test)6 NonBlockingIOThread (com.hazelcast.internal.networking.nonblocking.NonBlockingIOThread)5 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 Set (java.util.Set)2 IMap (com.hazelcast.core.IMap)1 TcpIpConnection (com.hazelcast.nio.tcp.TcpIpConnection)1 TcpIpConnectionManager (com.hazelcast.nio.tcp.TcpIpConnectionManager)1 Map (java.util.Map)1