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