Implmenting http persistent connections

MilanB milanbrahmbhatt at berkeley.edu
Thu Apr 30 19:19:37 EDT 2009


First off, Netty is very cool and very easily extensible.

I wrote an http client that makes many requests (even simultaneously) to the
same host:port and it's based on the http client example that's in the netty
example package.  I would like it to implement http persistent connection
(see http://www.w3.org/Protocols/rfc2616/rfc2616-sec8.html).  

I know I must set connection=keep-alive in the http out bound request and
don't close the channel once the http client receives a response; now to
actually implement the http persistent connection, I would want the
NioClientSocketChannelFactory to use existing established channels for new
requests if we've hit some bound on number of open connections to the same
host:port.  

So as an example, say I do the following: 

ChannelFactory factory =
            new NioClientSocketChannelFactory(
	                    my boss's cached thread pool executor,
	                    my worker's cached thread pool executor);

... 

set up the client bootstrap, set up the pipeline factory 
... 

start the connection attempt to the host:port by doing the following:
ChannelFuture future = bootstrap.connect(new InetSocketAddress(host, port));	
then eventually, once connected, write request to the established channel.  
... 

and then eventually close channel/ do some clean up
 

So this is how it would work for one request; now suppose I would like to
have a bound of 5 connections to host:port and I have 10 requests to make to
the same host:port.  So up until 5 connections, we would establish new
channels, but after 5 requests, I would like to reuse an existing
established channel.  Is there some trivial way of achieving this using the
NioCientSocketChannelFactory?  ( or do you think I would need to change the
implementation of the way boss threads work inteh channel factory -- since a
boss thread actually makes a connection attempt and gets the channel as per
the NioClientSocketChannelFactory javadoc ).  

Any insight on the matter is appreciated.  
thanks,
Milan

-- 
View this message in context: http://n2.nabble.com/Implmenting-http-persistent-connections-tp2750721p2750721.html
Sent from the Netty User Group mailing list archive at Nabble.com.




More information about the netty-users mailing list