You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@mina.apache.org by angel figueroa <an...@updatecom.com> on 2007/05/02 06:43:22 UTC

Simultaneous reading and writing using mina

Hi,

   IF i development a Financial Transaction Server. The protocol is ISO
8583.  But the Bank Transaction Switch  will make a connection to our server
written in mina. But it Require that the incoming transaction be queue and
process but at the same time sending the response by the outgoing tcp
connection.

All example i review is more a conversational transaction. You received a
transaction. Process it and Response Back.

Is any example where you are simultaneous reading information. Other worker
Thread and processing information. Put the response in a Queue, where the
outgoing worker thread sent bank the response.


-- 
View this message in context: http://www.nabble.com/Simultaneous-reading-and-writing-using-mina-tf3678684.html#a10280101
Sent from the mina dev mailing list archive at Nabble.com.


Re: Simultaneous reading and writing using mina

Posted by Trustin Lee <tr...@gmail.com>.
On 5/3/07, Martin Ritchie <ri...@apache.org> wrote:
> The Qpid project developed just such a multi threaded SocketIOProcessor,
>
> https://issues.apache.org/jira/browse/DIRMINA-301
>
> This creates two worker threads, one to read from the socket and one
> to write data to the socket. We did see an improvement in performance
> but only when run a machine with sufficient cpus to handle the extra
> threads.
>
> We are going to be upgrading our Mina shortly and will be retesting
> the performance difference with this MultiThreadedIOProcessor against
> the default single threaded Mina Processor.
>
> Any problems with the code feel free to give me a shout. As Mina has
> moved on somewhat since I first wrote this.

Actually we didn't make any big improvement in the SocketIoProcessor
implementation.  Running some test after limiting the amount of data
written at once per session might make the performance test result
more fair.

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

Re: Simultaneous reading and writing using mina

Posted by Martin Ritchie <ri...@apache.org>.
The Qpid project developed just such a multi threaded SocketIOProcessor,

https://issues.apache.org/jira/browse/DIRMINA-301

This creates two worker threads, one to read from the socket and one
to write data to the socket. We did see an improvement in performance
but only when run a machine with sufficient cpus to handle the extra
threads.

We are going to be upgrading our Mina shortly and will be retesting
the performance difference with this MultiThreadedIOProcessor against
the default single threaded Mina Processor.

Any problems with the code feel free to give me a shout. As Mina has
moved on somewhat since I first wrote this.

Cheers

On 02/05/07, angel figueroa <an...@updatecom.com> wrote:
>
> The read and the write operation will occurs at the same time.
>
> It is possible to have a daemon thread one for reading and one for writing,
> and this two daemon thread is startup when the session is open.
>
> Another Worker Thread will be startup at the Application Startup. His jobs
> is to process all the transactions posted on the  reading
> LinkedBlockingQueue, process the transaction and place the response into the
> writing LinkedBlockingQueue. This two LinkedBlockingQueue will be share
> between all sessions.
>
> The Reading daemon thread will write the information to a reading
> LinkedBlockingQueue.
> The Writing daemon thread will read the information from the writing
> LinkedBlockingQueue.
>
> Both operation will be operating in parallel.
>
> Any suggestion how it can be accomplished with the mina.
>
>
> Eugene Labunsky-2 wrote:
> >
> > I'm not using read/write one time. Only write or read.
> >
> > 2007/5/2, angel figueroa <an...@updatecom.com>:
> >>
> >>
> >> But How You accomplish to read  and write from the socket connection at
> >> the
> >> same time?
> >>
> >>
> >> Trustin Lee wrote:
> >> >
> >> > On 5/2/07, angel figueroa <an...@updatecom.com> wrote:
> >> >>
> >> >> Hi,
> >> >>
> >> >>    IF i development a Financial Transaction Server. The protocol is
> >> ISO
> >> >> 8583.  But the Bank Transaction Switch  will make a connection to our
> >> >> server
> >> >> written in mina. But it Require that the incoming transaction be queue
> >> >> and
> >> >> process but at the same time sending the response by the outgoing tcp
> >> >> connection.
> >> >>
> >> >> All example i review is more a conversational transaction. You
> >> received
> >> a
> >> >> transaction. Process it and Response Back.
> >> >>
> >> >> Is any example where you are simultaneous reading information. Other
> >> >> worker
> >> >> Thread and processing information. Put the response in a Queue, where
> >> the
> >> >> outgoing worker thread sent bank the response.
> >> >
> >> > I'm not sure I understood every single line, but what I can say is
> >> > that the bottom line is that you can read and write at the same time.
> >> >
> >> > 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/Simultaneous-reading-and-writing-using-mina-tf3678684.html#a10280335
> >> Sent from the mina dev mailing list archive at Nabble.com.
> >>
> >>
> >
> >
> > --
> > Regards,
> > Eugene Labunsky.
> > http://www.TrendMedium.com - MetaStock Add-on
> >
> >
>
> --
> View this message in context: http://www.nabble.com/Simultaneous-reading-and-writing-using-mina-tf3678684.html#a10287085
> Sent from the mina dev mailing list archive at Nabble.com.
>
>


