最大 MQTT 连接数 [英] Max MQTT connections

查看:291
本文介绍了最大 MQTT 连接数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要创建一个可以处理 5+ 百万个连接、5+ 百万个主题(每个客户端一个)、处理 30 万条消息/秒的服务器群.

I have a need to create a server farm that can handle 5+ million connections, 5+ million topics (one per client), process 300k messages/sec.

我试图了解各种消息代理的功能,因此我目前使用两个 RHEL EC2 实例 (r3.4xlarge) 来制作大量可用资源.所以你不需要查找它,它有 16vCPU,122GB RAM.我远未达到使用限制.

I tried to see what various message brokers were capable so I am currently using two RHEL EC2 instances (r3.4xlarge) to make lots of available resources. So you do not need to look it up, it has 16vCPU, 122GB RAM. I am nowhere near that limit in usage.

我无法通过 600k 连接限制.由于客户端和服务器上似乎没有任何 O/S 限制(大量 RAM/CPU/等),是什么限制了我?

我已将/etc/security/limits.conf 编辑如下:

I have edited /etc/security/limits.conf as follows:

* soft  nofile  20000000
* hard  nofile  20000000

* soft  nproc  20000000
* hard  nproc  20000000

root  soft  nofile 20000000
root  hard  nofile 20000000

我已将/etc/sysctl.conf 编辑如下:

I have edited /etc/sysctl.conf as follows:

net.ipv4.ip_local_port_range = 1024 65535  
net.ipv4.tcp_tw_reuse = 1 
net.ipv4.tcp_mem = 5242880  5242880 5242880 
net.ipv4.tcp_tw_recycle = 1 
fs.file-max = 20000000 
fs.nr_open = 20000000 
net.ipv4.tcp_syncookies = 0

net.ipv4.tcp_max_syn_backlog = 10000 
net.ipv4.tcp_synack_retries = 3 
net.core.somaxconn=65536 
net.core.netdev_max_backlog=100000 
net.core.optmem_max = 20480000

对于阿波罗:导出 APOLLO_ULIMIT=20000000

For Apollo: export APOLLO_ULIMIT=20000000

对于 ActiveMQ:

For ActiveMQ:

ACTIVEMQ_OPTS="$ACTIVEMQ_OPTS -Dorg.apache.activemq.UseDedicatedTaskRunner=false"
ACTIVEMQ_OPTS_MEMORY="-Xms50G -Xmx115G"

我在客户端为 eth0 创建了 20 个额外的私有地址,然后分配给它们:ip 地址添加 11.22.33.44/24 dev eth0

I created 20 additional private addresses for eth0 on the client, then assigned them: ip addr add 11.22.33.44/24 dev eth0

我完全了解 65k 端口限制,这就是我执行上述操作的原因.

I am FULLY aware of the 65k port limits which is why I did the above.

  • 对于 ActiveMQ,我得到了:574309
  • 对于阿波罗,我得到了:592891
  • 对于 Rabbit,我达到了 90k,但日志记录很糟糕,虽然我知道它可能,但我不知道该怎么做才能提高.
  • 对于 Hive,我的试用限制为 1000.等待许可
  • IBM 想用我房子的成本来换取使用它们 - 不!

推荐答案

ANSWER:在执行此操作时,我意识到我在/etc/sysctl.conf 文件中的客户端设置中有一个拼写错误:net.ipv4.ip_local_port_range

ANSWER: While doing this I realized that I had a misspelling in my client setting within /etc/sysctl.conf file for: net.ipv4.ip_local_port_range

我现在可以在 188 秒内将 956,591 个 MQTT 客户端连接到我的 Apollo 服务器.

I am now able to connect 956,591 MQTT clients to my Apollo server in 188sec.

更多信息:为了区分这是 O/S 连接限制还是 Broker,我决定编写一个简单的客户端/服务器.

More info: Trying to isolate if this is an O/S connection limitation or a Broker, I decided to write a simple Client/Server.

服务器:

    Socket client = null;
    server = new ServerSocket(1884);
    while (true) {
        client = server.accept();
        clients.add(client);
    }

客户:

    while (true) {
        InetAddress clientIPToBindTo = getNextClientVIP();
        Socket client = new Socket(hostname, 1884, clientIPToBindTo, 0);
        clients.add(client);
    }

如果有 21 个 IP,我希望 65535-1024*21 = 1354731 是边界.实际上我能够达到 1231734

With 21 IPs, I would expect 65535-1024*21 = 1354731 to be the boundary. In reality I am able to achieve 1231734

[root@ip ec2-user]# cat /proc/net/sockstat
sockets: used 1231734
TCP: inuse 5 orphan 0 tw 0 alloc 1231307 mem 2
UDP: inuse 4 mem 1
UDPLITE: inuse 0
RAW: inuse 0
FRAG: inuse 0 memory 0

socket/kernel/io 的东西就解决了.

So the socket/kernel/io stuff is worked out.

我仍然无法使用任何代理来实现这一点.

I am STILL unable to achieve this using any broker.

在我的客户端/服务器测试之后,这是内核设置.

Again just after my client/server test this is the kernel settings.

客户:

[root@ip ec2-user]# sysctl -p
net.ipv4.ip_local_port_range = 1024     65535
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_mem = 5242880      5242880 15242880
net.ipv4.tcp_tw_recycle = 1
fs.file-max = 20000000
fs.nr_open = 20000000

[root@ip ec2-user]# cat /etc/security/limits.conf
* soft  nofile  2000000
* hard  nofile  2000000    
root  soft  nofile 2000000
root  hard  nofile 2000000

服务器:

[root@ ec2-user]# sysctl -p
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_mem = 5242880      5242880 5242880
net.ipv4.tcp_tw_recycle = 1
fs.file-max = 20000000
fs.nr_open = 20000000
net.ipv4.tcp_syncookies = 0
net.ipv4.tcp_max_syn_backlog = 1000000
net.ipv4.tcp_synack_retries = 3
net.core.somaxconn = 65535
net.core.netdev_max_backlog = 1000000
net.core.optmem_max = 20480000

这篇关于最大 MQTT 连接数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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