-1

I believe, Webserver like Apache uses socket programming only. In TCP connections, we need to call listen(sock_fd, number_of_backlogs); This backlog has a limit, generally in two digits. I am wondering how come a Apache webserver can establish millions of connections to their site. How listen() works there?

Cœur
  • 37,241
  • 25
  • 195
  • 267
dexterous
  • 6,422
  • 12
  • 51
  • 99
  • You asked the same question [yesterday](http://stackoverflow.com/questions/21656473/is-my-understanding-right-on-the-listen-system-call-on-backlog-and-the-number-of) and the answer is still the same. Please stop it. – user207421 Feb 11 '14 at 06:11
  • I am unable to understand, also this question was not directly asked, but was asked in the comments. I would be happy if someone can exemplify it. I am not able to understand the answer. – dexterous Feb 11 '14 at 06:39
  • The answer to this question appears in the previous question, and also in this [other question of yours](http://stackoverflow.com/questions/21645925/in-network-programming-there-is-a-limit-to-number-of-sockets-connections-how-w). You are mistaken about what the 'backlog' parameter means. It's as simple as that. Please stop asking the same question over and over and over again. If you don't understand an answer you're given, say so there. – user207421 Feb 11 '14 at 06:52
  • Sorry, you can say that I am dumb but I am unable to understand it. Can you please explain me with an example. My mind is waving between the maximum number of connections and the backlog parameter. I don't understand the backlog usecase at all. People say the kernel connections is related with backlog. I am not getting it. Please explain me for the last time with a gory details and use case. I would really appreciate that one. – dexterous Feb 11 '14 at 06:55
  • Nobody has said you are dumb. When you don't understand an answer, the thing to do here is not just to ask the same question over and over again. The thing to do is ask for clarification *in your original question.* Please take notice of how Stack Overflow is supposed to work, and indeed any other forum I have ever been a member of. And please see my answer below. – user207421 Feb 11 '14 at 07:06
  • 1
    Please don't ask this question again. EJP is about to explode and the outcome could be messy. – Martin James Feb 11 '14 at 19:02

3 Answers3

1

number_of_backlogs is not the number of total connections, but the maximum number of connections the OS kernel will establish before the user space process takes control of these connections by calling accept.

listen defines a kind of bucket, where new connections are put into by the OS. If the bucket is full (e.g. depending on the arguments to listen) new connections will be rejected. With accept() the user space application (e.g. web server, mail server...) will take one connection out of the bucket and handle it. These leaves the accepted connection open but makes place in the bucket for another connection. Thus a web server can handle 1000s of connections even if the bucket has only room for 50. In effect the number_of_backlogs defines only how often the user space process has to look into the bucket for new connections, e.g. the more connections come in within a time the more often it should look and take connections out of the bucket or the bigger the bucket should be.

Steffen Ullrich
  • 114,247
  • 10
  • 131
  • 172
  • +1 for what I am looking for. However, I couldn't understand this line - Thus a web server can handle 1000s of connections even if the bucket has only room for 50. Does it mean, if we make backlog as 1000 in the webserver application then it can handle 1000's of connections simultaneously. Does it mean, the webserver program like Apache are setting this backlog to some 1000's value. – dexterous Feb 12 '14 at 08:23
  • sorry, I give up explaining. Please get a book about basics of socket programming – Steffen Ullrich Feb 12 '14 at 11:18
  • I understand your position. Sorry for it. http://veithen.blogspot.in/2014/01/how-tcp-backlog-works-in-linux.html This was good one, may be guys like may find it suitable. So, basically there are two queues. In your language, bucket ( accept queue) and the internal queue ( where connection is not established yet). The listen will lookup in the accept queue. If 5 is described in the accept queue, it means it can look up for 5 connections. The other not established connections will be there in other queue. – dexterous Feb 12 '14 at 12:09
1

The value specified in listen() limits the size of the queue of pending clients that are waiting to be accepted by the server using accept(). Once a client has been accepted, it is no longer in the backlog queue. The backlog does not affect how many clients can be simultaneously connected to the server, only the number of clients that are trying and waiting to connect at any given moment.

user207421
  • 305,947
  • 44
  • 307
  • 483
Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
  • +1 but the last sentence is incorrect. The connection is fully established once the final ACK has been received. Nothing to do with `accept()` whatsoever. – user207421 Feb 11 '14 at 07:11
0

I am going to answer this once more, and once more only.

You have a complete misunderstanding, expressed in several questions over several days.

The backlog parameter to listen() isn't the total number of connections that can exist simultaneously.

It is the maximum number of connections that can exist on the backlog queue at the TCP level, before they have been returned to accept() in the application.

user207421
  • 305,947
  • 44
  • 307
  • 483