use of com.hazelcast.nio.tcp.TcpIpConnectionManager in project hazelcast by hazelcast.
the class DefaultNodeContext method createConnectionManager.
@Override
public ConnectionManager createConnectionManager(Node node, ServerSocketChannel serverSocketChannel) {
NodeIOService ioService = new NodeIOService(node, node.nodeEngine);
IOThreadingModel ioThreadingModel = createTcpIpConnectionThreadingModel(node, ioService);
return new TcpIpConnectionManager(ioService, serverSocketChannel, node.loggingService, node.nodeEngine.getMetricsRegistry(), ioThreadingModel);
}
use of com.hazelcast.nio.tcp.TcpIpConnectionManager in project hazelcast by hazelcast.
the class IOBalancerMemoryLeakTest method testMemoryLeak_with_SocketConnections.
@Test
public void testMemoryLeak_with_SocketConnections() throws IOException {
Config config = new Config();
config.getGroupConfig().setName(randomName());
config.setProperty(GroupProperty.IO_BALANCER_INTERVAL_SECONDS.getName(), "1");
HazelcastInstance instance = Hazelcast.newHazelcastInstance(config);
final Address address = instance.getCluster().getLocalMember().getAddress();
int threadCount = 10;
final int connectionCountPerThread = 100;
Runnable runnable = new Runnable() {
public void run() {
for (int i = 0; i < connectionCountPerThread; i++) {
Socket socket = null;
try {
socket = new Socket(address.getHost(), address.getPort());
socket.getOutputStream().write(Protocols.CLUSTER.getBytes());
sleepMillis(1000);
socket.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
};
Thread[] threads = new Thread[threadCount];
for (int i = 0; i < threadCount; i++) {
threads[i] = new Thread(runnable);
threads[i].start();
}
assertJoinable(threads);
TcpIpConnectionManager connectionManager = (TcpIpConnectionManager) getConnectionManager(instance);
final IOBalancer ioBalancer = connectionManager.getIoBalancer();
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
LoadTracker inLoadTracker = ioBalancer.getInLoadTracker();
LoadTracker outLoadTracker = ioBalancer.getOutLoadTracker();
int inHandlerSize = inLoadTracker.getHandlers().size();
int outHandlerSize = outLoadTracker.getHandlers().size();
int inHandlerEventsCount = inLoadTracker.getHandlerEventsCounter().keySet().size();
int outHandlerEventsCount = outLoadTracker.getHandlerEventsCounter().keySet().size();
int inLastEventsCount = inLoadTracker.getLastEventCounter().keySet().size();
int outLastEventsCount = outLoadTracker.getLastEventCounter().keySet().size();
Assert.assertEquals(0, inHandlerSize);
Assert.assertEquals(0, outHandlerSize);
Assert.assertEquals(0, inHandlerEventsCount);
Assert.assertEquals(0, outHandlerEventsCount);
Assert.assertEquals(0, inLastEventsCount);
Assert.assertEquals(0, outLastEventsCount);
}
});
}
use of com.hazelcast.nio.tcp.TcpIpConnectionManager in project hazelcast by hazelcast.
the class IOBalancerMemoryLeakTest method testMemoryLeak_with_RestConnections.
@Test
public void testMemoryLeak_with_RestConnections() throws IOException {
Config config = new Config();
config.getGroupConfig().setName(randomName());
config.setProperty(GroupProperty.REST_ENABLED.getName(), "true");
config.setProperty(GroupProperty.IO_BALANCER_INTERVAL_SECONDS.getName(), "1");
HazelcastInstance instance = Hazelcast.newHazelcastInstance(config);
HTTPCommunicator communicator = new HTTPCommunicator(instance);
TcpIpConnectionManager connectionManager = (TcpIpConnectionManager) getConnectionManager(instance);
for (int i = 0; i < 100; i++) {
communicator.getClusterInfo();
}
final IOBalancer ioBalancer = connectionManager.getIoBalancer();
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
int inHandlerSize = ioBalancer.getInLoadTracker().getHandlers().size();
int outHandlerSize = ioBalancer.getOutLoadTracker().getHandlers().size();
Assert.assertEquals(0, inHandlerSize);
Assert.assertEquals(0, outHandlerSize);
}
});
}
use of com.hazelcast.nio.tcp.TcpIpConnectionManager in project hazelcast by hazelcast.
the class IOBalancerStressTest method assertBalanced.
private void assertBalanced(HazelcastInstance hz) {
TcpIpConnectionManager connectionManager = (TcpIpConnectionManager) getConnectionManager(hz);
Map<NonBlockingIOThread, Set<MigratableHandler>> handlersPerSelector = getHandlersPerSelector(connectionManager);
try {
for (Map.Entry<NonBlockingIOThread, Set<MigratableHandler>> entry : handlersPerSelector.entrySet()) {
NonBlockingIOThread selector = entry.getKey();
Set<MigratableHandler> handlers = entry.getValue();
assertBalanced(selector, handlers);
}
} catch (AssertionError e) {
// if something fails, we want to see the debug
System.out.println(debug(connectionManager));
throw e;
}
}
Aggregations