当前位置: 首页 > 工具软件 > not-perf > 使用案例 >

RabbitMQ压力测试之perf-test

夏侯渊
2023-12-01

一、Perf-Test介绍

perf-test是基于java客户端的可模拟基本工作负载的工具,有额外的工具可以输出成HTML图形,它能够对RabbitMQ单节点和集群进行性能测试。

二、Perf-Test安装

1.下载地址:点此进入下载地址

  • Linux平台-二进制包

rabbitmq-perf-test-2.15.0-bin.tar.gz
  • Windows平台-zip压缩包

perf-test_linux_x86_64

2.解压

tar -xzvf rabbitmq-perf-test-2.15.0-bin.tar.gz -C /opt
  • 目录结构

[root@node01 rabbitmq-perf-test-2.15.0]# ll
total 68
drwxr-xr-x. 2 root root   233 Jul 13 15:35 bin
drwxr-xr-x. 4 root root    81 Jul 13 09:46 html
drwxr-xr-x. 2 root root   157 Jul 13 09:46 images
drwxr-xr-x. 2 root root  4096 Jul 13 09:46 lib
-rw-r--r--. 1 root root   648 May 17 15:40 LICENSE
-rw-r--r--. 1 root root 11360 May 17 15:40 LICENSE-APACHE2
-rw-r--r--. 1 root root 17987 May 17 15:40 LICENSE-GPL2
-rw-r--r--. 1 root root 16596 May 17 15:40 LICENSE-MPL-RabbitMQ
-rw-r--r--. 1 root root  4932 May 17 15:40 README.md
[root@node01 rabbitmq-perf-test-2.15.0]# 

3.Java环境

因为RabbitMQ性能压测的包是类名似像com.rabbitmq.perf.PerfTest,所以他是基于java客户端的模拟性能测试工具。

三、测试

[root@node01 bin]# ./runjava  com.rabbitmq.perf.PerfTest --help
usage: <program>
 -?,--help                                   show usage
 -a,--autoack                                auto ack
 -A,--multi-ack-every <arg>                  multi ack every
 -ad,--auto-delete <arg>                     should the queue be
                                             auto-deleted, default is true
 -b,--heartbeat <arg>                        heartbeat interval
 -B,--body <arg>                             comma-separated list of files
                                             to use in message bodies
 -bc,--body-count <arg>                      number of pre-generated
                                             message bodies. Use with
                                             --json-body. Default is 100.
 -bfc,--body-field-count <arg>               number of pre-generated
                                             fields and values for body.
                                             Use with --json-body. Default
                                             is 1000.
 -c,--confirm <arg>                          max unconfirmed publishes
 -C,--pmessages <arg>                        producer message count
 -ca,--consumer-args <arg>                   consumer arguments as
                                             key/values pairs, separated
                                             by commas, e.g. x-priority=10
 -cri,--connection-recovery-interval <arg>   connection recovery interval
                                             in seconds. Default is 5
                                             seconds. Interval syntax,
                                             e.g. 30-60, is supported to
                                             specify an random interval
                                             between 2 values between each
                                             attempt.
 -ct,--confirm-timeout <arg>                 waiting timeout for
                                             unconfirmed publishes before
                                             failing (in seconds)
 -ctp,--consumers-thread-pools <arg>         number of thread pools to use
                                             for all consumers, default is
                                             to use a thread pool for each
                                             consumer
 -d,--id <arg>                               test ID
 -D,--cmessages <arg>                        consumer message count
 -dcr,--disable-connection-recovery          disable automatic connection
                                             recovery
 -e,--exchange <arg>                         exchange name
 -E,--exclusive                              use server-named exclusive
                                             queues. Such queues can only
                                             be used by their declaring
                                             connection!
 -env,--environment-variables                show usage with environment
                                             variables
 -f,--flag <arg>                             message flag(s), supported
                                             values: persistent and
                                             mandatory. Use the option
                                             several times to specify
                                             several values.
 -h,--uri <arg>                              connection URI
 -H,--uris <arg>                             connection URIs (separated by
                                             commas)
 -hst,--heartbeat-sender-threads <arg>       number of threads for
                                             producers and consumers
                                             heartbeat senders
 -i,--interval <arg>                         sampling interval in seconds
 -jb,--json-body                             generate a random JSON
                                             document for message body.
                                             Use with --size.
 -k,--routing-key <arg>                      routing key
 -K,--random-routing-key                     use random routing key per
                                             message
 -l,--legacy-metrics                         display legacy metrics
                                             (min/avg/max latency)
 -L,--consumer-latency <arg>                 consumer latency in
                                             microseconds
 -m,--ptxsize <arg>                          producer tx size
 -M,--framemax <arg>                         frame max
 -mh,--metrics-help                          show metrics usage
 -mp,--message-properties <arg>              message properties as
                                             key/value pairs, separated by
                                             commas, e.g. priority=5
 -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
 -na,--nack                                  nack and requeue messages
 -niot,--nio-threads <arg>                   number of NIO threads to use
 -niotp,--nio-thread-pool <arg>              size of NIO thread pool,
                                             should be slightly higher
                                             than number of NIO threads
 -o,--output-file <arg>                      output file for timing
                                             results
 -p,--predeclared                            allow use of predeclared
                                             objects
 -P,--publishing-interval <arg>              publishing interval in
                                             seconds (opposite of producer
                                             rate limit)
 -pi,--polling-interval <arg>                time to wait before polling
                                             with basic.get, in
                                             millisecond, default is 0.
 -po,--polling                               use basic.get to consume
                                             messages. Do not use this in
                                             real applications.
 -prsd,--producer-random-start-delay <arg>   max random delay in seconds
                                             to start producers
 -pst,--producer-scheduler-threads <arg>     number of threads to use when
                                             using --publishing-interval
 -q,--qos <arg>                              consumer prefetch count
 -Q,--global-qos <arg>                       channel prefetch count
 -qa,--queue-args <arg>                      queue arguments as key/value
                                             pairs, separated by commas,
                                             e.g. x-max-length=10
 -qf,--queue-file <arg>                      file to look up queue names
                                             from
 -qp,--queue-pattern <arg>                   queue name pattern for
                                             creating queues in sequence
 -qpf,--queue-pattern-from <arg>             queue name pattern range
                                             start (inclusive)
 -qpt,--queue-pattern-to <arg>               queue name pattern range end
                                             (inclusive)
 -qq,--quorum-queue                          create quorum queue(s)
 -r,--rate <arg>                             producer rate limit
 -R,--consumer-rate <arg>                    consumer rate limit
 -rkcs,--routing-key-cache-size <arg>        size of the random routing
                                             keys cache. See
                                             --random-routing-key.
 -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
 -se,--sasl-external                         use SASL EXTERNAL
                                             authentication, default is
                                             false. Set to true if using
                                             client certificate
                                             authentication with the
                                             rabbitmq_auth_mechanism_ssl
                                             plugin.
 -sni,--server-name-indication <arg>         server names for Server Name
                                             Indication TLS parameter,
                                             separated by commas
 -sst,--servers-startup-timeout <arg>        start timeout in seconds (in
                                             case the servers(s) is (are)
                                             not available when the run
                                             starts). Default is to fail
                                             immediately if the servers(s)
                                             is (are) not available.
 -st,--shutdown-timeout <arg>                shutdown timeout, default is
                                             5 seconds
 -sul,--servers-up-limit <arg>               number of available servers
                                             needed before starting the
                                             run. Used in conjunction with
                                             --servers-start-timeout.
                                             Default is deduced from --uri
                                             or --uris.
 -t,--type <arg>                             exchange type
 -T,--body-content-type <arg>                body content-type
 -u,--queue <arg>                            queue name
 -udsc,--use-default-ssl-context             use JVM default SSL context
 -v,--version                                print version information
 -vl,--variable-latency <arg>                variable consumer processing
                                             latency with
                                             [MICROSECONDS]:[DURATION]
                                             syntax, where [MICROSECONDS]
                                             integer >= 0 and [DURATION]
                                             integer > 0. Use the option
                                             several times to specify
                                             several values.
 -vr,--variable-rate <arg>                   variable publishing rate with
                                             [RATE]:[DURATION] syntax,
                                             where [RATE] integer >= 0 and
                                             [DURATION] integer > 0. Use
                                             the option several times to
                                             specify several values.
 -vs,--variable-size <arg>                   variable message size with
                                             [SIZE]:[DURATION] syntax,
                                             where [SIZE] integer > 0 and
                                             [DURATION] integer > 0. Use
                                             the option several times to
                                             specify several values.
 -x,--producers <arg>                        producer count
 -X,--producer-channel-count <arg>           channels per producer
 -y,--consumers <arg>                        consumer count
 -Y,--consumer-channel-count <arg>           channels per consumer
 -z,--time <arg>                             run duration in seconds
                                             (unlimited by default)
