简体   繁体   English

如何在端口上发出超过65k的请求

[英]How to make more than 65k request on a port

I have a simple node js web socket server as follows: 我有一个简单的节点js Web套接字服务器,如下所示:

var ws = require("nodejs-websocket")
var connectionCount = 0;
console.info("Node websocket started @ 8001");

var server = ws.createServer(function (conn) {;
    console.log("New connection", ++connectionCount);
    conn.on("close", function (code, reason) {
        console.log("Connection closed")
    });
}).listen(8001)

This server takes 65k connections (as one port takes at the max 65k connections). 该服务器需要65k个连接(因为一个端口最多可以容纳65k个连接)。 How can I scale the server so that it can take more than 100k connections? 如何扩展服务器,使其可以容纳超过10万个连接?

I recently opened three such servers with different ports and tried to do load balancing using nginx but to no avail, as the nginx server also could take 65k connections only. 我最近打开了三台具有不同端口的服务器,并尝试使用nginx进行负载平衡,但无济于事,因为nginx服务器也只能进行65k连接。 The nginx config is here Nginx配置在这里

upstream localhost {
    server localhost:8001;
    server localhost:8002;
    server localhost:8003;
}


server {
    proxy_read_timeout 3600s;
    listen 8000;
    location / {
            proxy_pass http://localhost;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "upgrade";
    }
}

The port 8000 could take only 65k connections. 端口8000只能连接65k。

How are these kind of situations handled in the real time. 这些情况如何实时处理。 I am an amateur here and need some good pointer to scale the server. 我在这里很业余,需要一些很好的指针来扩展服务器。 The solution need not have to be using nginx. 解决方案不必使用nginx。 It can be anything. 可以是任何东西。 I just want to know, how to handle these kind of problems. 我只想知道如何处理这类问题。 Detail answers are appreciated. 详细的答案表示赞赏。 Thanks. 谢谢。

The limitation of 65535 ports only holds for outgoing connections, not for incoming connections. 65535端口的限制仅适用于传出连接,不适用于传入连接。

The operating system uniquely identifies a connection/socket by these four properties: 操作系统通过以下四个属性唯一地标识连接/套接字:

  • source IP address 源IP地址
  • source TCP port destination 源TCP端口目标
  • server IP address 服务器的IP地址
  • server TCP port 服务器TCP端口

So for a single IP address you Node.js or Nginx server can maintain at most 65535 connections. 因此,对于一个IP地址 ,Node.js或Nginx服务器最多可以维护65535个连接。 Across different client IPs, the only limitations are the CPU and RAM resources of your server. 在不同的客户端IP上,唯一的限制是服务器的CPU和RAM资源。

Maybe you tested this behavior from a single client? 也许您从单个客户端测试了此行为? In that case, you ran into the limitation of source TCP ports . 在这种情况下,您会遇到源TCP端口的限制。 Try testing from different clients and your server should work just fine with more than 65535 connections. 尝试从不同的客户端进行测试,并且服务器在超过65535个连接的情况下应该可以正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在多个端口上侦听并将端口映射到另一个域 - listen on more than one port and map port to another domain 如何在 nginx 中接受域后端口的请求 - How to accept request with port after domain in nginx 如何配置nginx X-Forwarded-Port为原始请求端口 - How to configure nginx X-Forwarded-Port to be the originally request port SCGI 一次可以处理多个请求吗? - Can SCGI handle more than one request at a time? 如何在 Nginx 上监听不同的端口并代理请求? - How to listen to different port on Nginx and proxy the request? 如何使用Unix套接字而不是TCP / IP堆栈向PHP-FPM发出HTTP请求? - How to make HTTP request to PHP-FPM using Unix socket rather than TCP/IP stack? 如何进行安全请求? - How to make a secure request? docker是否可以在同一台计算机的端口80上运行多个应用程序? - Is it possible with docker to run more than one app on port 80 on the same computer? 如何将传入请求转发到主机上的 80 端口到 x 端口,其中 x 是传入请求参数 - How to forward incoming request to 80 port on host to x port where x is the incoming request parameter 如果没有在 API 请求中指定端口号,服务器如何确定此请求是针对端口 80 或 443 - Without specifying a port number inside of a API request how server decided that this request is for port 80 or 443
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM