You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@mina.apache.org by pongjy123 <15...@163.com> on 2014/05/08 08:59:39 UTC

use mina as a tcp client performance

hello,all


I have a problem,I have a java process(mina tcp client), need to connect 1000+ tcp server,my code is :
connector = new NioSocketConnector();
connector.getFilterChain().addLast("clientCodec", new ProtocolCodecFilter(new SplCodecFactory(true, type)));
connector.getSessionConfig().setReadBufferSize(MAX_READ_BUFF_SIZE);
connector.getSessionConfig().setUseReadOperation(true);
connector.setHandler(new SplClientIoHandler(this.receiver, connectorManager));
int count = 3;
while(--count >= 0){
if(count < 2){
logger.warn("retry connect count:"+count+",addr:"+addr);
}
ConnectFuture connFuture = connector.connect(addr);
connFuture.awaitUninterruptibly(CONNECT_TIMEOUT);
session = connFuture.getSession();
if(session == null){
if(count == 0){
throw new Exception("session is null!" + addr);
}
}else{
break;
}
}
connectState = ConnectState.CONNECTED;


The problem is mina created 1000+thread, So My Processor is so slow, 
Are there other ways to solve it? 
If I can just create a thread, with multiple objects to solve the problem? but i don't know how to do it.
Thanks.

Re: use mina as a tcp client performance

Posted by Jeff MAURY <je...@jeffmaury.com>.
Hello,

can you give the code for the rest of the application because I can't see
where all those threads are created (I see only 3 connections in your
sample).

Regards
Jeff


On Thu, May 8, 2014 at 8:59 AM, pongjy123 <15...@163.com> wrote:

> *hello,all*
>
> * I have a problem,I have a java process(mina tcp client), need to connect
> 1000+ tcp server,my code is :*
>  connector = new NioSocketConnector();
> connector.getFilterChain().addLast("clientCodec", new
> ProtocolCodecFilter(new SplCodecFactory(true, type)));
>  connector.getSessionConfig().setReadBufferSize(MAX_READ_BUFF_SIZE);
> connector.getSessionConfig().setUseReadOperation(true);
>  connector.setHandler(new SplClientIoHandler(this.receiver,
> connectorManager));
>  int count = 3;
>  while(--count >= 0){
> if(count < 2){
> logger.warn("retry connect count:"+count+",addr:"+addr);
>  }
> ConnectFuture connFuture = connector.connect(addr);
> connFuture.awaitUninterruptibly(CONNECT_TIMEOUT);
>  session = connFuture.getSession();
> if(session == null){
> if(count == 0){
>  throw new Exception("session is null!" + addr);
> }
> }else{
>  break;
> }
> }
> connectState = ConnectState.CONNECTED;
>
> *The problem is mina created 1000+thread, So My Processor is so slow, *
> *Are there other ways to solve it? *
> *If I can just create a thread, with multiple objects to solve the
> problem? but i don't know how to do it.*
> *Thanks.*
>
>
> 来自网易手机号码邮箱了解更多 <http://shouji.163.com>
>



-- 
Jeff MAURY


"Legacy code" often differs from its suggested alternative by actually
working and scaling.
 - Bjarne Stroustrup

http://www.jeffmaury.com
http://riadiscuss.jeffmaury.com
http://www.twitter.com/jeffmaury

Re: use mina as a tcp client performance

Posted by Emmanuel Lécharny <el...@gmail.com>.
Le 08/05/2014 08:59, pongjy123 a écrit :
> hello,all

Hi,

first, please send such mail to the users mailing list?. You are more
likely to get an answer. The dev list has a limited number of
subscribers, those who are working on MINA code.

Sorry for the delayed response, The ASF has experimented some huge
trouble this past 10 days with their mail system, this mail has only be
received yesterday...
>
>
> I have a problem,I have a java process(mina tcp client), need to connect 1000+ tcp server,my code is :
> connector = new NioSocketConnector();
> connector.getFilterChain().addLast("clientCodec", new ProtocolCodecFilter(new SplCodecFactory(true, type)));
> connector.getSessionConfig().setReadBufferSize(MAX_READ_BUFF_SIZE);
> connector.getSessionConfig().setUseReadOperation(true);
> connector.setHandler(new SplClientIoHandler(this.receiver, connectorManager));
> int count = 3;
> while(--count >= 0){
> if(count < 2){
> logger.warn("retry connect count:"+count+",addr:"+addr);
> }
> ConnectFuture connFuture = connector.connect(addr);
> connFuture.awaitUninterruptibly(CONNECT_TIMEOUT);
> session = connFuture.getSession();
> if(session == null){
> if(count == 0){
> throw new Exception("session is null!" + addr);
> }
> }else{
> break;
> }
> }
> connectState = ConnectState.CONNECTED;


This is the correct way to connect to the client, assuming you aren't
creating a new Connector for every single client.

Which version of MINA are you using ? Can you post us a threadDump, I'll
be curious to know what are those 1000 threads you are having (actually,
if you could have a test with 20 clients instead of 1000, that would be
easier ;-). Thanks !