[root@node01 bin]# 

选项说明:



    -x,-- (生产者数量)
    -y,-- (消费者数量)
    -u,-- (队列名称)
    -a,--    autoack auto ack,客户端在处理完messages之后会给服务端返回一个ack确认信息,服务端在收到该ack信息之后才会把messages删除;
    -d,-- (本次测试的编号,身份标识)
    -s,-- (消息大小,单位是字节)
    -f,-- (消息标志,多个可以用逗号隔开,支持的值:persistent 和 mandatory)
    消费者可以一次确认多条消息,例如,下面是100条消息确认一次

    runjava com.rabbitmq.perf.PerfTest -x 1 -y 2 -u "test-6" --id "test-6" -f persistent --multi-ack-every 100

    -A,-- (每多少条消息返回一次ack信息给服务器端)
    -q,-- (消费者预读取的数量)
    -c,-- (未确认消息发布的最大值)
    -C,-- (生产者要生成的消息的数量,译者注:在此次性能测试中,生产者一旦生成了指定数量的消息,就会停止。)
    -r,-- (生产者速度限制)
    -R,--(消费者速度限制)
    -z,-- (运行时间,单位是秒(默认没有限制))。
    -p,-- (允许使用预定义的对象)
    -D,-- (消费者要消费的消息数量,也就是指定这次测试中消费者一共要消费多少条消息,一旦消费者消费了这么多条消息,消费者就会被停止)
    -qa,--queue-args <arg> queue  队列参数键值对,使用逗号隔开,例如x-max-length=10
    -mp,--  消息属性以逗号隔开的键值对方式,比如priority=5.
    -B,-- 使用逗号分隔的文件列表,用在消息的内容中(这里是多个由逗号分隔开的文件名,把文件中的内容作为消息体写入到指定queue中)
    -T,-- 消息体内容类型
    -qp,--  按顺序依次创建的队列名称模式
    -F,--  队列模式的开始(包含)
    -T,-- 队列模式的结束(包含)
    -hst,--heartbeat-sender-threads <arg>  生产者和消费者的心跳发送者的线程数量
    -ms,-- 是否收集延迟时间,单位毫秒。默认是关闭的。如果生产者和消费者在不同的主机上运行,那么就将其设置成为true。
    -p,-- 允许使用预先声明的对象

四、性能测试

根据help得到的参数和实际环境进行测试。官网给出了许多测试的例子。在这里贴出地址,可以参考:

https://rabbitmq.github.io/rabbitmq-perf-test/stable/htmlsingle/#basic-usage
 类似资料: