0

What is the overhead associated with keeping a socket open on the server?

Let's say that you've got millions of concurrent connections like facebook, would sockets add too much overhead compared to HTTP requests? I know that sockets will reduce network overhead by a good amount (because of headers), but would sockets be the better choice? If you don't update the client REAL-TIME, but still send batches of information (every few seconds or whenever the client requests) to the client which is the better option to serve these millions of users in terms of scalability, performance and server side overhead? (Would you have to scale more/faster using sockets or http?)

HelloWorld
  • 605
  • 1
  • 7
  • 22
  • "would sockets add too much overhead" - compared to what? "would sockets be the better choice" - compared to what? "I know that sockets will reduce network overhead by a good amount" - wat?? and so on... – Karoly Horvath Apr 20 '14 at 21:08
  • as compared to updating via HTTP requests or push notifications – HelloWorld Apr 20 '14 at 21:14
  • You should really do more research before asking. HTTP is a layer on top of sockets unless you are using some obscure OS which communicates using something other than sockets. You are also forgetting another important thing: Facebook do not have just one server. What do you think is easier to scale? Something using a standard protocol or something that you invented? – jgauffin Apr 20 '14 at 21:16
  • @Karoly I know that HTTP uses sockets. I'm talking about keeping a connection open rather than getting some information, closing the connection and then doing it all over again by sending HTTP headers again and such.. – HelloWorld Apr 20 '14 at 21:18
  • then talk about that. and please rewrite(edit) your question. – Karoly Horvath Apr 20 '14 at 21:20
  • @user2243357: You need to provide more information. HTTP keeps the connection open for a period of time (unless you use HTTP 1.0). You got WebSockets which keeps the connection open longer. So it's hard to understand what you mean – jgauffin Apr 20 '14 at 21:21
  • apparently this question has been poorly stated. I KNOW the difference. What I DONT KNOW is how much overhead keeping an open socket adds to the server (of course this depends on the language too) vs sending HTTP headers again and again and again for millions of connections. I'm not inventing sockets here.. And clearly facebook doesn't have one server.. – HelloWorld Apr 20 '14 at 21:21
  • or don't. it will be closed anyways as there's no simple yes/no answer for it. i'm sure it depends on the actual app. – Karoly Horvath Apr 20 '14 at 21:21
  • @user2243357 HTTP headers are sent back and forth no matter if you keep the connection open or not (HTTP Keep-Alive). For websockets they aren't. Still unclear what you are asking – jgauffin Apr 20 '14 at 21:23
  • you cannot seriously expect a definitive answer for "how much overhead", can you? – Karoly Horvath Apr 20 '14 at 21:23
  • Not so much definitive or quantitative, but in general would it be better to use websockets (or another form) or just send the HTTP requests over and over again. Because, the server will have to keep the open connections in memory and i'm wondering if this is going to cause too much vertical scaling (just per node) (could always just keep going horizontal) vs periodic HTTP requests. – HelloWorld Apr 20 '14 at 21:27
  • I will close this, but maybe HTTP keep-alive will be the better design choice. Cheers guys. Sorry for the poorly formulated question. – HelloWorld Apr 20 '14 at 21:30

1 Answers1

0

The correct question to ask is "How many sockets can I keep open per server".

It depends on the OS.

Linux:
The value set to net.ipv4.netfilter.ip_conntrack_max

https://serverfault.com/questions/10852/what-limits-the-maximum-number-of-connections-on-a-linux-server


Windows:

70,000 connections on a reasonably low spec VM

Max tcp/ip connections on Windows Server 2008


Then it of course depends on how well written your application is, the hardware spec etc etc.

So I would say that you should not design your application per the amount of open sockets because your application would probably crash and burn before the socket limit is reached.

Community
  • 1
  • 1
jgauffin
  • 99,844
  • 45
  • 235
  • 372