You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@mina.apache.org by Vishal_Jain <pi...@gmail.com> on 2007/12/04 11:02:50 UTC
Managing large number of Connectors
Hi All,
Am having a bit of confusion and appreciate any help from the community.
i want to manage a large number of connectors (which would connect to
different web servers). Am experimenting with Mina 2 and use the
AsyncHttpClient like code. Would we benefit in terms of performance/latency
if i were to add a ExecutorFilter ?
and if yes, am a bit confused about how to specify the executorfilter to the
connector. There seem to be two ways to associate the socket with an
ExecutorFilter/Executors;
1.connector.getFilterChain().addLast("threadPool", new
ExecutorFilter(Executors.newCachedThreadPool()));
2. connector = new
SocketConnector(Runtime.getRuntime().availableProcessors() + 1,
Executors.newCachedThreadPool());
are they equivalent ? and shouldn't i be using the same ExecutorFilter (in
1) for every connector's filter chain that i create ?
and similarly, shouldn't i be passing the same Executor object while
creating the connector ?
thanks.
--
View this message in context: http://www.nabble.com/Managing-large-number-of-Connectors-tf4942096s16868.html#a14147575
Sent from the Apache MINA Support Forum mailing list archive at Nabble.com.
Re: Managing large number of Connectors
Posted by Trustin Lee <tr...@gmail.com>.
Hi Luc,
On Dec 7, 2007 3:30 AM, Luc Willems <wi...@pandora.be> wrote:
> On Thursday 06 December 2007 07:27:17 Trustin Lee wrote:
> > Hi Vishal,
> >
> > On Dec 6, 2007 2:53 PM, Vishal_Jain <pi...@gmail.com> wrote:
> > > Hi Trustin,
> > >
> > > Yes i did try to follow the Thread model tutorial. As is evident, its not
> > > clear to me :)
> > >
> > > I seem to have missed to understand, One Connector tied with one I/O
> > > handler. Thanks for clearing that up for me.
> > > now, for every session that is created by calling connector.connect(), i
> > > need to attach some application specific data.
> > > Would it be ok to wait on the ConnectFuture object to join() and then add
> > > the data to the session attachment ?
> > > (i ask because, connection setup may take a while and in the meantime i
> > > would have received more requests to forward)
> >
> > ConnectFuture completes after sessionOpened event is processed.
> > Therefore, sessionCreated and sessionOpened event handlers will not
> > see the attachment. You could attach in your IoHandler, or you could
> > try org.apache.mina.handler.multiton package which helps you to create
> > a handler in a per-session manner.
> >
> hello all ,
>
> i have a same kind of problem when converting 1.1.x mina based code to
>
> 2.0.0.M1 codebase.
>
> I have some code that simulates a user. This user has a 1 instance of a Connection agent class that implements IoHandler interface
> and keeps track of communcation over 1 TCP connection. when de user need to send/connect to a remote server,
> it ask the agent to setup a connection.
>
> this agent class would do
>
> public void connect() {
> cf=connector.connect(address, null, this, config) --> where this is the Agent class
> cf.await();
> }
>
> public void sessionCreated(..) {
> this.session=session;
> }
>
> public void send() {
> this.session.write(message);
> }
>
> this way the agent class gets all the notification events and could handle the TCP
> communication from "just before" creation until the end.
> the user keeps a reference to the agent to delegate the IO requests.
> any message send before connection is finished can be buffered until the session is created.
> this way we don't have to wait until connection is finished ,or not.
>
> in MINA 2.0.0 i can't do this any more because connect() method has been simplified.
> in 2.0.0. i have to wait until connection is finished and after that a can attach my handler to
> the session and use a delegating IoHandler to delegate al events.
>
> i looked at the 2.0.0 org.apache.mina.handler.multiton classes but they don't implement what i need .
> it uses the SingleSessionIoHandlerFactory to link a just created IoSession with a SingleSessionIoHandler instance.
>
> the problem with this aproche is that the Factory doesn't know about my Agent class. we could implement
> a factory that keeps track of all Agents but how do we link agent.connect() with the just created IoSession in a
> multi thread save way without blocking ?
>
> it would be nice that connector.connect() would have a implementation that we
> could attach a object to this connection before IoSession is created or even better , like the 1.1.x example.
> this would make the SingleSessionIoHandler implementation simple by
> doing :
>
> - create custom class that extends/implements SingleSessionIoHandler/SingleSessionIo interface
> - use connector.connect(address,userIoHandler)
>
> after that all events should be deligated to userIoHandler.
I am not sure I understood your question correctly, but you might want
to create your own IoFilter and insert it to get notified before the
ConnectFuture is complete. If your custom IoFilter, you can relate
your Agent and IoSession easily.
Moreover, I think you can still do the same by calling the following
statement assuming you are using the same handler instance:
connector.setHandler(this);
HTH,
Trustin
--
what we call human nature is actually human habit
--
http://gleamynode.net/
--
PGP Key ID: 0x0255ECA6
Re: Managing large number of Connectors
Posted by Luc Willems <wi...@pandora.be>.
On Thursday 06 December 2007 07:27:17 Trustin Lee wrote:
> Hi Vishal,
>
> On Dec 6, 2007 2:53 PM, Vishal_Jain <pi...@gmail.com> wrote:
> > Hi Trustin,
> >
> > Yes i did try to follow the Thread model tutorial. As is evident, its not
> > clear to me :)
> >
> > I seem to have missed to understand, One Connector tied with one I/O
> > handler. Thanks for clearing that up for me.
> > now, for every session that is created by calling connector.connect(), i
> > need to attach some application specific data.
> > Would it be ok to wait on the ConnectFuture object to join() and then add
> > the data to the session attachment ?
> > (i ask because, connection setup may take a while and in the meantime i
> > would have received more requests to forward)
>
> ConnectFuture completes after sessionOpened event is processed.
> Therefore, sessionCreated and sessionOpened event handlers will not
> see the attachment. You could attach in your IoHandler, or you could
> try org.apache.mina.handler.multiton package which helps you to create
> a handler in a per-session manner.
>
hello all ,
i have a same kind of problem when converting 1.1.x mina based code to
2.0.0.M1 codebase.
I have some code that simulates a user. This user has a 1 instance of a Connection agent class that implements IoHandler interface
and keeps track of communcation over 1 TCP connection. when de user need to send/connect to a remote server,
it ask the agent to setup a connection.
this agent class would do
public void connect() {
cf=connector.connect(address, null, this, config) --> where this is the Agent class
cf.await();
}
public void sessionCreated(..) {
this.session=session;
}
public void send() {
this.session.write(message);
}
this way the agent class gets all the notification events and could handle the TCP
communication from "just before" creation until the end.
the user keeps a reference to the agent to delegate the IO requests.
any message send before connection is finished can be buffered until the session is created.
this way we don't have to wait until connection is finished ,or not.
in MINA 2.0.0 i can't do this any more because connect() method has been simplified.
in 2.0.0. i have to wait until connection is finished and after that a can attach my handler to
the session and use a delegating IoHandler to delegate al events.
i looked at the 2.0.0 org.apache.mina.handler.multiton classes but they don't implement what i need .
it uses the SingleSessionIoHandlerFactory to link a just created IoSession with a SingleSessionIoHandler instance.
the problem with this aproche is that the Factory doesn't know about my Agent class. we could implement
a factory that keeps track of all Agents but how do we link agent.connect() with the just created IoSession in a
multi thread save way without blocking ?
it would be nice that connector.connect() would have a implementation that we
could attach a object to this connection before IoSession is created or even better , like the 1.1.x example.
this would make the SingleSessionIoHandler implementation simple by
doing :
- create custom class that extends/implements SingleSessionIoHandler/SingleSessionIo interface
- use connector.connect(address,userIoHandler)
after that all events should be deligated to userIoHandler.
greetings,
luc
Re: Managing large number of Connectors
Posted by Trustin Lee <tr...@gmail.com>.
Hi Vishal,
On Dec 6, 2007 2:53 PM, Vishal_Jain <pi...@gmail.com> wrote:
> Hi Trustin,
>
> Yes i did try to follow the Thread model tutorial. As is evident, its not
> clear to me :)
>
> I seem to have missed to understand, One Connector tied with one I/O
> handler. Thanks for clearing that up for me.
> now, for every session that is created by calling connector.connect(), i
> need to attach some application specific data.
> Would it be ok to wait on the ConnectFuture object to join() and then add
> the data to the session attachment ?
> (i ask because, connection setup may take a while and in the meantime i
> would have received more requests to forward)
ConnectFuture completes after sessionOpened event is processed.
Therefore, sessionCreated and sessionOpened event handlers will not
see the attachment. You could attach in your IoHandler, or you could
try org.apache.mina.handler.multiton package which helps you to create
a handler in a per-session manner.
> I can imagine its not easy to put up with silly questions :)
> appreciate your patience.
Questions are always important to me because it gives everyone an idea
about improving MINA to reduce the number of questions. ;)
Cheers,
Trustin
--
what we call human nature is actually human habit
--
http://gleamynode.net/
--
PGP Key ID: 0x0255ECA6
Re: Managing large number of Connectors
Posted by Vishal_Jain <pi...@gmail.com>.
Hi Trustin,
Yes i did try to follow the Thread model tutorial. As is evident, its not
clear to me :)
I seem to have missed to understand, One Connector tied with one I/O
handler. Thanks for clearing that up for me.
now, for every session that is created by calling connector.connect(), i
need to attach some application specific data.
Would it be ok to wait on the ConnectFuture object to join() and then add
the data to the session attachment ?
(i ask because, connection setup may take a while and in the meantime i
would have received more requests to forward)
I can imagine its not easy to put up with silly questions :)
appreciate your patience.
vishal
Trustin Lee wrote:
>
> Hi Vishal,
>
> On Dec 4, 2007 7:02 PM, Vishal_Jain <pi...@gmail.com> wrote:
>>
>> Hi All,
>>
>> Am having a bit of confusion and appreciate any help from the community.
>>
>> i want to manage a large number of connectors (which would connect to
>> different web servers). Am experimenting with Mina 2 and use the
>> AsyncHttpClient like code. Would we benefit in terms of
>> performance/latency
>> if i were to add a ExecutorFilter ?
>
> It depends on what you do in your IoHandler implementation. If it's
> pure CPU logic, then you don't need an ExecutorFilter.
>
>> and if yes, am a bit confused about how to specify the executorfilter to
>> the
>> connector. There seem to be two ways to associate the socket with an
>> ExecutorFilter/Executors;
>> 1.connector.getFilterChain().addLast("threadPool", new
>> ExecutorFilter(Executors.newCachedThreadPool()));
>> 2. connector = new
>> SocketConnector(Runtime.getRuntime().availableProcessors() + 1,
>> Executors.newCachedThreadPool());
>>
>> are they equivalent ? and shouldn't i be using the same ExecutorFilter
>> (in
>> 1) for every connector's filter chain that i create ?
>> and similarly, shouldn't i be passing the same Executor object while
>> creating the connector ?
>
> They are different from each other. Are you sure you read the thread
> model tutorial? One connector (or one acceptor) takes one connector
> (or one acceptor) thread, so creating 100 connectors will create 100
> connector threads + 100 (or more) I/O worker threads. I'd recommend
> you to create only one connector and reuse it if all connections are
> categorized to the same service category; an IoService is essentially
> a logical grouping of sessions with the same IoHandler.
>
> HTH,
> Trustin
> --
> what we call human nature is actually human habit
> --
> http://gleamynode.net/
> --
> PGP Key ID: 0x0255ECA6
>
>
--
View this message in context: http://www.nabble.com/Managing-large-number-of-Connectors-tf4942096s16868.html#a14186786
Sent from the Apache MINA Support Forum mailing list archive at Nabble.com.
Re: Managing large number of Connectors
Posted by Trustin Lee <tr...@gmail.com>.
Hi Vishal,
On Dec 4, 2007 7:02 PM, Vishal_Jain <pi...@gmail.com> wrote:
>
> Hi All,
>
> Am having a bit of confusion and appreciate any help from the community.
>
> i want to manage a large number of connectors (which would connect to
> different web servers). Am experimenting with Mina 2 and use the
> AsyncHttpClient like code. Would we benefit in terms of performance/latency
> if i were to add a ExecutorFilter ?
It depends on what you do in your IoHandler implementation. If it's
pure CPU logic, then you don't need an ExecutorFilter.
> and if yes, am a bit confused about how to specify the executorfilter to the
> connector. There seem to be two ways to associate the socket with an
> ExecutorFilter/Executors;
> 1.connector.getFilterChain().addLast("threadPool", new
> ExecutorFilter(Executors.newCachedThreadPool()));
> 2. connector = new
> SocketConnector(Runtime.getRuntime().availableProcessors() + 1,
> Executors.newCachedThreadPool());
>
> are they equivalent ? and shouldn't i be using the same ExecutorFilter (in
> 1) for every connector's filter chain that i create ?
> and similarly, shouldn't i be passing the same Executor object while
> creating the connector ?
They are different from each other. Are you sure you read the thread
model tutorial? One connector (or one acceptor) takes one connector
(or one acceptor) thread, so creating 100 connectors will create 100
connector threads + 100 (or more) I/O worker threads. I'd recommend
you to create only one connector and reuse it if all connections are
categorized to the same service category; an IoService is essentially
a logical grouping of sessions with the same IoHandler.
HTH,
Trustin
--
what we call human nature is actually human habit
--
http://gleamynode.net/
--
PGP Key ID: 0x0255ECA6