Search in sources :

Example 1 with NioThread

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

the class LoadTracker method printDebugTable.

private void printDebugTable() {
    if (!logger.isFinestEnabled()) {
        return;
    }
    NioThread minThread = imbalance.dstOwner;
    NioThread maxThread = imbalance.srcOwner;
    if (minThread == null || maxThread == null) {
        return;
    }
    StringBuilder sb = new StringBuilder(LINE_SEPARATOR).append("------------").append(LINE_SEPARATOR);
    Long loadPerOwner = ownerLoad.get(minThread);
    sb.append("Min NioThread ").append(minThread).append(" receive-load ").append(loadPerOwner).append(" load. ");
    sb.append("It contains following pipelines: ").append(LINE_SEPARATOR);
    appendSelectorInfo(minThread, ownerToPipelines, sb);
    loadPerOwner = ownerLoad.get(maxThread);
    sb.append("Max NioThread ").append(maxThread).append(" receive-load ").append(loadPerOwner);
    sb.append("It contains following pipelines: ").append(LINE_SEPARATOR);
    appendSelectorInfo(maxThread, ownerToPipelines, sb);
    sb.append("Other NioThread: ").append(LINE_SEPARATOR);
    for (NioThread thread : ioThreads) {
        if (!thread.equals(minThread) && !thread.equals(maxThread)) {
            loadPerOwner = ownerLoad.get(thread);
            sb.append("NioThread ").append(thread).append(" contains ").append(loadPerOwner).append(" and has these pipelines: ").append(LINE_SEPARATOR);
            appendSelectorInfo(thread, ownerToPipelines, sb);
        }
    }
    sb.append("------------").append(LINE_SEPARATOR);
    logger.finest(sb.toString());
}
Also used : NioThread(com.hazelcast.internal.networking.nio.NioThread)

Example 2 with NioThread

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

the class LoadTracker method updateNewFinalImbalance.

private void updateNewFinalImbalance() {
    imbalance.minimumLoad = Long.MAX_VALUE;
    imbalance.maximumLoad = Long.MIN_VALUE;
    imbalance.srcOwner = null;
    imbalance.dstOwner = null;
    for (NioThread owner : ioThreads) {
        long load = ownerLoad.get(owner);
        int pipelineCount = ownerToPipelines.get(owner).size();
        if (load > imbalance.maximumLoad && pipelineCount > 1) {
            // if a nioThread has only 1 handle, there is no point in making it a source nioThread since
            // there is no pipeline that can be migrated anyway. In that case it is better to move on to
            // the next nioThread.
            imbalance.maximumLoad = load;
            imbalance.srcOwner = owner;
        }
        if (load < imbalance.minimumLoad) {
            imbalance.minimumLoad = load;
            imbalance.dstOwner = owner;
        }
    }
}
Also used : NioThread(com.hazelcast.internal.networking.nio.NioThread)

Example 3 with NioThread

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

the class LoadTracker method updatePipelineState.

private void updatePipelineState(MigratablePipeline pipeline) {
    long pipelineLoad = getLoadSinceLastCheck(pipeline);
    pipelineLoadCount.set(pipeline, pipelineLoad);
    NioThread owner = pipeline.owner();
    if (owner == null) {
        // the pipeline is currently being migrated - owner is null
        return;
    }
    ownerLoad.add(owner, pipelineLoad);
    ownerToPipelines.get(owner).add(pipeline);
}
Also used : NioThread(com.hazelcast.internal.networking.nio.NioThread)

Example 4 with NioThread

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

the class IOBalancerStressTest method debug.

private StringBuilder debug(HazelcastInstance hz) {
    TcpServer networkingService = (TcpServer) getNode(hz).getServer();
    NioNetworking networking = (NioNetworking) networkingService.getNetworking();
    ServerConnectionManager cm = getNode(hz).getServer().getConnectionManager(EndpointQualifier.MEMBER);
    StringBuilder sb = new StringBuilder();
    sb.append("in owners\n");
    for (NioThread in : networking.getInputThreads()) {
        sb.append(in).append(": ").append(in.getEventCount()).append("\n");
        for (ServerConnection connection : cm.getConnections()) {
            TcpServerConnection tcpConnection = (TcpServerConnection) connection;
            NioInboundPipeline inboundPipeline = ((NioChannel) tcpConnection.getChannel()).inboundPipeline();
            if (inboundPipeline.owner() == in) {
                sb.append("\t").append(inboundPipeline).append(" load: ").append(inboundPipeline.load()).append("\n");
            }
        }
    }
    sb.append("out owners\n");
    for (NioThread in : networking.getOutputThreads()) {
        sb.append(in).append(": ").append(in.getEventCount()).append("\n");
        for (ServerConnection connection : cm.getConnections()) {
            TcpServerConnection tcpConnection = (TcpServerConnection) connection;
            NioOutboundPipeline outboundPipeline = ((NioChannel) tcpConnection.getChannel()).outboundPipeline();
            if (outboundPipeline.owner() == in) {
                sb.append("\t").append(outboundPipeline).append(" load:").append(outboundPipeline.load()).append("\n");
            }
        }
    }
    return sb;
}
Also used : NioThread(com.hazelcast.internal.networking.nio.NioThread) ServerConnectionManager(com.hazelcast.internal.server.ServerConnectionManager) NioChannel(com.hazelcast.internal.networking.nio.NioChannel) ServerConnection(com.hazelcast.internal.server.ServerConnection) TcpServerConnection(com.hazelcast.internal.server.tcp.TcpServerConnection) NioNetworking(com.hazelcast.internal.networking.nio.NioNetworking) NioOutboundPipeline(com.hazelcast.internal.networking.nio.NioOutboundPipeline) TcpServer(com.hazelcast.internal.server.tcp.TcpServer) TcpServerConnection(com.hazelcast.internal.server.tcp.TcpServerConnection) NioInboundPipeline(com.hazelcast.internal.networking.nio.NioInboundPipeline)

Example 5 with NioThread

use of com.hazelcast.internal.networking.nio.NioThread 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)

Aggregations

NioThread (com.hazelcast.internal.networking.nio.NioThread)11 MigratablePipeline (com.hazelcast.internal.networking.nio.MigratablePipeline)4 IMap (com.hazelcast.map.IMap)3 Map (java.util.Map)3 Collectors.toMap (java.util.stream.Collectors.toMap)3 Test (org.junit.Test)2 Config (com.hazelcast.config.Config)1 HazelcastInstance (com.hazelcast.core.HazelcastInstance)1 NioChannel (com.hazelcast.internal.networking.nio.NioChannel)1 NioInboundPipeline (com.hazelcast.internal.networking.nio.NioInboundPipeline)1 NioNetworking (com.hazelcast.internal.networking.nio.NioNetworking)1 NioOutboundPipeline (com.hazelcast.internal.networking.nio.NioOutboundPipeline)1 ServerConnection (com.hazelcast.internal.server.ServerConnection)1 ServerConnectionManager (com.hazelcast.internal.server.ServerConnectionManager)1 TcpServer (com.hazelcast.internal.server.tcp.TcpServer)1 TcpServerConnection (com.hazelcast.internal.server.tcp.TcpServerConnection)1 ILogger (com.hazelcast.logging.ILogger)1 NightlyTest (com.hazelcast.test.annotation.NightlyTest)1 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)1 QuickTest (com.hazelcast.test.annotation.QuickTest)1