RabbitMQ单机安装及性能测试

本文使用CentOS7.9安装RabbitMQ单机环境,并进行性能测试。

1. 安装RabbitMQ

RabbitMQ依赖Erlang,版本配套关系参考官网:https://www.rabbitmq.com/docs/which-erlang

本文安装RabbitMQ3.8.21,Erlang版本要求为23.2~24.2。

# 卸载通过yum源安装的erlang,版本不满足
$ sudo yum remove erlang-*
# 安装erlang
$ sudo yum install -y make gcc gcc-c++ m4 openssl openssl-devel ncurses-devel unixODBC unixODBC-devel java java-devel
$ sudo mkdir /usr/local/erlang
$ wget https://github.com/erlang/otp/releases/download/OTP-23.3.4.20/otp_src_23.3.4.20.tar.gz
$ tar xf otp_src_23.3.4.20.tar.gz
$ cd otp_src_23.3.4.20/
$ sudo ./configure --prefix=/usr/local/erlang
$ sudo make && sudo make install
# 配置环境变量
$ sudo vim /etc/profile
#########   添加如下内容   ###############
PATH=$PATH:/usr/local/erlang/bin
$ sudo source /etc/profile
# 查看erlang版本
$ sudo erl -version
Erlang (SMP,ASYNC_THREADS,HIPE) (BEAM) emulator version 11.2.2.18

# 安装rabbitmq-server
$ wget https://github.com/rabbitmq/rabbitmq-server/releases/download/v3.8.21/rabbitmq-server-generic-unix-3.8.21.tar.xz
$ tar xf rabbitmq-server-generic-unix-3.8.21.tar.xz
$ sudo mv rabbitmq_server-3.8.21/  /usr/local/

# 添加环境变量
$ sudo vim /etc/profile
export RABBITMQ_HOME=/usr/local/rabbitmq_server-3.8.21/sbin
export PATH=$RABBITMQ_HOME:$PATH

# 重载一下环境变量
$ sudo source /etc/profile
 
# 添加web管理插件
$ sudo rabbitmq-plugins enable rabbitmq_management

# 找到rabbitmq.conf.example和advanced.config.example文件,将.example去掉,拷贝到/usr/local/rabbitmq_server-3.8.21/etc/rabbitmq目录下。
# 配置文件实例:https://www.rabbitmq.com/docs/configure#config-file
$ mv rabbitmq.conf.example rabbitmq.conf
$ mv advanced.config.example advanced.config

# 修改rabbitmq.conf文件,取消注释如下两行(91、97行),并将geust从loopback_users中移除。
$ sudo vim rabbitmq.conf
{loopback_users, []},
loopback_users.guest = false

# 后台启动
$ sudo rabbitmq-server -detached

# 停止
$ sudo rabbitmqctl stop

2. PerfTest测试Rabbitmq性能

2.1 PerfTest安装

PerfTest也是从Bintray和GitHub发布的二进制版本库中分发的。如果需要将它作为库,也可以在Maven Central上使用。

参考:

官网:https://perftest.rabbitmq.com/

GitHub:https://github.com/rabbitmq/rabbitmq-perf-test/releases

Maven Central: https://central.sonatype.com/artifact/com.rabbitmq/perf-test

# 下载解压
$ wget https://github.com/rabbitmq/rabbitmq-perf-test/releases/download/v2.20.0/rabbitmq-perf-test-2.20.0-bin.zip
$ unzip rabbitmq-perf-test-2.20.0-bin.zip
$ cd rabbitmq-perf-test-2.20.0/bin/
# 帮助文档
$ ./runjava com.rabbitmq.perf.PerfTest --help
usage: <program>
 -?,--help                           show usage
 -A,--multi-ack-every <arg>          multi ack every
 -a,--autoack                        auto ack
 -ad,--auto-delete <arg>             should the queue be auto-deleted,
                                     default is true
 -B,--body <arg>                     comma-separated list of files to use
                                     in message bodies
 -b,--heartbeat <arg>                heartbeat interval
 -C,--pmessages <arg>                producer message count
 -c,--confirm <arg>                  max unconfirmed publishes
 -ct,--confirm-timeout <arg>         waiting timeout for unconfirmed
                                     publishes before failing (in seconds)
 -D,--cmessages <arg>                consumer message count
 -d,--id <arg>                       test ID
 -e,--exchange <arg>                 exchange name
 -f,--flag <arg>                     message flag
 -H,--uris <arg>                     connection URIs (separated by commas)
 -h,--uri <arg>                      connection URI
 -i,--interval <arg>                 sampling interval in seconds
 -K,--random-routing-key             use random routing key per message
 -k,--routing-key <arg>              routing key
 -L,--consumer-latency <arg>         consumer latency in microseconds
 -l,--legacy-metrics                 display legacy metrics (min/avg/max
                                     latency)
 -M,--framemax <arg>                 frame max
 -m,--ptxsize <arg>                  producer tx size
 -ms,--use-millis                    should latency be collected in
                                     milliseconds, default is false. Set to true if producers are consumers run
                                     on different machines.
 -n,--ctxsize <arg>                  consumer tx size
 -o,--output-file <arg>              output file for timing results
 -p,--predeclared                    allow use of predeclared objects
 -Q,--global-qos <arg>               channel prefetch count
 -q,--qos <arg>                      consumer prefetch count
 -qa,--queue-args <arg>              queue arguments as key/pair values,
                                     separated by commas
 -R,--consumer-rate <arg>            consumer rate limit
 -r,--rate <arg>                     producer rate limit
 -S,--slow-start                     start consumers slowly (1 sec delay
                                     between each)
 -s,--size <arg>                     message size in bytes
 -sb,--skip-binding-queues           don't bind queues to the exchange
 -T,--body-content-type <arg>        body content-type
 -t,--type <arg>                     exchange type
 -u,--queue <arg>                    queue name
 -udsc,--use-default-ssl-context     use JVM default SSL context
 -X,--producer-channel-count <arg>   channels per producer
 -x,--producers <arg>                producer count
 -Y,--consumer-channel-count <arg>   channels per consumer
 -y,--consumers <arg>                consumer count
 -z,--time <arg>                     run duration in seconds (unlimited by
                                     default)

