You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@mina.apache.org by Frank Kim <fr...@gmail.com> on 2010/04/20 22:26:10 UTC

SocketAcceptor pausing on CentOS

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]));
    }
}

Re: SocketAcceptor pausing on CentOS

Posted by David Rosenstrauch <da...@darose.net>.
On 04/20/2010 04:26 PM, Frank Kim wrote:
> 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

Maybe a garbage collection pause?

I was running into this on my MINA-based server, which is a customized 
memory cache (and hence runs into some memory/GC-based issues from time 
to time).  One thing that helped alleviate the problem was to switch to 
use the conncurrent garbage collector.  (See: 
http://java.sun.com/docs/hotspot/gc5.0/gc_tuning_5.html#0.0.0.%20When%20to%20Use%20the%20Concurrent%20Low%20Pause%20Collector%7Coutline) 
  You activate it by using the "-XX:+UseConcMarkSweepGC" switch at the 
Java command line.

HTH,

DR

Re: SocketAcceptor pausing on CentOS

Posted by Frank Kim <fr...@gmail.com>.
Emmanuel, turns out that the code I've previously included did not test my
issue in production exactly. The issue here was due to utilizing
Executors.newFixedThreadPool(threadCount) in the SocketAcceptor, and when I
switched over to Executors.newCachedThreadPool(), I did not see any pauses.
The Mina documentation recommends using newCachedThreadPool for
socketacceptor as it may lead to weird performance issues which I've faced
recently. The notable fact here is that on a 32bit system Redhat 5.1 running
JDK1.6, Executors.newFixedThreadPool performed flawlessly, and that's why
I've been using it for last 2 years. But when we moved up to 64Bit CentOS
the newFixedThreadPool produced weird results which originated this whole
thread.

Thanks,
Frank

On Wed, Apr 21, 2010 at 2:37 AM, Emmanuel Lécharny <el...@apache.org>wrote:

>
>> Emmanuel, thanks for the help, I think I narrowed it down to socket
>> acceptor
>> thread pool being stuck on "waiting on condition."
>>
>>
> Can you test your code with 1.1.7 ?
>
>
> --
> Regards,
> Cordialement,
> Emmanuel Lécharny
> www.nextury.com
>
>
>

Re: SocketAcceptor pausing on CentOS

Posted by Emmanuel Lécharny <el...@apache.org>.
>
> Emmanuel, thanks for the help, I think I narrowed it down to socket acceptor
> thread pool being stuck on "waiting on condition."
>    
Can you test your code with 1.1.7 ?

-- 
Regards,
Cordialement,
Emmanuel Lécharny
www.nextury.com



Re: SocketAcceptor pausing on CentOS

Posted by Frank Kim <fr...@gmail.com>.
Emmanuel, thanks for the help, I think I narrowed it down to socket acceptor
thread pool being stuck on "waiting on condition."

Frank

"pool-5-thread-1" prio=10 tid=0x0a258000 nid=0x4fe2 waiting on condition
[0xcf3ea000]
   java.lang.Thread.State: TIMED_WAITING (parking)
        at sun.misc.Unsafe.park(Native Method)
        - parking to wait for  <0xda2e8a20> (a
java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
        at
java.util.concurrent.locks.LockSupport.parkNanos(LockSupport.java:198)
        at
java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.awaitNanos(AbstractQueuedSynchronizer.java:1963)
        at java.util.concurrent.DelayQueue.take(DelayQueue.java:164)
        at
java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:583)
        at
java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:576)
        at
java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:947)
        at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:907)
        at java.lang.Thread.run(Thread.java:619)



On Tue, Apr 20, 2010 at 7:19 PM, Frank Kim <fr...@gmail.com> wrote:

