Thanks Frederic ! It really helps to know how this could be implemented :) I would be trying out with a Manager class (something like a connectionFactory) which abstracts the connection nitty-gritties. But as Brad pointed out, i don't really need to worry abt pooling yet (since tomcat on the other end can be configured for that), am hoping the short lived connections will ensure only a few tens of connections at any given time. (will stress test that after i implement). and as for the hashmap - earlier i was using that approach but i felt storing my state in the session object was much cleaner (and recommended by the Mina community) .. so i'll go ahead with that.
I ran a profiler to check memory usage of the sample program i wrote. what i am doing in this program is that i have a class extending the IoHandlerAdaptor and i create a new instance of this in a thread for a couple of hundred connections. what i didn't understand is that, after the connection was closed, the memory used was still lurking around. I tried using a static instance of that class instead of new .. same behavior. i must be missing something and would be grateful if someone can point that out for me. am attaching the file if that helps. Thanks, vishal http://www.nabble.com/file/p13619922/Client3.java Client3.java Frédéric Brégier wrote: > > > In my project I use a pool of connections in one specific case since I > have > the following situation : > 1 Mina Main server gets transactions from outside applications (Mina > client) > or users (Tomcat with a Mina connector). > > Application Client makes one shot connection so there is no pool of > connection. > But in Tomcat (web services), multiple users/threads from Tomcat can > access > to the Mina Main server > through a connection. I've done some benchmark and I saw a big improvement > using a pool of connection > for Mina connector. > For the implementation, I implement something close to the database pool > of > connection. > The code is quite not clear since it is inside the main project which is > quite complex, but > if you think it could be useful, I can try to make a proposal of a subset > of > code that helps. > The main idea is at follow : > - One class take the role of the pool of connections (static object in > Java) > as with database pool. > Upper it, there is an hashmap bind to Mina Main server id (since in my > app there could be several Mina server > where Tomcat can connect to). If there is only one server as target, > this hashmap is unuseful. > In the pool of connections class, there is a Linked list of > connections > and a counter of initialized connections. > - One class take the role of a superset of Mina connections which includes > a > pointer to the pool of connections. > The methode close is created to close "virtually" the connection, in > fact returning it into the linked list. > - When 1 thread (Tomcat user) ask for a connection from the pool, the > scenario is as the following : > - if the list is empty, creates one new connection and return it. > - if the list is not empty, retrieve the first one (removing from the > list) and check if the connection is still ok > (using Mina method). If ok, it returns this connection. If not, > retry from the beginning. > - When 1 thread close the connection, it is simply add to the list. > The counter is used in order to not travel the linked list to count the > objects stored inside, so as to be efficient. > > My benchmark were done with and without this pool. I cannot find right now > the numbers, > but I remember it was really impressive (almost 5 time faster) under heavy > load. > > Hoping this can help you > > And finally for Trustin, my project is under production, at the time > beeing > for a subset only, > and we are waiting for the version 2 too since I saw that I need to change > quite a bit the code > since last huge work you (all) have done ! > So keep the good job done ! Thank you for this great project ! > > Frederic > ----- Original Message ----- > From: "Vishal_Jain" > > Thanks Brad for pointing that out ! > > am using Mina because what we need is a proxy service and a server > interface > (2 connectors tunneling messages and an acceptor which channels data to > one > of the connectors .. ) > > will check out if Jakarta HTTP client can be used for this .. :) > > -vishal > > > Brad Harvey-2 wrote: >> >> Hi Vishal, >> >> If you're talking standard client side HTTP, MINA might not be the best >> tool for the job. For example, see >> http://jakarta.apache.org/httpcomponents/httpclient-3.x/ >> >> One of the features you might be interested in: >> * Connection management support for use in multi-threaded applications. >> Supports setting the maximum total connections as well as the maximum >> connections per host. Detects and closes stale connections. >> >> Trustin mentioned that connection pools are useful when the cost of >> connection is relatively high (eg, SSL handshake). Another time they >> are useful is when you want to limit the number of connections to the >> server from a multi threaded client. This is often to conserve >> resources/limit load on the server. >> >> Cheers, >> Brad. >> >> Vishal_Jain wrote: >>> Thanks Trustin ! >>> >>> The server i have at my disposal is within the LAN (same subnet) and the >>> connection time i have noticed is about 50ms. >>> My dilemma is to whether accept 50ms as acceptable/reasonable or try >>> something to further reduce this. >>> Purpose is to connect to a HTTP server (tomcat actually) and >>> send/receive >>> requests (socket would close after every transaction); my aim is to keep >>> the >>> system decently scalable with heavy loads (am not sure about how heavy >>> it >>> could get yet). >>> >>> - vishal >>> >>> >>> Trustin Lee wrote: >>> >>>> On 11/6/07, Vishal_Jain <[EMAIL PROTECTED]> wrote: >>>> >>>>> Thats right. >>>>> I was wondering if someone in this forum has implemented a connection >>>>> pool >>>>> (not necessarily around Mina) and perhaps share with rest of newbies >>>>> like >>>>> me >>>>> ? :) >>>>> Another doubt i have is regarding keeping a pool of 'connected' >>>>> sockets. >>>>> How >>>>> useful is it to pull up a already connected socket and do a message >>>>> exchange >>>>> compared to creating and connecting a socket as and when required ? >>>>> >>>> I think it depends on the cost of making a connection. It's often >>>> very small and once connected, there's no problem with your bandwidth. >>>> If disconnection is unlikely, you could simply reconnect even if the >>>> connection cost is somewhat high. >>>> >>>> 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/Client-Connection-Pool-support-tf4722391s16868.html#a13602821 > Sent from the Apache MINA Support Forum mailing list archive at > Nabble.com. > > > > -- View this message in context: http://www.nabble.com/Client-Connection-Pool-support-tf4722391s16868.html#a13619922 Sent from the Apache MINA Support Forum mailing list archive at Nabble.com.
