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;
}
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;
}
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);
}
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);
}
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);
}
Aggregations