> Emmanuel, I did not realize mina 1.1.4 is 3 years old, thanks for the
> insight. After some debugging, I realized that there is tons of waiting on
> condition - does anything seem odd here?
>
> "pool-1-thread-12" prio=10 tid=0x091d8800 nid=0x4be1 waiting on condition
> [0xccbb7000]
>    java.lang.Thread.State: WAITING (parking)
>         at sun.misc.Unsafe.park(Native Method)
>         - parking to wait for  <0xda130380> (a
> java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
>         at
> java.util.concurrent.locks.LockSupport.park(LockSupport.java:158)
>         at
> java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:1925)
>         at
> java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:399)
>         at
> java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:947)
>         at
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:907)
>         at java.lang.Thread.run(Thread.java:619)
> "pool-1-thread-11" prio=10 tid=0x090e0400 nid=0x4be0 waiting on condition
> [0xccc08000]
>    java.lang.Thread.State: WAITING (parking)
>         at sun.misc.Unsafe.park(Native Method)
>         - parking to wait for  <0xda130380> (a
> java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
>         at
> java.util.concurrent.locks.LockSupport.park(LockSupport.java:158)
>         at
> java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:1925)
>         at
> java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:399)
>         at
> java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:947)
>         at
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:907)
>         at java.lang.Thread.run(Thread.java:619)
> "pool-1-thread-10" prio=10 tid=0x090de800 nid=0x4bdf waiting on condition
> [0xccc59000]
>    java.lang.Thread.State: WAITING (parking)
>         at sun.misc.Unsafe.park(Native Method)
>         - parking to wait for  <0xda130380> (a
> java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
>         at
> java.util.concurrent.locks.LockSupport.park(LockSupport.java:158)
>         at
> java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:1925)
>         at
> java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:399)
>         at
> java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:947)
>         at
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:907)
>         at java.lang.Thread.run(Thread.java:619)
> "pool-3-thread-12" prio=10 tid=0x090dc800 nid=0x4bde waiting on condition
> [0xcccaa000]
>    java.lang.Thread.State: WAITING (parking)
>         at sun.misc.Unsafe.park(Native Method)
>         - parking to wait for  <0xda0702f8> (a
> java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
>         at
> java.util.concurrent.locks.LockSupport.park(LockSupport.java:158)
>         at
> java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:1925)
>         at
> java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:399)
>         at
> java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:947)
>         at
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:907)
>         at java.lang.Thread.run(Thread.java:619)
>
>
>   On Tue, Apr 20, 2010 at 6:30 PM, Emmanuel Lécharny <elecharny@apache.org
> > wrote:
>
>>
>>> Emmanuel, thanks for the reply
>>>
>>> JAVA IS
>>>
>>> java version "1.6.0_19"
>>> Java(TM) SE Runtime Environment (build 1.6.0_19-b04)
>>> Java HotSpot(TM) Server VM (build 16.2-b04, mixed mode)
>>>
>>>
>>> MINA 1.1.4
>>>
>>>
>> Woot !!! It's just 3 years old ! Have you tried 1.1.7 ?
>>
>>
>> --
>> Regards,
>> Cordialement,
>> Emmanuel Lécharny
>> www.nextury.com
>>
>>
>>
>

Re: SocketAcceptor pausing on CentOS

Posted by Frank Kim <fr...@gmail.com>.
Emmanuel, I did not realize mina 1.1.4 is 3 years old, thanks for the
insight. After some debugging, I realized that there is tons of waiting on
condition - does anything seem odd here?

"pool-1-thread-12" prio=10 tid=0x091d8800 nid=0x4be1 waiting on condition
[0xccbb7000]
   java.lang.Thread.State: WAITING (parking)
        at sun.misc.Unsafe.park(Native Method)
        - parking to wait for  <0xda130380> (a
java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
        at java.util.concurrent.locks.LockSupport.park(LockSupport.java:158)
        at
java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:1925)
        at
java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:399)
        at
java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:947)
        at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:907)
        at java.lang.Thread.run(Thread.java:619)
