前言:官方说的单台连接达到百万,虽然我信,但我还是要自己玩一下。
我用emqtt_benchmark进行压测,要用emqtt_benchmark需要有erlangR17版本以上的环境
## 安装erlang虚拟机
yum -y install ncurses-devel openssl-devel unixODBC-devel gcc-c++
cd /opt
wget http://erlang.org/download/otp_src_19.0.tar.gz
tar -zxvf otp_src_19.0.tar.gz
cd otp_src_19.0
./configure --prefix=/usr/local/erlang --with-ssl -enable-threads -enable-smmp-support -enable-kernel-poll --enable-hipe --without-javac
make && make install
配置环境变量
vim /etc/profile
# erlang
export ERLPATH=/usr/local/erlang
export PATH=$ERLPATH/bin:$PATH
source /etc/profile
验证是否安装成功
[root@localhost ~]# erl
Erlang/OTP 19 [erts-8.0] [source] [64-bit] [async-threads:10] [kernel-poll:false]
Eshell V8.0 (abort with ^G)
1>
出现以上代表erlang环境弄好了
安装emqtt_benchmark
yum -y install git
cd /opt
git clone https://github.com/emqtt/emqtt_benchmark.git
cd emqtt_benchmark
make
上面make时候可能会提示没有rebar
cd ..
git clone https://github.com/erlang/rebar3.git
cd rebar3
./bootstrap
./rebar3 local install
cp rebar3 -rf /usr/local/bin
#修改profile文件
vi /etc/profile
export PATH=$PATH:/usr/local/bin/rebar3
source /etc/profile
#最后编译
rebar3 compile
然后再退回emqtt_benchmark目录执行: make 命令
上面都做完后开始进行压测,我有三台机器,每台给30000连接数以便观测
## 调整系统参数并且开始压测
sysctl -w net.ipv4.ip_local_port_range="500 65535"
echo 1000000 > /proc/sys/fs/nr_open
ulimit -n 1000000
./emqtt_bench_sub -h 192.168.1.135 -c 30000 -p 1883 -i 1 -t bench /%i -q 1
效果图,三台机器作为压力机,每台提供30000连接数到135上
再测测136
再测测128
由上可以看出,成功率还是比较高的,我这里测试的只是连接压力而已。并且由于压力机有限,只能创建这么多的连接数,如果有更多的压力机,应该还能承受更大的连接数。
官网也说了还有很多其他方面的测试,待我研究了再来分享。