You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@mina.apache.org by "YoungJoon, Chun" <mo...@gmail.com> on 2007/09/08 04:10:53 UTC

using SocketConnector on not reachable address result in full cpu

Hello.

 

I'm using mina in my server application and the server also uses
SocketConnector to connect to client in some cases. Sometimes my server uses
CPU up to 100% and I found out that

when SocketConnector connects to an address which is not reachable (machine
is off), it just use up all cpu resource after some time trying to connect
(eg. 30 seconds).

 

A simple test application that uses SocketConnector also has same problem. 1
connection uses 50% cpu and

2 or more connections more cpu %.

 

The weird thing is even though machine is off and the address is not
reachable (no route to host with telnet), connection handler's (instance of
SingleSessionIoHandler) sessionOpened() method is called, though no further
progress. And setConnectTimeout() does not work and ConnectFuture is not
getting notified as well.

 

My debugging shows SocketIoProcessor thread seems to be the cause. Couldn't
figure out the detail yet.

Anyone is having the same problem with me?

 

I'm using mina 2.0 trunk (from maven repository) and java 1.6u2, Windows XP
SP2.

Thanks.

 


Re: using SocketConnector on not reachable address result in full cpu

Posted by Adam Fisk <a...@lastbamboo.org>.
Hmnn...makes sense now.  I catch the RuntimeIOs, but I don't see why you'd
want to keep looping.  Doesn't the RuntimeIOException simply indicate the
server didn't respond within the default timeout or some other legitimate
reason for a failure?  Why would you want to hammer the server like that?

On 9/10/07, mat <fo...@gmail.com> wrote:
>
> protected void connect() {
>   Logger.info(" connecting " + ip + ":" + port);
>   while (true) {
>    try {
>     ConnectFuture future = connector.connect(new InetSocketAddress(ip,
> port), handler, config);
>     future.join();
>     session = future.getSession();
>     Logger.info(" connected");
>     break;
>    }
>    catch( RuntimeIOException e ) {
>     Logger.info(" failed to connect " + ip + ":" + port);
>    }
>
>    try {
>     Logger.info(" reconnecting " + ip + ":" + port);
>     Thread.sleep(10000);
>    }
>    catch (InterruptedException e) {
>     e.printStackTrace();
>    }
>   }
> }
>
>
> On 9/11/07, Adam Fisk <a...@lastbamboo.org> wrote:
> >
> > So we should not be catching the RuntimeIOException, is that right?
> >
> > One way around all of this would be to use the
> > InetAddress.isReachablemethod before trying to connect.  I've found
> > that to be useful in my own
> > code.
> >
> > -Adam
> >
> >
> > On 9/8/07, mat <fo...@gmail.com> wrote:
> > >
> > > 1)  Please don't double post the same thread. Thanks.
> > > 2)  Did you catch RuntimeIOException after ConnectFuture future =
> > > connector.connect()? The reconnect in a infinite loop without
> > Thread.sleep
> > > ()
> > > normally causes 100% CPU usage.
> > >
> > >
> > > On 9/8/07, YoungJoon, Chun <mo...@gmail.com> wrote:
> > > >
> > > > Hello.
> > > >
> > > >
> > > >
> > > > I'm using mina in my server application and the server also uses
> > > > SocketConnector to connect to client in some cases. Sometimes my
> > server
> > > > uses
> > > > CPU up to 100% and I found out that
> > > >
> > > > when SocketConnector connects to an address which is not reachable
> > > > (machine
> > > > is off), it just use up all cpu resource after some time trying to
> > > connect
> > > > (eg. 30 seconds).
> > > >
> > > >
> > > >
> > > > A simple test application that uses SocketConnector also has same
> > > problem.
> > > > 1
> > > > connection uses 50% cpu and
> > > >
> > > > 2 or more connections more cpu %.
> > > >
> > > >
> > > >
> > > > The weird thing is even though machine is off and the address is not
> > > > reachable (no route to host with telnet), connection handler's
> > (instance
> > > > of
> > > > SingleSessionIoHandler) sessionOpened() method is called, though no
> > > > further
> > > > progress. And setConnectTimeout() does not work and ConnectFuture is
> > not
> > > > getting notified as well.
> > > >
> > > >
> > > >
> > > > My debugging shows SocketIoProcessor thread seems to be the cause.
> > > > Couldn't
> > > > figure out the detail yet.
> > > >
> > > > Anyone is having the same problem with me?
> > > >
> > > >
> > > >
> > > > I'm using mina 2.0 trunk (from maven repository) and java 1.6u2,
> > Windows
> > > > XP
> > > > SP2.
> > > >
> > > > Thanks.
> > > >
> > > >
> > > >
> > > >
> > >
> >
>

