端口 80 上的 HTTP 通信
我想了解 Web 服务器如何处理大量同时发生的 HTTP 请求和响应。请记住我是网络编程新手。
Web 服务器可以同时在端口 80 上发送多个 HTTP 响应吗?或者响应是否必须“序列化”?
Web 服务器是否以序列化方式接收请求?如果是这样,那么插入优先级队列可能需要很快。
I'd like to understand how web servers handle large number of simultaneous HTTP requests and responses. Please keep in mind I'm new to network programming.
Can the web server send multiple HTTP responses on port 80 at the same time? Or do the responses have to be "serialized"?
Does the web server receive requests in a serialized fashion? If so then inserting into a priority queue probably needs to be fast.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
简而言之,大多数 Web 服务器将通过在单独的线程/进程上处理每个请求(通过从线程池中拉出线程或创建一个新线程)来并行处理传入请求。通常,可以同时处理的请求数量是有上限的(例如线程池中的最大线程数)。超过该上限意味着待处理的请求将在队列中等待,直到另一个请求完成。如果服务器需要对请求进行一些异步处理,它可能会将线程返回到线程池,直到准备好完成请求(例如 ASP.NET 中的 IHttpAsyncHandler)。
服务器实际上并不在端口 80 上发回请求。客户端将为该特定连接拥有自己的端口。
The short answer is that most web servers will process incoming requests in parallel by handling each request on a separate thread/process (by pulling thread from a threadpool or creating a new one). Usually, there is a cap on the number of requests that can be processed simultaneously (such as the maximum number of threads in the threadpool). Going beyond that cap means pending requests will wait in queue until another request finishes. If the server needs to do some asynchronous processing of the request, it may return the thread to the threadpool until it is ready to finish the request (such as with IHttpAsyncHandler in ASP.NET).
The server doesn't actually send back requests on port 80. The client will have its own port for that particular connection.
我也是新手,但对网络通信有一点了解。
它不会同时响应多个请求,一次一个,只是在正常运行时非常非常快。
当信息通过网络发送时,无论端口是什么,它都会以数据包的形式发送出去。
在该数据包中,标头定义了您所询问的情况,它尝试使用的端口号和其他所需的信息。
标头之后是数据。数据包中数据的大小因设置而异,即计算机、路由器/交换机以及涉及的任何其他设备。
最后是页脚,其中包含关于这是否是针对该特定请求的最后一个数据包的说明,或者如果不是,则在下一个数据包中查找什么内容。
希望这有助于回答您的问题,并可能给您带来更多问题。
I'm new as well but have a little understanding of network communications.
It doesn't respond to multiple requests at the same time, one at a time, just very, very fast when functioning properly.
When info is sent out over the network regardless of what port it is, it is sent out in a packet.
In that packet is the header which defines, in your case that your asking about, the port number that it is attempting to use and other needed info.
After the header is the data. Size of the data in the packet varies on setting, ie computer, router/switch, and whatever else is involved.
Then finally the footer, which contains directions as to whether it is the last packet coming for that particular reguest or if not, what to look for in the next packet.
Hoped that helped to answer your question and maybe give you a few more questions.