0
我有一个使用websocket的应用程序。到目前为止,经过严格的尝试,我能够建立65000个连接,但我的资源仍然基本上是免费的。我如何增加连接数量。增加套接字连接数量
的后端代码是用Java编写Vertx Verticle
public class HttpVerticle extends AbstractVerticle {
static int connectionCount = 0;
@Override
public void start() throws Exception {
HttpServer server = vertx.createHttpServer();
server.websocketHandler(serverWebSocket -> {
System.out.println("Connection established: " + (++connectionCount));
serverWebSocket.closeHandler(handler -> {
System.out.println("Connection Closed");
});
});
server.listen(8888);
}
}
主要应用:
public class Main {
public static void main(String[] args) {
System.out.println("server started @ 8080");
Vertx vertx = Vertx.vertx();
vertx.deployVerticle(new HttpVerticle());
}
}
我的系统配置:
Dell latitude
16Gb ram
intel core i7
内存信息,而65000个建立连接:
16313976 total
6009728 used
10283896 free
我可以用这种配置进行的最大连接数是多少,以及增加这个连接数的方法是什么?我发现大内存仍然是免费的,那么我如何增加这种连接呢?
而我的系统设置
的/etc/sysctl.conf
net.core.rmem_max = 33554432
net.core.wmem_max = 33554432
net.ipv4.tcp_rmem = 4096 16384 33554432
net.ipv4.tcp_wmem = 4096 16384 33554432
net.ipv4.tcp_mem = 786432 1048576 26777216
net.ipv4.tcp_max_tw_buckets = 360000
net.core.netdev_max_backlog = 2500
vm.min_free_kbytes = 65536
vm.swappiness = 0
net.ipv4.ip_local_port_range = 1024 65535
在/etc/security/limits.conf
myusername hard nofile 1000000
root soft nofile 1000000
root hard nofile 1000000
非常感谢。但我做了一个方法,我在端口8000上启动了一个nginx服务器。并在8001,8002,8003中创建了3个不同的服务器。这个想法是使用nginx负载均衡器将连接分配给这三台服务器。但是当它尝试这种方法时,nginx负载均衡器本身只需要65k连接。任何想法我怎么能解决这个问题? – CuriousMind
我认为这是同样的问题,你有3台服务器,但是ngnix是一台服务器,所以一旦它达到〜64k连接,它将耗尽临时端口,你仍然需要启动几台ngnix服务器或者将其连接到vert.x服务器直接 –
这些问题如何正常解决?我猜想使用websocket的应用程序不仅限于65k连接? – CuriousMind