英文:
I can not exceed 28233 websocket connection on my localhost (for stress test) | Go Client (Gorilla)
问题
我正在尝试创建一个连接到相同 WebSocket 服务器(Go 服务器)的客户端池,以测试性能和处理传入请求的能力。
我想知道如何达到例如 100,000 个客户端,因为我发现当我达到 28,233 个 gorilla 客户端(WebSocket 客户端)时,程序无法再创建更多。
我遇到了以下错误:
tcp 127.0.0.1:8000: connect: cannot assign requested address
提前感谢。
英文:
I am trying to make pool of client which connect to the same websocket server (Go Server), in order to test performance and the ability to handle coming request.
I was wondering how I can reach 100K client for example, because I see when I reach 28233 gorilla client (websocket client), program can not make more.
I am getting the following error
tcp 127.0.0.1:8000: connect: cannot assign requested address
Thanks in advance
答案1
得分: 2
你不能从127.0.0.1到127.0.0.1:8000建立100k个并行客户端连接。这些并行客户端连接中的每一个必须具有不同的源端口(否则它将不是一个不同的连接),而可用的源端口只有64k个。实际上,可用的端口更少,因为系统会从临时端口范围中随机选择一个端口(这取决于操作系统和配置)。
如果系统无法选择一个与同一目标IP和端口的另一个连接未使用的唯一源端口,则会出现"cannot assign requested address"的错误。
如果你想支持更多的并行连接,你需要改变连接的其他参数,而不仅仅是源端口。通常,这是通过拥有多个监听不同端口的服务器套接字来实现的。
英文:
You cannot have 100k parallel client connections from 127.0.0.1 to 127.0.0.1:8000. Each of these parallel client connections must have a different source port (otherwise it would not be a different connection) and there are only 64k source ports available. In practice there are even less since the system will choose a port at random from the range of ephemeral ports which is even less (OS and configuration dependent).
If the system fails to pick a unique source port not used by another connection to the same target IP and port, then you get "cannot assign requested address".
If you want to support more parallel connections you need to vary other parameters for the connection than the source port only. Typically this is done by having not a single server socket but multiple sockets which listen on different ports.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论