Hi all, I have 2 simple files attached to illustrate a issue on CentOS 64Bit
running Java 1.6. The basic issue is that the SocketAcceptor accept lot of
connections and then it would "pause" for few seconds at which point the the
SimpleServer stops accepting connections and then it would continue on
accepting more connections as if nothing had happened. Has anyone seen
something like this? I am bit stumped as everything works beautifully on
RedHat 5.1 (Tikanga) 32bit. I had check ulimit and it's currently at 8096,
the "pause" usually occurs after opening/closing for around 1200~ times. Any
insight would be very appreciated.

Thanks,
Frank


import java.net.InetSocketAddress;
import java.net.Socket;
import java.util.Random;

public class SimpleSocketClient
{
    public static void main(String[] args) throws Exception
    {
        try
        {
            for (int i = 0; i < Integer.parseInt(args[2]) ; i++)
            {
                Socket socket = new Socket();
                socket.connect(new InetSocketAddress(args[0],
Integer.parseInt(args[1])));
                System.out.println("** CONNECTED: " + i);

                socket.close();

                System.out.println("** CLOSED!!!");
                Thread.sleep(Math.abs(new Random().nextInt() %
Integer.parseInt(args[3])));

            }
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
    }
}

import java.net.InetSocketAddress;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Executors;

import org.apache.mina.common.DefaultIoFilterChainBuilder;
import org.apache.mina.common.IdleStatus;
import org.apache.mina.common.IoAcceptorConfig;
import org.apache.mina.common.IoHandler;
import org.apache.mina.common.IoSession;
import org.apache.mina.transport.socket.nio.SocketAcceptor;


public class SimpleServer implements IoHandler, Runnable
{
    protected List<IoSession> ioSessionList = new ArrayList<IoSession>();

    public void run()
    {
        System.out.println("[CONNECTION] " + ioSessionList.size() + " still
connected");
        // System.out.println("[SOCKET ACCEPTOR] " + acceptor.
    }

    @Override
    public void exceptionCaught(IoSession session, Throwable cause) throws
Exception
    {
        // TODO Auto-generated method stub

        cause.printStackTrace();
    }

    @Override
    public void messageReceived(IoSession session, Object message) throws
Exception
    {
        // TODO Auto-generated method stub

    }

    @Override
    public void messageSent(IoSession session, Object message) throws
Exception
    {
        // TODO Auto-generated method stub

    }

    @Override
    public void sessionClosed(IoSession session) throws Exception
    {
        // TODO Auto-generated method stub
        System.out.println("[CLOSED]");
        ioSessionList.remove(session);
    }

    @Override
    public void sessionCreated(IoSession session) throws Exception
    {
        // TODO Auto-generated method stub
        System.out.println("[CREATED]");
        ioSessionList.add(session);
    }

    @Override
    public void sessionIdle(IoSession session, IdleStatus status) throws
Exception
    {
        // TODO Auto-generated method stub

    }

    @Override
    public void sessionOpened(IoSession session) throws Exception
    {
        // TODO Auto-generated method stub

    }

    protected IoAcceptorConfig config;
    protected DefaultIoFilterChainBuilder chain;
    protected SocketAcceptor acceptor;

    public SimpleServer(String host, int port, int acceptorCount, int
threadPoolSize) throws Exception
    {

        acceptor = new SocketAcceptor(acceptorCount,
Executors.newFixedThreadPool(threadPoolSize));
        acceptor.bind(new InetSocketAddress(host, port), this);

        System.out.println("Listening on: " + host + "[" + port + "]");
        // chain.addLast("EODCodecFactory", new ProtocolCodecFilter(new
        // EODCodecFactory()));

    }

    public static void main(String[] args) throws Exception
    {

        if (args.length < 4)
        {
            System.out.println("SimpleServer <host> <port> <acceptorcount>
<threadpoolsize>");
            return;
        }
        new SimpleServer(args[0], Integer.parseInt(args[1]),
Integer.parseInt(args[2]), Integer.parseInt(args[3]));
    }
}

Reply via email to