You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@directory.apache.org by "Irving, Dave" <da...@logicacmg.com> on 2005/10/25 12:48:36 UTC

[mina] Writing to an IoSession

Hi,

Im writing an Http server based on Mina. The tutorial was great and got
me started in the right direction. I'm using a "stateful" parser
approach like that used in ASN1 - and it fitted in very nicely.
Currently, I can ** parse ** around 24,000 HTTP requests per second -
and with multiple (non-HTTP-pipelining) connections, I can service
around 700 requests a second. This will improve massively in a few days
when I implement keep-alive.
So - after that background, I first want to say a big thank-you for
MINA. So far, it has proved very stable, and very fast - and hey, I was
getting bored of writing selector loops anyway :o)

One question I do have: Currently Im holding on to the IoSession
associated with a request so that when a response becomes available
(asyncronously), it knows where to write it to. I cant see any other way
of knowing where a response is destined for.
E.g, (cut down, sort of psudo-code)


/**
 * Invoked asyncronously when a response is comitted - and ready to be 
 * written
 */
void handleResponse(Request req, Response resp, Object marker) {
  IoSession session = req.getContext().getSession();
  ByteBuffer buff = getBufferFor(resp);
  session.write(buff, marker);
}


Should I be holding on to sessions like this - or looking them up by
some other means?
It doesn't seem clear from the tutorial.

Many thanks,

Dave


This e-mail and any attachment is for authorised use by the intended recipient(s) only. It may contain proprietary material, confidential information and/or be subject to legal privilege. It should not be copied, disclosed to, retained or used by, any other party. If you are not an intended recipient then please promptly delete this e-mail and any attachment and all copies and inform the sender. Thank you.

Re: [mina] Writing to an IoSession

Posted by Trustin Lee <tr...@gmail.com>.
Hi Dave,

2005/10/25, Irving, Dave <da...@logicacmg.com>:
>
> Im writing an Http server based on Mina. The tutorial was great and got
> me started in the right direction. I'm using a "stateful" parser
> approach like that used in ASN1 - and it fitted in very nicely.
> Currently, I can ** parse ** around 24,000 HTTP requests per second -
> and with multiple (non-HTTP-pipelining) connections, I can service
> around 700 requests a second. This will improve massively in a few days
> when I implement keep-alive.
> So - after that background, I first want to say a big thank-you for
> MINA. So far, it has proved very stable, and very fast - and hey, I was
> getting bored of writing selector loops anyway :o)


This sounds great. It would be very great if you can provide us some
benchmark results against Tomcat and Apache HTTPD / Apache HTTPD 2 if you
can. Are you able to do that for us? Of course we can run benchmark by
ourselves if we can access your HTTP server implementation.

One question I do have: Currently Im holding on to the IoSession
> associated with a request so that when a response becomes available
> (asyncronously), it knows where to write it to. I cant see any other way
> of knowing where a response is destined for.
> E.g, (cut down, sort of psudo-code)
>
> /**
> * Invoked asyncronously when a response is comitted - and ready to be
> * written
> */
> void handleResponse(Request req, Response resp, Object marker) {
> IoSession session = req.getContext().getSession();
> ByteBuffer buff = getBufferFor(resp);
> session.write(buff, marker);
> }


Yes there's no other way to find out what session is associated with request
right now. But you could maintain an IdentityHashMap<Request, IoSession>
based on sessionOpened() and sessionCreated() event:

void handleResponse(Request req, Response resp, Object marker) {
IoSession session = req2sessionMap.get( req );
byteBuffer buf = getBufferFor( resp );
session.write( buf, marker );
}

BTW which version of MINA are you using? It seems like you're using only I/O
layer. Am I right?

HTH,
Trustin
--
what we call human nature is actually human habit
--
http://gleamynode.net/