Search in sources :

Example 1 with TcpIpConnectionManager

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);
}
Also used : NodeIOService(com.hazelcast.nio.NodeIOService) SpinningIOThreadingModel(com.hazelcast.internal.networking.spinning.SpinningIOThreadingModel) IOThreadingModel(com.hazelcast.internal.networking.IOThreadingModel) NonBlockingIOThreadingModel(com.hazelcast.internal.networking.nonblocking.NonBlockingIOThreadingModel) TcpIpConnectionManager(com.hazelcast.nio.tcp.TcpIpConnectionManager)

Example 2 with TcpIpConnectionManager

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);
        }
    });
}
Also used : Address(com.hazelcast.nio.Address) Config(com.hazelcast.config.Config) IOException(java.io.IOException) IOException(java.io.IOException) HazelcastInstance(com.hazelcast.core.HazelcastInstance) AssertTask(com.hazelcast.test.AssertTask) TcpIpConnectionManager(com.hazelcast.nio.tcp.TcpIpConnectionManager) Socket(java.net.Socket) NightlyTest(com.hazelcast.test.annotation.NightlyTest) Test(org.junit.Test)

Example 3 with TcpIpConnectionManager

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);
        }
    });
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Config(com.hazelcast.config.Config) AssertTask(com.hazelcast.test.AssertTask) TcpIpConnectionManager(com.hazelcast.nio.tcp.TcpIpConnectionManager) IOException(java.io.IOException) HTTPCommunicator(com.hazelcast.internal.ascii.HTTPCommunicator) NightlyTest(com.hazelcast.test.annotation.NightlyTest) Test(org.junit.Test)

Example 4 with TcpIpConnectionManager

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;
    }
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) NonBlockingIOThread(com.hazelcast.internal.networking.nonblocking.NonBlockingIOThread) TcpIpConnectionManager(com.hazelcast.nio.tcp.TcpIpConnectionManager) MigratableHandler(com.hazelcast.internal.networking.nonblocking.MigratableHandler) HashMap(java.util.HashMap) Map(java.util.Map) IMap(com.hazelcast.core.IMap)

Aggregations

TcpIpConnectionManager (com.hazelcast.nio.tcp.TcpIpConnectionManager)4 Config (com.hazelcast.config.Config)2 HazelcastInstance (com.hazelcast.core.HazelcastInstance)2 AssertTask (com.hazelcast.test.AssertTask)2 NightlyTest (com.hazelcast.test.annotation.NightlyTest)2 IOException (java.io.IOException)2 Test (org.junit.Test)2 IMap (com.hazelcast.core.IMap)1 HTTPCommunicator (com.hazelcast.internal.ascii.HTTPCommunicator)1 IOThreadingModel (com.hazelcast.internal.networking.IOThreadingModel)1 MigratableHandler (com.hazelcast.internal.networking.nonblocking.MigratableHandler)1 NonBlockingIOThread (com.hazelcast.internal.networking.nonblocking.NonBlockingIOThread)1 NonBlockingIOThreadingModel (com.hazelcast.internal.networking.nonblocking.NonBlockingIOThreadingModel)1 SpinningIOThreadingModel (com.hazelcast.internal.networking.spinning.SpinningIOThreadingModel)1 Address (com.hazelcast.nio.Address)1 NodeIOService (com.hazelcast.nio.NodeIOService)1 Socket (java.net.Socket)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1