2.2 测试rabbitmq性能

# 使用2个发布者和4个消费者,消费者自动确认。测试10s
$ ./runjava com.rabbitmq.perf.PerfTest -x 2 -y 4 -u "throughput-test-2" -a --id "test 2" -z 10
id: test 2, starting consumer #0
id: test 2, starting consumer #0, channel #0
id: test 2, starting consumer #1
id: test 2, starting consumer #1, channel #0
id: test 2, starting consumer #2
id: test 2, starting consumer #2, channel #0
id: test 2, starting consumer #3
id: test 2, starting consumer #3, channel #0
id: test 2, starting producer #0
id: test 2, starting producer #0, channel #0
id: test 2, starting producer #1
id: test 2, starting producer #1, channel #0
id: test 2, time 1.003 s, sent: 127999 msg/s, received: 15782 msg/s, min/median/75th/95th/99th consumer latency: 5713/307891/402582/528289/582712 µs
id: test 2, time 2.001 s, sent: 131113 msg/s, received: 26712 msg/s, min/median/75th/95th/99th consumer latency: 492458/927258/1076558/1200196/1224838 µs
id: test 2, time 3.002 s, sent: 70270 msg/s, received: 27921 msg/s, min/median/75th/95th/99th consumer latency: 1231947/1636103/1762087/1911254/1961337 µs
id: test 2, time 4.004 s, sent: 65868 msg/s, received: 32514 msg/s, min/median/75th/95th/99th consumer latency: 1871274/2289855/2447511/2573695/2638878 µs
id: test 2, time 5.010 s, sent: 71051 msg/s, received: 47652 msg/s, min/median/75th/95th/99th consumer latency: 2558754/2876891/2982484/3254060/3317619 µs
id: test 2, time 6.002 s, sent: 59422 msg/s, received: 61646 msg/s, min/median/75th/95th/99th consumer latency: 2759697/3160876/3333301/3550598/3577079 µs
id: test 2, time 7.002 s, sent: 51860 msg/s, received: 62923 msg/s, min/median/75th/95th/99th consumer latency: 2821628/3221174/3346806/3479463/3500692 µs
id: test 2, time 8.001 s, sent: 69568 msg/s, received: 64028 msg/s, min/median/75th/95th/99th consumer latency: 2815461/3220554/3359531/3509414/3540637 µs
id: test 2, time 9.001 s, sent: 60874 msg/s, received: 56448 msg/s, min/median/75th/95th/99th consumer latency: 2810135/3187379/3422998/3547960/3569557 µs
id: test 2, time 10.006 s, sent: 52246 msg/s, received: 58175 msg/s, min/median/75th/95th/99th consumer latency: 2871297/3260717/3463882/3582327/3608431 µs
id: test 2, time 11.001 s, sent: 2.0 msg/s, received: 60551 msg/s, min/median/75th/95th/99th consumer latency: 2933013/3275629/3448953/3585931/3630662 µs
id: test 2, time 12.001 s, sent: 0 msg/s, received: 70372 msg/s, min/median/75th/95th/99th consumer latency: 2767204/3282635/3474078/3678657/3719987 µs
id: test 2, time 13.001 s, sent: 0 msg/s, received: 65454 msg/s, min/median/75th/95th/99th consumer latency: 2552693/3090484/3276141/3544581/3585066 µs
test stopped (Reached time limit)
id: test 2, sending rate avg: 58506 msg/s
id: test 2, receiving rate avg: 49985 msg/s
id: test 2, consumer latency min/median/75th/95th/99th 14918/3156722/3342902/3541320/3615540 µs
$ bin/runjava com.rabbitmq.perf.PerfTest -x 2 -y 4 -u "throughput-test-2" -a --id "test 2"

# 将消费者切换到手动确认:
$ ./runjava com.rabbitmq.perf.PerfTest -x 1 -y 2 -u "throughput-test-3" --id "test 3"

# 修改将消息大小从默认(12字节)更改为4 kB:
$ ./runjava com.rabbitmq.perf.PerfTest -x 1 -y 2 -u "throughput-test-4" --id "test 4" -s 4000

# 使用持久队列和持久消息:
$ ./runjava com.rabbitmq.perf.PerfTest -x 1 -y 2 -u "throughput-test-5" --id "test-5" -f persistent

# 队列数400,生产者200,消费者200,消息大小12bytes(默认),消息自动确认,持久化,持续生产消费5分钟。建议测试客户端和被测试机器分开部署。
$ ./runjava com.rabbitmq.perf.PerfTest -x 200 -y 200 -u "max-throughput-test" -s 12 -a --id "test 2" -z 300 -f persistent
id: test 2, sending rate avg: 116797 msg/s
id: test 2, receiving rate avg: 29674 msg/s
id: test 2, consumer latency min/median/75th/95th/99th 7504371/104831283/114120030/121894266/124635729 µs

点赞(0) 打赏

评论列表 共有 0 条评论

暂无评论

微信公众账号

微信扫一扫加关注

发表
评论
返回
顶部