在网络编程中,sockets/connections 的数量是有限制的,webserver 是如何超过这个限制的? [英] In network programming, there is a limit to number of sockets/connections, how webserver exceeds this limit?

查看:31
本文介绍了在网络编程中,sockets/connections 的数量是有限制的,webserver 是如何超过这个限制的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经开始探索使用 Socket 在 Linux 中的网络编程.我想知道 Yahoo、google 等网络服务器如何能够建立数百万/数十亿的连接.我相信核心只是套接字编程来访问远程服务器.如果是这种情况,那么数十亿人和数百万人如何能够连接到服务器.这意味着数十亿/数百万的套接字连接.这不可能吧?规范说最多只能有 5 个套接字连接.背后究竟有什么玄机?

I have started exploring on the network programming in Linux using Socket. I am wondering how come webservers like Yahoo, google, and etc are able to establish million/billions of connections. I believe the core is only socket programming to access the remote server. If that is the case then how come billion and millions of people are able to connect to the server. It means billions/millions of socket connection. This is not possible right? The spec says maximum 5 socket connections only. What is the mystery behind it?

您能否也谈谈这个 - API?

Can you also speak in terms of this - API?

listen(sock,5);

推荐答案

它并没有只说最多 5 个连接".您引用的 listen() 参数是积压,而不是连接总数.它指的是在应用程序通过 accept() 获取之前,TCP 将接受并保留在积压"队列() 上的传入连接数.

It doesn't 'say maximum 5 connections only'. The argument to listen() that you refer to is the backlog, not the total number of connections. It refers to the number of incoming connections that TCP will accept and hold on the 'backlog' queue() prior to the application getting hold of them via accept().

这篇关于在网络编程中,sockets/connections 的数量是有限制的,webserver 是如何超过这个限制的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