Re: using SocketConnector on not reachable address result in full cpu

Posted by mat <fo...@gmail.com>.
protected void connect() {
  Logger.info(" connecting " + ip + ":" + port);
  while (true) {
   try {
    ConnectFuture future = connector.connect(new InetSocketAddress(ip,
port), handler, config);
    future.join();
    session = future.getSession();
    Logger.info(" connected");
    break;
   }
   catch( RuntimeIOException e ) {
    Logger.info(" failed to connect " + ip + ":" + port);
   }

   try {
    Logger.info(" reconnecting " + ip + ":" + port);
    Thread.sleep(10000);
   }
   catch (InterruptedException e) {
    e.printStackTrace();
   }
  }
 }


On 9/11/07, Adam Fisk <a...@lastbamboo.org> wrote:
>
> So we should not be catching the RuntimeIOException, is that right?
>
> One way around all of this would be to use the
> InetAddress.isReachablemethod before trying to connect.  I've found
> that to be useful in my own
> code.
>
> -Adam
>
>
> On 9/8/07, mat <fo...@gmail.com> wrote:
> >
> > 1)  Please don't double post the same thread. Thanks.
> > 2)  Did you catch RuntimeIOException after ConnectFuture future =
> > connector.connect()? The reconnect in a infinite loop without
> Thread.sleep
> > ()
> > normally causes 100% CPU usage.
> >
> >
> > On 9/8/07, YoungJoon, Chun <mo...@gmail.com> wrote:
> > >
> > > Hello.
> > >
> > >
> > >
> > > I'm using mina in my server application and the server also uses
> > > SocketConnector to connect to client in some cases. Sometimes my
> server
> > > uses
> > > CPU up to 100% and I found out that
> > >
> > > when SocketConnector connects to an address which is not reachable
> > > (machine
> > > is off), it just use up all cpu resource after some time trying to
> > connect
> > > (eg. 30 seconds).
> > >
> > >
> > >
> > > A simple test application that uses SocketConnector also has same
> > problem.
> > > 1
> > > connection uses 50% cpu and
> > >
> > > 2 or more connections more cpu %.
> > >
> > >
> > >
> > > The weird thing is even though machine is off and the address is not
> > > reachable (no route to host with telnet), connection handler's
> (instance
> > > of
> > > SingleSessionIoHandler) sessionOpened() method is called, though no
> > > further
> > > progress. And setConnectTimeout() does not work and ConnectFuture is
> not
> > > getting notified as well.
> > >
> > >
> > >
> > > My debugging shows SocketIoProcessor thread seems to be the cause.
> > > Couldn't
> > > figure out the detail yet.
> > >
> > > Anyone is having the same problem with me?
> > >
> > >
> > >
> > > I'm using mina 2.0 trunk (from maven repository) and java 1.6u2,
> Windows
> > > XP
> > > SP2.
> > >
> > > Thanks.
> > >
> > >
> > >
> > >
> >
>

Re: using SocketConnector on not reachable address result in full cpu

Posted by Adam Fisk <a...@lastbamboo.org>.
So we should not be catching the RuntimeIOException, is that right?

One way around all of this would be to use the
InetAddress.isReachablemethod before trying to connect.  I've found
that to be useful in my own
code.

-Adam


