Как веб-серверы прослушивают новые запросы?

Оглавление:

Как веб-серверы прослушивают новые запросы?
Как веб-серверы прослушивают новые запросы?

Видео: Как веб-серверы прослушивают новые запросы?

Видео: Как веб-серверы прослушивают новые запросы?
Видео: ВСЕ ПРО GOOGLE ТАБЛИЦЫ ЗА 13 МИНУТ | Как пользоваться? Видеоурок | Алексей Аль-Ватар - YouTube 2024, Май
Anonim
Когда вы узнаете о веб-серверах и о том, как они работают, вам может быть любопытно, постоянно ли они прослушивают запросы или ждут, пока они не получат запрос о вступлении в действие. Имея это в виду, у сегодняшней почты SuperUser Q & A есть ответы, чтобы удовлетворить любопытство читателя.
Когда вы узнаете о веб-серверах и о том, как они работают, вам может быть любопытно, постоянно ли они прослушивают запросы или ждут, пока они не получат запрос о вступлении в действие. Имея это в виду, у сегодняшней почты SuperUser Q & A есть ответы, чтобы удовлетворить любопытство читателя.

Сегодняшняя сессия вопросов и ответов приходит к нам благодаря SuperUser - подразделению Stack Exchange, основанной на сообществах сайтам Q & A.

Скриншот любезности xmodulo / Linux Скриншоты (Flickr).

Вопрос

Читатель SuperUser user2202911 хочет знать, как веб-серверы прослушивают новые запросы:

I am trying to understand the ‘deeper level’ details of how web servers work. I want to know if a server, say Apache, for instance, is continuously polling for new requests or if it works by some sort of interrupt system. If it is an interrupt, what is sparking the interrupt? Is it the network card driver?

Как веб-сервер прослушивает новые запросы?

Ответ

Для нас ответчик SuperUser Грег Боузер отвечает:

The short answer is some sort of interrupt system. Essentially, they use blocking I/O, meaning they sleep (block) while waiting for new data.

  1. The server creates a listening socket and then blocks while waiting for new connections. During this time, the kernel puts the process into an interruptible sleep state and runs other processes. This is an important point; having the process poll continuously would waste CPU resources. The kernel is able to use the system resources more efficiently by blocking the process until there is work for it to do.
  2. When new data arrives on the network, the network card issues an interrupt.
  3. Seeing that there is an interrupt from the network card, the kernel, via the network card driver, reads the new data from the network card and stores it in memory. (This must be done quickly and is generally handled inside the interrupt handler.)
  4. The kernel processes the newly arrived data and associates it with a socket. A process that is blocking on that socket will be marked runnable, meaning that it is now eligible to run. It does not necessarily run immediately (the kernel may decide to run other processes still).
  5. At its leisure, the kernel will wake up the blocked web server process. (Since it is now runnable.)
  6. The web server process continues executing as if no time has passed. Its blocking system call returns and it processes any new data. Then go to step 1.

Есть что добавить к объяснению? Отключить звук в комментариях. Хотите узнать больше ответов от других пользователей Windows? Посмотрите здесь полную дискуссионную тему.

Рекомендуемые: