1

I have started exploring on the network programming in Linux using Socket. I am wondering how come webservers like Yahoo, google, and etc are able to establish million/billions of connections. I believe the core is only socket programming to access the remote server. If that is the case then how come billion and millions of people are able to connect to the server. It means billions/millions of socket connection. This is not possible right? The spec says maximum 5 socket connections only. What is the mystery behind it?

Can you also speak in terms of this - API?

listen(sock,5);
dexterous
  • 6,422
  • 12
  • 51
  • 99
  • take a look on this http://stackoverflow.com/questions/2350071/maximum-number-of-concurrent-connections-on-a-single-port-socket-of-server – Leo Feb 08 '14 at 12:30

2 Answers2

0

To get an idea of tuning an individual server you may want to start with Apache Performance Tuning and maybe Linux Tuning Parameters, though it is somewhat outdated. Also see Upper limit of file descriptor in Linux

When you got a number of finely tuned servers, a network balancer is used and it typically distributes IP traffic across a cluster of such hosts. Sometimes a DNS load balancing is used in addition to further split between IP balancers.

Here, if you are interested you can follow Google's Compute Engine Load Balancing, which provides a single IP address, and does away with the need to have DNS balancing in addition, and reproduce their results:

The following instructions walk you step-by-step in setting up a Google Compute Load Balancer benchmark that achieves 1,000,000 Requests Per Second. It is the code and step were used when writing a blog post for the Google Cloud Platform blog. You can find the Google Cloud Platform blog @ http://googlecloudplatform.blogspot.com/ This GIST is a combination of instructions and scripts from Eric Hankland and Anthony F. Voellm. You are free to reuse the code snippets. https://gist.github.com/voellm/1370e09f7f394e3be724

Community
  • 1
  • 1
mockinterface
  • 14,452
  • 5
  • 28
  • 49
  • Does it mean that the same copy of server program is running on a various machines. Can I say these machines as the sub-servers or helper servers running the same piece of code. – dexterous Feb 08 '14 at 12:37
  • It means that the network balancer has a large cluster of web servers behind it, and it splits the requests among them. Yes, typically these web servers will be completely identical. – mockinterface Feb 08 '14 at 12:38
  • It depends on the descriptor limit. In a Linux machine it may be 2048 fd. Now, one machine can support a maximum upto 2048 connections. So, it all depends on the number of clusters as well as on the load balancing algorithm. Am I thinking correctly? – dexterous Feb 08 '14 at 12:44
  • No the limit on the number of fds is significantly higher. You will need to read about linux server tuning and increasing the maximum number of connections, say for Apache. There isn't a single source of information, so you may want to check serverfault and SO. But assuming you have highly tuned web servers, then you would put them behind a load balancer. – mockinterface Feb 08 '14 at 12:50
  • Thanks! By the way how many fd's we can have? Because fd will have only the meta data information. Is it equal to the number of inodes supported? – dexterous Feb 08 '14 at 12:56
  • I updated the answer. I don't think you'll get all the info in one answer to one question, there is a long road ahead for you of research and tuning for your scenario :) – mockinterface Feb 08 '14 at 12:59
  • How about listen(sock,5); – dexterous Feb 08 '14 at 14:00
  • cat /proc/sys/fs/file-max 380594 – dexterous Feb 08 '14 at 14:04
0

It doesn't 'say maximum 5 connections only'. The argument to listen() that you refer to is the backlog, not the total number of connections. It refers to the number of incoming connections that TCP will accept and hold on the 'backlog' queue() prior to the application getting hold of them via accept().

user207421
  • 305,947
  • 44
  • 307
  • 483
  • Does it mean that before calling accept, if any connections are missed, then based on the backlog number it can still retrieve those connections? – dexterous Feb 09 '14 at 07:08
  • It means that connections aren't 'missed' at all, they are accepted for you and put on the backlog queue, and that the backlog size has nothing to do with the maximum number of concurrent connections. – user207421 Feb 09 '14 at 09:22