Search in sources :

Example 1 with NonBlockingIOThread

use of com.hazelcast.internal.networking.nonblocking.NonBlockingIOThread 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 2 with NonBlockingIOThread

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

the class IOBalancer method tryMigrate.

private void tryMigrate(LoadImbalance loadImbalance) {
    MigratableHandler handler = strategy.findHandlerToMigrate(loadImbalance);
    if (handler == null) {
        logger.finest("I/O imbalance is detected, but no suitable migration candidate is found.");
        return;
    }
    NonBlockingIOThread destinationSelector = loadImbalance.destinationSelector;
    if (logger.isFinestEnabled()) {
        NonBlockingIOThread sourceSelector = loadImbalance.sourceSelector;
        logger.finest("Scheduling migration of handler " + handler + " from selector thread " + sourceSelector + " to " + destinationSelector);
    }
    handler.requestMigration(destinationSelector);
}
Also used : NonBlockingIOThread(com.hazelcast.internal.networking.nonblocking.NonBlockingIOThread) MigratableHandler(com.hazelcast.internal.networking.nonblocking.MigratableHandler)

Example 3 with NonBlockingIOThread

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

the class LoadTracker method printDebugTable.

private void printDebugTable() {
    if (!logger.isFinestEnabled()) {
        return;
    }
    NonBlockingIOThread minThread = imbalance.destinationSelector;
    NonBlockingIOThread maxThread = imbalance.sourceSelector;
    if (minThread == null || maxThread == null) {
        return;
    }
    StringBuilder sb = new StringBuilder(LINE_SEPARATOR).append("------------").append(LINE_SEPARATOR);
    Long eventCountPerSelector = selectorEvents.get(minThread);
    sb.append("Min Selector ").append(minThread).append(" received ").append(eventCountPerSelector).append(" events. ");
    sb.append("It contains following handlers: ").append(LINE_SEPARATOR);
    appendSelectorInfo(minThread, selectorToHandlers, sb);
    eventCountPerSelector = selectorEvents.get(maxThread);
    sb.append("Max Selector ").append(maxThread).append(" received ").append(eventCountPerSelector).append(" events. ");
    sb.append("It contains following handlers: ").append(LINE_SEPARATOR);
    appendSelectorInfo(maxThread, selectorToHandlers, sb);
    sb.append("Other Selectors: ").append(LINE_SEPARATOR);
    for (NonBlockingIOThread selector : ioThreads) {
        if (!selector.equals(minThread) && !selector.equals(maxThread)) {
            eventCountPerSelector = selectorEvents.get(selector);
            sb.append("Selector ").append(selector).append(" contains ").append(eventCountPerSelector).append(" and has these handlers: ").append(LINE_SEPARATOR);
            appendSelectorInfo(selector, selectorToHandlers, sb);
        }
    }
    sb.append("------------").append(LINE_SEPARATOR);
    logger.finest(sb.toString());
}
Also used : NonBlockingIOThread(com.hazelcast.internal.networking.nonblocking.NonBlockingIOThread)

Example 4 with NonBlockingIOThread

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

the class LoadTracker method updateHandlerState.

private void updateHandlerState(MigratableHandler handler) {
    long handlerEventCount = getEventCountSinceLastCheck(handler);
    handlerEventsCounter.set(handler, handlerEventCount);
    NonBlockingIOThread owner = handler.getOwner();
    selectorEvents.add(owner, handlerEventCount);
    Set<MigratableHandler> handlersOwnedBy = selectorToHandlers.get(owner);
    handlersOwnedBy.add(handler);
}
Also used : NonBlockingIOThread(com.hazelcast.internal.networking.nonblocking.NonBlockingIOThread) MigratableHandler(com.hazelcast.internal.networking.nonblocking.MigratableHandler)

Example 5 with NonBlockingIOThread

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

the class LoadTracker method updateNewFinalImbalance.

private void updateNewFinalImbalance() {
    imbalance.minimumEvents = Long.MAX_VALUE;
    imbalance.maximumEvents = Long.MIN_VALUE;
    imbalance.sourceSelector = null;
    imbalance.destinationSelector = null;
    for (NonBlockingIOThread selector : ioThreads) {
        long eventCount = selectorEvents.get(selector);
        int handlerCount = selectorToHandlers.get(selector).size();
        if (eventCount > imbalance.maximumEvents && handlerCount > 1) {
            // if a selector has only 1 handle, there is no point in making it a source selector since
            // there is no handler that can be migrated anyway. In that case it is better to move on to
            // the next selector.
            imbalance.maximumEvents = eventCount;
            imbalance.sourceSelector = selector;
        }
        if (eventCount < imbalance.minimumEvents) {
            imbalance.minimumEvents = eventCount;
            imbalance.destinationSelector = selector;
        }
    }
}
Also used : NonBlockingIOThread(com.hazelcast.internal.networking.nonblocking.NonBlockingIOThread)

Aggregations

NonBlockingIOThread (com.hazelcast.internal.networking.nonblocking.NonBlockingIOThread)9 MigratableHandler (com.hazelcast.internal.networking.nonblocking.MigratableHandler)5 TcpIpConnection (com.hazelcast.nio.tcp.TcpIpConnection)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 Set (java.util.Set)2 IMap (com.hazelcast.core.IMap)1 NonBlockingIOThreadingModel (com.hazelcast.internal.networking.nonblocking.NonBlockingIOThreadingModel)1 NonBlockingSocketReader (com.hazelcast.internal.networking.nonblocking.NonBlockingSocketReader)1 NonBlockingSocketWriter (com.hazelcast.internal.networking.nonblocking.NonBlockingSocketWriter)1 ILogger (com.hazelcast.logging.ILogger)1 TcpIpConnectionManager (com.hazelcast.nio.tcp.TcpIpConnectionManager)1 ParallelTest (com.hazelcast.test.annotation.ParallelTest)1 QuickTest (com.hazelcast.test.annotation.QuickTest)1 Map (java.util.Map)1 Before (org.junit.Before)1 Test (org.junit.Test)1