"pool-1-thread-11" prio=10 tid=0x090e0400 nid=0x4be0 waiting on condition
[0xccc08000]
   java.lang.Thread.State: WAITING (parking)
        at sun.misc.Unsafe.park(Native Method)
        - parking to wait for  <0xda130380> (a
java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
        at java.util.concurrent.locks.LockSupport.park(LockSupport.java:158)
        at
java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:1925)
        at
java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:399)
        at
java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:947)
        at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:907)
        at java.lang.Thread.run(Thread.java:619)
"pool-1-thread-10" prio=10 tid=0x090de800 nid=0x4bdf waiting on condition
[0xccc59000]
   java.lang.Thread.State: WAITING (parking)
        at sun.misc.Unsafe.park(Native Method)
        - parking to wait for  <0xda130380> (a
java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
        at java.util.concurrent.locks.LockSupport.park(LockSupport.java:158)
        at
java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:1925)
        at
java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:399)
        at
java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:947)
        at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:907)
        at java.lang.Thread.run(Thread.java:619)
"pool-3-thread-12" prio=10 tid=0x090dc800 nid=0x4bde waiting on condition
[0xcccaa000]
   java.lang.Thread.State: WAITING (parking)
        at sun.misc.Unsafe.park(Native Method)
        - parking to wait for  <0xda0702f8> (a
java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
        at java.util.concurrent.locks.LockSupport.park(LockSupport.java:158)
        at
java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:1925)
        at
java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:399)
        at
java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:947)
        at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:907)
        at java.lang.Thread.run(Thread.java:619)


On Tue, Apr 20, 2010 at 6:30 PM, Emmanuel Lécharny <el...@apache.org>wrote:

>
>> Emmanuel, thanks for the reply
>>
>> JAVA IS
>>
>> java version "1.6.0_19"
>> Java(TM) SE Runtime Environment (build 1.6.0_19-b04)
>> Java HotSpot(TM) Server VM (build 16.2-b04, mixed mode)
>>
>>
>> MINA 1.1.4
>>
>>
> Woot !!! It's just 3 years old ! Have you tried 1.1.7 ?
>
>
> --
> Regards,
> Cordialement,
> Emmanuel Lécharny
> www.nextury.com
>
>
>

Re: SocketAcceptor pausing on CentOS

Posted by Emmanuel Lécharny <el...@apache.org>.
>
> Emmanuel, thanks for the reply
>
> JAVA IS
>
> java version "1.6.0_19"
> Java(TM) SE Runtime Environment (build 1.6.0_19-b04)
> Java HotSpot(TM) Server VM (build 16.2-b04, mixed mode)
>
>
> MINA 1.1.4
>    
Woot !!! It's just 3 years old ! Have you tried 1.1.7 ?

-- 
Regards,
Cordialement,
Emmanuel Lécharny
www.nextury.com



Re: SocketAcceptor pausing on CentOS

Posted by Frank Kim <fr...@gmail.com>.
Emmanuel, thanks for the reply

JAVA IS

java version "1.6.0_19"
Java(TM) SE Runtime Environment (build 1.6.0_19-b04)
Java HotSpot(TM) Server VM (build 16.2-b04, mixed mode)


MINA 1.1.4

On Tue, Apr 20, 2010 at 5:25 PM, Emmanuel Lecharny <el...@gmail.com>wrote:

>
>> Hi all, I have 2 simple files attached to illustrate a issue on CentOS
>> 64Bit
>> running Java 1.6.
>>
> Which JVM ?
>
> 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.
>>
>>
> MINA version ?
>
> --
> Regards,
> Cordialement,
> Emmanuel Lécharny
> www.nextury.com
>
>
>

Re: SocketAcceptor pausing on CentOS

Posted by Emmanuel Lecharny <el...@gmail.com>.
>
> Hi all, I have 2 simple files attached to illustrate a issue on CentOS 64Bit
> running Java 1.6.
Which JVM ?
> 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.
>    
MINA version ?

-- 
Regards,
Cordialement,
Emmanuel Lécharny
www.nextury.com