On 9/8/07, mat <fo...@gmail.com> wrote:
>
> 1)  Please don't double post the same thread. Thanks.
> 2)  Did you catch RuntimeIOException after ConnectFuture future =
> connector.connect()? The reconnect in a infinite loop without Thread.sleep
> ()
> normally causes 100% CPU usage.
>
>
> On 9/8/07, YoungJoon, Chun <mo...@gmail.com> wrote:
> >
> > Hello.
> >
> >
> >
> > I'm using mina in my server application and the server also uses
> > SocketConnector to connect to client in some cases. Sometimes my server
> > uses
> > CPU up to 100% and I found out that
> >
> > when SocketConnector connects to an address which is not reachable
> > (machine
> > is off), it just use up all cpu resource after some time trying to
> connect
> > (eg. 30 seconds).
> >
> >
> >
> > A simple test application that uses SocketConnector also has same
> problem.
> > 1
> > connection uses 50% cpu and
> >
> > 2 or more connections more cpu %.
> >
> >
> >
> > The weird thing is even though machine is off and the address is not
> > reachable (no route to host with telnet), connection handler's (instance
> > of
> > SingleSessionIoHandler) sessionOpened() method is called, though no
> > further
> > progress. And setConnectTimeout() does not work and ConnectFuture is not
> > getting notified as well.
> >
> >
> >
> > My debugging shows SocketIoProcessor thread seems to be the cause.
> > Couldn't
> > figure out the detail yet.
> >
> > Anyone is having the same problem with me?
> >
> >
> >
> > I'm using mina 2.0 trunk (from maven repository) and java 1.6u2, Windows
> > XP
> > SP2.
> >
> > Thanks.
> >
> >
> >
> >
>

Re: using SocketConnector on not reachable address result in full cpu

Posted by Trustin Lee <tr...@gmail.com>.
Do you have any log file or full thread dump?  Please create a JIRA
issue and attach related files such as log file, full thread dump and
reproduceable code.

If you are using nabble.com forum, you can attach the files there too.

Trustin

On 9/11/07, YoungJoon, Chun <mo...@gmail.com> wrote:
>
>
> > -----Original Message-----
> > From: mat [mailto:forum.maillist@gmail.com]
> > Sent: Sunday, September 09, 2007 12:54 PM
> > To: dev@mina.apache.org
> > Subject: Re: using SocketConnector on not reachable address result in full
> > cpu
> >
> > 1)  Please don't double post the same thread. Thanks.
>
>
> Yep. Sorry:)
>
> > 2)  Did you catch RuntimeIOException after ConnectFuture future =
> > connector.connect()? The reconnect in a infinite loop without
> > Thread.sleep()
> > normally causes 100% CPU usage.
> >
>
>
>
> Exception is handled and There's no infinite loop or retry. Following is the
> test code.
>
>
>                 connector = new
> SocketConnector(Runtime.getRuntime().availableProcessors() + 1,
> Executors.newCachedThreadPool());
>                 VMPCodecFactory cf = new VMPCodecFactory();
>
>                 connector.getFilterChain().addLast(
>                                 "codec",
>                                 new ProtocolCodecFilter(cf));
>                 connector.getFilterChain().addLast("StreamWriter", new
> StreamWriteFilter());
>                 connector.getFilterChain().addLast("threadPool", new
> ExecutorFilter(Executors.newCachedThreadPool()));
>                 connector.getFilterChain().addLast( "logger", new
> LoggingFilter() );
>
>                 connector.setHandler(new SingleSessionIoHandlerDelegate(new
> SingleSessionIoHandlerFactory() {
>                         public SingleSessionIoHandler getHandler(IoSession
> session) {
>                                 return new TestHandler(session);
>                         }
>                 }));
>
>                 ...
>
>                 try
>                 {
>                 ConnectFuture future = connector.connect( new
> InetSocketAddress(addr, port) );
>                 future.addListener(new IoFutureListener() {
>                         public void operationComplete(IoFuture future)
>                         {
>                                 Exception handling here too but doesn't
> reach here
>                         }
>                 ...
>                 }
>                 catch(RuntimeException e)
>
>
> As I mentioned previously, Handler's sessionOpened() is magically called
> even though the machine is turned off.
> And after that, no further progress, and cpu goes up to 50% for that single
> connection.
> No error or exception returned.
>
> Thanks
>
>
>


-- 
what we call human nature is actually human habit
--
http://gleamynode.net/
--
PGP Key ID: 0x0255ECA6

RE: using SocketConnector on not reachable address result in full cpu

Posted by "YoungJoon, Chun" <mo...@gmail.com>.

> -----Original Message-----
> From: mat [mailto:forum.maillist@gmail.com]
> Sent: Sunday, September 09, 2007 12:54 PM
> To: dev@mina.apache.org
> Subject: Re: using SocketConnector on not reachable address result in full
> cpu
> 
> 1)  Please don't double post the same thread. Thanks.


Yep. Sorry:)

> 2)  Did you catch RuntimeIOException after ConnectFuture future =
> connector.connect()? The reconnect in a infinite loop without
> Thread.sleep()
> normally causes 100% CPU usage.
> 



