web服务器如何侦听新请求?

在了解web服务器及其工作方式时,您可能会好奇,他们是在不断地侦听请求,还是等到收到请求后才采取行动。有鉴于此,今天的超级用户问答帖子有了满足读者好奇心的答案。...

web服务器如何侦听新请求?

在了解web服务器及其工作方式时,您可能会好奇,他们是在不断地侦听请求,还是等到收到请求后才采取行动。有鉴于此,今天的超级用户问答帖子有了满足读者好奇心的答案。

今天的问答环节是由SuperUser提供的,SuperUser是Stack Exchange的一个分支,是一个由社区驱动的问答网站分组。

截图由xmodulo/Linux截图(Flickr)提供。

问题

超级用户读者user2202911想知道web服务器如何侦听新请求:

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?

web服务器如何侦听新请求?

答案

超级用户贡献者Greg Bowser为我们提供了答案:

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 connecti***. 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.

有什么要补充的解释吗?在评论中发出声音。想从其他精通技术的Stack Exchange用户那里了解更多答案吗?在这里查看完整的讨论主题。

  • 发表于 2021-04-11 04:35
  • 阅读 ( 179 )
  • 分类:互联网

你可能感兴趣的文章

不,linux不需要防病毒或防火墙

... 你唯一需要防火墙的时候,就是在你的系统上运行某种服务器应用程序的时候。这可能是web服务器、电子邮件服务器、游戏服务器等。在这种情况下,防火墙将限制某些端口的传入连接,确保它们只能与适当的服务器应用程序...

  • 发布于 2021-03-12 20:15
  • 阅读 ( 190 )

什么是cgi脚本,它们如何改进网站?

CGI代表公共网关接口。它是web服务器执行程序并为web浏览器生成输出的标准协议。该程序被称为CGI程序(或CGI脚本)。当用户的web浏览器请求特定的URL时,它代表web服务器执行以产生输出。 ...

  • 发布于 2021-03-13 08:17
  • 阅读 ( 249 )

为什么wi-fi direct没有你想象的那么安全

... 然后,连接的设备可以完全访问远程控制功能以及web服务器,并可以对媒体服务器和所有连接的设备进行读/写访问。所有这些权限都是在没有身份验证或通知的情况下授予的。或许不出意外,WD电视直播在2016年停播。 ...

  • 发布于 2021-03-25 20:57
  • 阅读 ( 433 )

什么是csrf攻击?如何防止它们?

...洞的最古老方法之一。它针对通常需要登录等身份验证的服务器端web交换机。在CSRF攻击过程中,攻击者的目标是强迫其受害者代表他们发出未经授权的恶意web请求。 ...

  • 发布于 2021-03-29 05:49
  • 阅读 ( 330 )

如何使用listen-alike在spotify上查找音乐匹配项

... 如何使用spotify的listen-like ...

  • 发布于 2021-03-29 15:16
  • 阅读 ( 232 )

如何在ubuntu上设置远程桌面

...我们会教你怎么做。 ubuntu内置的“屏幕共享”是一个vnc服务器 当您与远程ubuntulinux计算机建立SSH连接时,您会得到一个终端窗口接口。这对于许多任务来说都是非常好的,比如系统管理,它的优点是轻量级连接。没有图形可以...

  • 发布于 2021-04-03 07:59
  • 阅读 ( 216 )

什么是反向ssh隧道?(以及如何使用)

...用隧道。 所以我们得到了“反向SSH隧道”这个名字 它是如何工作的? 反向SSH隧道依赖于远程计算机使用已建立的连接来侦听来自本地计算机的新连接请求。 远程计算机监听本地计算机上的网络端口。如果它检测到对该端口的SS...

  • 发布于 2021-04-03 08:32
  • 阅读 ( 212 )

htg解释:什么是端口扫描?

...您连接到一个安全的网站时,您的web浏览器正在与监听该服务器端口443的web服务器进行通信。 服务并不总是必须在这些特定端口上运行。例如,如果愿意,可以在端口32342上运行HTTPS web服务器,或者在端口65001上运行安全Shell服...

  • 发布于 2021-04-04 08:28
  • 阅读 ( 140 )

如何转发路由器上的端口

... 我们讨论过的很多项目都将您的计算机用作其他设备的服务器。当你在你的人际网络中时,大多数事情都能正常工作。但有些应用程序,如果你想在网络之外访问它们,会让事情变得更加复杂。让我们先看看为什么会这样。 ...

  • 发布于 2021-04-08 20:23
  • 阅读 ( 159 )

Windows10的“可选功能”是做什么的,以及如何打开或关闭它们

...开或关闭这些功能。这些特性中有许多是针对业务网络和服务器的,而有些对每个人都有用。下面是对每个功能的说明,以及如何打开或关闭它们。 无论您是否启用了Windows10功能,所有这些功能都会占用硬盘空间。但你不应该...

  • 发布于 2021-04-09 18:10
  • 阅读 ( 204 )
aypt3486
aypt3486

0 篇文章

相关推荐