Need advise on sockets
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Programming > Need advise on sockets




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    Need advise on sockets  
abhi147@gmail.com


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
09-16-06 06: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 !






[ Post a follow-up to this message ]



    Re: Need advise on sockets  
Maxim Yegorushkin


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
09-16-06 06: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).






[ Post a follow-up to this message ]



    Re: Need advise on sockets  
Rick Jones


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
09-16-06 06: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...





[ Post a follow-up to this message ]



    Re: Need advise on sockets  
Barry Margolin


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
09-16-06 06: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 ***





[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 04:08 AM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register