phantom said:
Doing some intial reading I learned about socket pooling but there
are mixed reactions on pooling sockets, with some believing that
sockets are not too expensive when instantiating and some otherwise.
It would be great if somebody could help me with this.
I can't give you direct guidance, but some things to consider:
How long do you hold a connection open (if you're not using pooling), if it's
for any significant period of time then the cost of opening/closing a
connection will be completely trivial in comparison. OTOH, if you open a
connection, use it to send a handful of bytes, and then close it, then the
cost of setting up the connection and then tearing it down again will dominate
the overall network activity, so it may well be worth pooling.
Pooling can cut network traffic (since it avoids the flurries of small packets
that are used to open and close a TCP/IP connection -- I assume you are talking
about TCP/IP), but if you are not actually having network traffic problems,
then that doesn't seem to be a good argument for using pooling. Similarly,
pooling can cut the load on the machines' network stacks, but if you are not
actually being limited by that factor, then it's not an issue.
Another factor is that creating lots of connections in a short time can exhaust
the space of port numbers. There are various ways around that, one is to use
pooling.
Another factor is that the time taken setting up a connection goes up as the
number of network hops (and firewalls and what have you) between the two host
goes up. Opening a connection between two hosts on a LAN is much faster than
opening one between London and Tokyo.
Anyway, in summary, if you are using lots of short-lived connections, then
pooling may be worth considering. But what do "lots" and "short-lived" mean
here ? I've no idea -- that depends on your situation and your applications.
If you structure your code properly then it'll be simple to experiment with
pooling if you think it may be *in fact* affecting your application.
-- chris