-3

The server should response as soon as possible, isn't the server process always polling if there are requests? So, it would like a while loop. But why is not CPU(single core) all consumed if there is no visit?

heLomaN
  • 1,634
  • 2
  • 22
  • 33
  • 3
    You need to provide a lot more details like what server software and how it's configured. In general server's do not actively poll, they have the OS notify them when a new connection/data is available. Until then they just sleep. – kicken Mar 26 '16 at 08:07
  • @kicken Really sorry that I do not know much about server details; I meant the general intuition. Do you mean that it's some mechanism like hardware interruption? – heLomaN Mar 26 '16 at 08:47

2 Answers2

3

isn't the server process always polling?

Not if that's a reasonable implementation.

There are many implementations of HTTP servers, and communication servers in general, and polling is not a suitable architecture for any of these.

For example, some servers rely on asynchronous I/O operations using events, callbacks and so on. Other implementations rely on blocking socket APIs while operating in multi threaded modes, and there could be other architectures as well...

Amit
  • 45,440
  • 9
  • 78
  • 110
  • For using blocking socket APIs, when blocked, the process is stopped and is not consuming CPU; Is it? – heLomaN Mar 26 '16 at 08:51
  • @heLomaN - That's right. – Amit Mar 26 '16 at 09:02
  • For using `asynchronous I/O`, requests will trigger some actions to handle them. There is not a while main loop, but why the process is not terminated? A software with procedural programming should exit after running even it register some callbacks; then how be called when not running? – heLomaN Mar 26 '16 at 09:25
  • @heLomaN - the answer is OS & implementation dependent. I suggest you read about async I/O for your specific requirements. – Amit Mar 26 '16 at 09:58
0

isn't the server process always polling if there are requests?

No. It is blocking, in either an accept() call or a select() call. No polling.

user207421
  • 305,947
  • 44
  • 307
  • 483
  • FTR, there are other options (probably more likely) such as `epoll_wait()` -- and that's if we're not talking about Windows. – Yam Marcovic Mar 26 '16 at 08:59