|
Home > Archive > Unix Programming > September 2006 > Need advise on sockets
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Need advise on sockets
|
|
| abhi147@gmail.com 2006-09-16, 1:43 pm |
| Hi ,
I have a program which has 1 client and 4 servers . Client
sends messages(every second) to all these 4 servers and recieves a
response from these servers . It has load balaning and failover logic
in it .
Now my question is , is it a good practice to connect to these servers
outside the while loop or should I connect these inside the loop(so
that client connect to server everytime a message is being sent ) ..
Wouldn't connecting and closing the socket every second be a load on
the system ?
Thanks !
| |
| Maxim Yegorushkin 2006-09-16, 1:43 pm |
| abhi147@gmail.com wrote:
> I have a program which has 1 client and 4 servers . Client
> sends messages(every second) to all these 4 servers and recieves a
> response from these servers . It has load balaning and failover logic
> in it .
> Now my question is , is it a good practice to connect to these servers
> outside the while loop or should I connect these inside the loop(so
> that client connect to server everytime a message is being sent ) ..
Assuming you use TCP, connecting to a server for each request results
in overhead of 6 ip datagrams (total: 3 for establishing a connection,
3 for tearing down). Whether it's an issue depends on your environment.
If it is, you might consider using udp or sctp to reduce the overhead.
> Wouldn't connecting and closing the socket every second be a load on
> the system ?
It depends on how often you do so. I once had an in-memory database
server on linux os. Protocol was simple: a client (php) connects to the
server, sends a request (add, get, update, delete), the server
responds, the client disconnects (i.e. a tcp connection for each
request). The request and response were less than 512 bytes long.
Serving 2500 tcp connection per second server used no more than 30% of
(one) cpu time (the server actually worked on a 4-core amd opteron, but
it only ever used one thread).
| |
| Rick Jones 2006-09-16, 1:43 pm |
| abhi147@gmail.com wrote:
> I have a program which has 1 client and 4 servers . Client
> sends messages(every second) to all these 4 servers and recieves a
> response from these servers . It has load balaning and failover logic
> in it .
> Now my question is , is it a good practice to connect to these servers
> outside the while loop or should I connect these inside the loop(so
> that client connect to server everytime a message is being sent ) ..
> Wouldn't connecting and closing the socket every second be a load on
> the system ?
Four messages a second... In broad practical terms at that load level
it does not matter unless you have especially wimpy hardware. In the
interest of dealing with the time when the load is much higher, I
would establish the connections once and leave them connected.
rick jones
--
web2.0 n, the dot.com reunion tour...
these opinions are mine, all mine; HP might not want them anyway... 
feel free to post, OR email to rick.jones2 in hp.com but NOT BOTH...
| |
| Barry Margolin 2006-09-16, 1:43 pm |
| In article <2JAOg.104$EW3.7@news.cpqcorp.net>,
Rick Jones <rick.jones2@hp.com> wrote:
> abhi147@gmail.com wrote:
>
>
> Four messages a second... In broad practical terms at that load level
> it does not matter unless you have especially wimpy hardware. In the
> interest of dealing with the time when the load is much higher, I
> would establish the connections once and leave them connected.
One issue with leaving them connected is that it's a bit more
complicated to deal with reconnecting when connections fail.
--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***
|
|
|
|
|