I am developing a client program which uses Mqtt3AsyncClient and trying to connect more than 10,000 client connections. Upon reaching 9,200+ connections, the client slows down and not able to complete 10k connections.
Im running on a server having 32 CPUs and 32 GB RAM, Red Hat Enterprise Linux Server release 7.9, with Java™ SE Runtime Environment (build 1.8.0_221).
I have already overriden the RHEL default system limits.
ulimit -a
core file size (blocks, -c) 0
data seg size (kbytes, -d) unlimited
scheduling priority (-e) 0
file size (blocks, -f) unlimited
pending signals (-i) 127883
max locked memory (kbytes, -l) 64
max memory size (kbytes, -m) unlimited
open files (-n) 1048576
pipe size (512 bytes, -p) 8
POSIX message queues (bytes, -q) 819200
real-time priority (-r) 0
stack size (kbytes, -s) 8192
cpu time (seconds, -t) unlimited
max user processes (-u) 127883
virtual memory (kbytes, -v) unlimited
file locks (-x) unlimited
I have fined tuned OS TCP settings as stated on this link
Linux Test/Measurement hosts
net.core.rmem_max = 536870912
net.core.wmem_max = 536870912
net.ipv4.tcp_rmem = 4096 87380 268435456
net.ipv4.tcp_wmem = 4096 65536 268435456
net.ipv4.tcp_congestion_control=htcp
net.core.default_qdisc = fq
net.core.somaxconn=1024
net.ipv4.tcp_timestamps=0
net.ipv4.tcp_low_latency=1
net.core.netdev_max_backlog=250000
net.ipv4.tcp_max_syn_backlog=250000
I’m using latest HiveMQ MQTT version.
<dependency>
<groupId>com.hivemq</groupId>
<artifactId>hivemq-mqtt-client</artifactId>
<version>1.2.2</version>
</dependency>
<dependency>
<groupId>com.hivemq</groupId>
<artifactId>hivemq-mqtt-client-epoll</artifactId>
<version>1.2.2</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>com.hivemq</groupId>
<artifactId>hivemq-mqtt-client-reactor</artifactId>
<version>1.2.2</version>
</dependency>
As fine tuning OS and TCP configuration did not help, I started reading Netty framework as its being used under the hood tried to play on some NETTY JVM args as shown below.
NETTY_ARGS="-Dio.netty.eventLoopThreads=128 -Dio.netty.threadLocalMap.stringBuilder.initialSize=1024 -Dio.netty.threadLocalMap.stringBuilder.maxSize=4069 -Dio.netty.allocator.tinyCacheSize=5120 -Dio.netty.allocator.smallCacheSize=2560 -Dio.netty.allocator.normalCacheSize=640 -Dio.netty.allocator.maxCachedBufferCapacity=536870912 -Dio.netty.allocator.maxCachedByteBuffersPerChunk=10230 -Dio.netty.allocator.numHeapArenas=64 -Dio.netty.allocator.numDirectArenas=64"
In the end, im still stuck at 9,000+ client MQTT connections, and not able to reach more than that. I’m having difficulty on how to proceed now, wondering which config knob i have missed.
Any advice is greatly appreciated!.