Exception is handled and There's no infinite loop or retry. Following is the
test code.


		connector = new
SocketConnector(Runtime.getRuntime().availableProcessors() + 1,
Executors.newCachedThreadPool());
		VMPCodecFactory cf = new VMPCodecFactory();

		connector.getFilterChain().addLast(
				"codec",
				new ProtocolCodecFilter(cf));
		connector.getFilterChain().addLast("StreamWriter", new
StreamWriteFilter());
		connector.getFilterChain().addLast("threadPool", new
ExecutorFilter(Executors.newCachedThreadPool()));
		connector.getFilterChain().addLast( "logger", new
LoggingFilter() );

		connector.setHandler(new SingleSessionIoHandlerDelegate(new
SingleSessionIoHandlerFactory() {
			public SingleSessionIoHandler getHandler(IoSession
session) {
				return new TestHandler(session);
			}
		}));

		...

		try
		{
		ConnectFuture future = connector.connect( new
InetSocketAddress(addr, port) );
		future.addListener(new IoFutureListener() {
			public void operationComplete(IoFuture future)
			{
				Exception handling here too but doesn't
reach here
			}
		...
		}
		catch(RuntimeException e)


As I mentioned previously, Handler's sessionOpened() is magically called
even though the machine is turned off.
And after that, no further progress, and cpu goes up to 50% for that single
connection.
No error or exception returned.

Thanks



Re: using SocketConnector on not reachable address result in full cpu

Posted by mat <fo...@gmail.com>.
1)  Please don't double post the same thread. Thanks.
2)  Did you catch RuntimeIOException after ConnectFuture future =
connector.connect()? The reconnect in a infinite loop without Thread.sleep()
normally causes 100% CPU usage.


On 9/8/07, YoungJoon, Chun <mo...@gmail.com> wrote:
>
> Hello.
>
>
>
> I'm using mina in my server application and the server also uses
> SocketConnector to connect to client in some cases. Sometimes my server
> uses
> CPU up to 100% and I found out that
>
> when SocketConnector connects to an address which is not reachable
> (machine
> is off), it just use up all cpu resource after some time trying to connect
> (eg. 30 seconds).
>
>
>
> A simple test application that uses SocketConnector also has same problem.
> 1
> connection uses 50% cpu and
>
> 2 or more connections more cpu %.
>
>
>
> The weird thing is even though machine is off and the address is not
> reachable (no route to host with telnet), connection handler's (instance
> of
> SingleSessionIoHandler) sessionOpened() method is called, though no
> further
> progress. And setConnectTimeout() does not work and ConnectFuture is not
> getting notified as well.
>
>
>
> My debugging shows SocketIoProcessor thread seems to be the cause.
> Couldn't
> figure out the detail yet.
>
> Anyone is having the same problem with me?
>
>
>
> I'm using mina 2.0 trunk (from maven repository) and java 1.6u2, Windows
> XP
> SP2.
>
> Thanks.
>
>
>
>

Re: using SocketConnector on not reachable address result in full cpu

Posted by Trustin Lee <tr...@gmail.com>.
Any findings?

On 9/8/07, YoungJoon, Chun <mo...@gmail.com> wrote:
> Hello.
>
>
>
> I'm using mina in my server application and the server also uses
> SocketConnector to connect to client in some cases. Sometimes my server uses
> CPU up to 100% and I found out that
>
> when SocketConnector connects to an address which is not reachable (machine
> is off), it just use up all cpu resource after some time trying to connect
> (eg. 30 seconds).
>
>
>
> A simple test application that uses SocketConnector also has same problem. 1
> connection uses 50% cpu and
>
> 2 or more connections more cpu %.
>
>
>
> The weird thing is even though machine is off and the address is not
> reachable (no route to host with telnet), connection handler's (instance of
> SingleSessionIoHandler) sessionOpened() method is called, though no further
> progress. And setConnectTimeout() does not work and ConnectFuture is not
> getting notified as well.
>
>
>
> My debugging shows SocketIoProcessor thread seems to be the cause. Couldn't
> figure out the detail yet.
>
> Anyone is having the same problem with me?
>
>
>
> I'm using mina 2.0 trunk (from maven repository) and java 1.6u2, Windows XP
> SP2.
>
> Thanks.
>
>
>
>


-- 
what we call human nature is actually human habit
--
http://gleamynode.net/
--
PGP Key ID: 0x0255ECA6