-- 
Martin Ritchie

Re: Simultaneous reading and writing using mina

Posted by angel figueroa <an...@updatecom.com>.
The read and the write operation will occurs at the same time.

It is possible to have a daemon thread one for reading and one for writing,
and this two daemon thread is startup when the session is open.

Another Worker Thread will be startup at the Application Startup. His jobs
is to process all the transactions posted on the  reading
LinkedBlockingQueue, process the transaction and place the response into the
writing LinkedBlockingQueue. This two LinkedBlockingQueue will be share
between all sessions.

The Reading daemon thread will write the information to a reading
LinkedBlockingQueue.
The Writing daemon thread will read the information from the writing
LinkedBlockingQueue.

Both operation will be operating in parallel.

Any suggestion how it can be accomplished with the mina. 


Eugene Labunsky-2 wrote:
> 
> I'm not using read/write one time. Only write or read.
> 
> 2007/5/2, angel figueroa <an...@updatecom.com>:
>>
>>
>> But How You accomplish to read  and write from the socket connection at
>> the
>> same time?
>>
>>
>> Trustin Lee wrote:
>> >
>> > On 5/2/07, angel figueroa <an...@updatecom.com> wrote:
>> >>
>> >> Hi,
>> >>
>> >>    IF i development a Financial Transaction Server. The protocol is
>> ISO
>> >> 8583.  But the Bank Transaction Switch  will make a connection to our
>> >> server
>> >> written in mina. But it Require that the incoming transaction be queue
>> >> and
>> >> process but at the same time sending the response by the outgoing tcp
>> >> connection.
>> >>
>> >> All example i review is more a conversational transaction. You
>> received
>> a
>> >> transaction. Process it and Response Back.
>> >>
>> >> Is any example where you are simultaneous reading information. Other
>> >> worker
>> >> Thread and processing information. Put the response in a Queue, where
>> the
>> >> outgoing worker thread sent bank the response.
>> >
>> > I'm not sure I understood every single line, but what I can say is
>> > that the bottom line is that you can read and write at the same time.
>> >
>> > 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/Simultaneous-reading-and-writing-using-mina-tf3678684.html#a10280335
>> Sent from the mina dev mailing list archive at Nabble.com.
>>
>>
> 
> 
> -- 
> Regards,
> Eugene Labunsky.
> http://www.TrendMedium.com - MetaStock Add-on
> 
> 

-- 
View this message in context: http://www.nabble.com/Simultaneous-reading-and-writing-using-mina-tf3678684.html#a10287085
Sent from the mina dev mailing list archive at Nabble.com.


Re: Simultaneous reading and writing using mina

Posted by Eugene Labunsky <el...@gmail.com>.
I'm not using read/write one time. Only write or read.

2007/5/2, angel figueroa <an...@updatecom.com>:
>
>
> But How You accomplish to read  and write from the socket connection at
> the
> same time?
>
>
> Trustin Lee wrote:
> >
> > On 5/2/07, angel figueroa <an...@updatecom.com> wrote:
> >>
> >> Hi,
> >>
> >>    IF i development a Financial Transaction Server. The protocol is ISO
> >> 8583.  But the Bank Transaction Switch  will make a connection to our
> >> server
> >> written in mina. But it Require that the incoming transaction be queue
> >> and
> >> process but at the same time sending the response by the outgoing tcp
> >> connection.
> >>
> >> All example i review is more a conversational transaction. You received
> a
> >> transaction. Process it and Response Back.
> >>
> >> Is any example where you are simultaneous reading information. Other
> >> worker
> >> Thread and processing information. Put the response in a Queue, where
> the
> >> outgoing worker thread sent bank the response.
> >
> > I'm not sure I understood every single line, but what I can say is
> > that the bottom line is that you can read and write at the same time.
> >
> > 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/Simultaneous-reading-and-writing-using-mina-tf3678684.html#a10280335
> Sent from the mina dev mailing list archive at Nabble.com.
>
>


-- 
Regards,
Eugene Labunsky.
http://www.TrendMedium.com - MetaStock Add-on

Re: Simultaneous reading and writing using mina

Posted by angel figueroa <an...@updatecom.com>.
It is possible to have a daemon thread one for reading and one form writing,
and this daemon thread is startup when the session is open.

Another Worker Thread will be startup at the Application Startup. His jobs
is to process all the transactions posted on the  reading
LinkedBlockingQueue, process the transaction and place the response into the
writing LinkedBlockingQueue. This two LinkedBlockingQueue will be share
between all sessions. 

The Reading daemon thread will write the information to a reading
LinkedBlockingQueue. 
The Writing daemon thread will read the information from the writing
LinkedBlockingQueue.

Both operation will be operating in parallel. 

Any suggestion how it can be accomplished with the mina. 




proyal wrote:
> 
> On May 2, 2007, at 7:44 AM, angel figueroa wrote:
>> In order to send information to the client. the client must sent a  
>> messages.
>> How you can change it in order to write to the session separately  
>> from the
>> messageReceived.  This is function more like synchronous  
>> communication.
>>
>> What i would like to accomplish is received messages and at the  
>> time time
>> writing message to the session?
> 
> You can call IoSession.write() anytime after the session is connected  
> (such as in IoHandler.sessionOpened)
> 
> -pete
> 
> 
> 
> -- 
> proyal@apache.org - http://fotap.org/~osi
> 
> 
> 
> 
>  
> 

-- 
View this message in context: http://www.nabble.com/Simultaneous-reading-and-writing-using-mina-tf3678684.html#a10287080
Sent from the mina dev mailing list archive at Nabble.com.


Re: Simultaneous reading and writing using mina

Posted by peter royal <pr...@apache.org>.
On May 2, 2007, at 7:44 AM, angel figueroa wrote:
> In order to send information to the client. the client must sent a  
> messages.
> How you can change it in order to write to the session separately  
> from the
> messageReceived.  This is function more like synchronous  
> communication.
>
> What i would like to accomplish is received messages and at the  
> time time
> writing message to the session?

You can call IoSession.write() anytime after the session is connected  
(such as in IoHandler.sessionOpened)

-pete



-- 
proyal@apache.org - http://fotap.org/~osi




Re: Simultaneous reading and writing using mina

Posted by angel figueroa <an...@updatecom.com>.
Take the Example from the TimeServer the messageReceived
	public void messageReceived(IoSession session, Object msg) throws Exception
{
		String str = msg.toString();
		if( str.trim().equalsIgnoreCase("quit") ) {
			session.close();
			return;
		}

		Date date = new Date();
		session.write( date.toString() );
		System.out.println("Message written...");
	}

In order to send information to the client. the client must sent a messages. 
How you can change it in order to write to the session separately from the
messageReceived.  This is function more like synchronous communication.

What i would like to accomplish is received messages and at the time time
writing message to the session?





Trustin Lee wrote:
> 
> On 5/2/07, angel figueroa <an...@updatecom.com> wrote:
>>
>> But How You accomplish to read  and write from the socket connection at
>> the
>> same time?
> 
> If you request a write operation, it is queued and performed in a
> background I/O thread.  All I/O operations are done in a separate I/O
> thread, so I/O occurs when you process events.
> 
> 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/Simultaneous-reading-and-writing-using-mina-tf3678684.html#a10280421
Sent from the mina dev mailing list archive at Nabble.com.


Re: Simultaneous reading and writing using mina

Posted by Trustin Lee <tr...@gmail.com>.
On 5/2/07, angel figueroa <an...@updatecom.com> wrote:
>
> But How You accomplish to read  and write from the socket connection at the
> same time?

If you request a write operation, it is queued and performed in a
background I/O thread.  All I/O operations are done in a separate I/O
thread, so I/O occurs when you process events.

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

Re: Simultaneous reading and writing using mina

Posted by angel figueroa <an...@updatecom.com>.
But How You accomplish to read  and write from the socket connection at the
same time?


Trustin Lee wrote:
> 
> On 5/2/07, angel figueroa <an...@updatecom.com> wrote:
>>
>> Hi,
>>
>>    IF i development a Financial Transaction Server. The protocol is ISO
>> 8583.  But the Bank Transaction Switch  will make a connection to our
>> server
>> written in mina. But it Require that the incoming transaction be queue
>> and
>> process but at the same time sending the response by the outgoing tcp
>> connection.
>>
>> All example i review is more a conversational transaction. You received a
>> transaction. Process it and Response Back.
>>
>> Is any example where you are simultaneous reading information. Other
>> worker
>> Thread and processing information. Put the response in a Queue, where the
>> outgoing worker thread sent bank the response.
> 
> I'm not sure I understood every single line, but what I can say is
> that the bottom line is that you can read and write at the same time.
> 
> 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/Simultaneous-reading-and-writing-using-mina-tf3678684.html#a10280335
Sent from the mina dev mailing list archive at Nabble.com.


Re: Simultaneous reading and writing using mina

Posted by Trustin Lee <tr...@gmail.com>.
On 5/2/07, angel figueroa <an...@updatecom.com> wrote:
>
> Hi,
>
>    IF i development a Financial Transaction Server. The protocol is ISO
> 8583.  But the Bank Transaction Switch  will make a connection to our server
> written in mina. But it Require that the incoming transaction be queue and
> process but at the same time sending the response by the outgoing tcp
> connection.
>
> All example i review is more a conversational transaction. You received a
> transaction. Process it and Response Back.
>
> Is any example where you are simultaneous reading information. Other worker
> Thread and processing information. Put the response in a Queue, where the
> outgoing worker thread sent bank the response.

I'm not sure I understood every single line, but what I can say is
that the bottom line is that you can read and write at the same time.

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