PerfTest对RabbitMQ进行压力测试

本文详细介绍了RabbitMQ官方提供的性能测试工具PerfTest的使用方法,包括下载地址、参数配置及常见应用场景,帮助读者掌握如何评估RabbitMQ在不同场景下的表现。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

下载地址:

官网地址:http://www.rabbitmq.com/java-tools.html

下载后进行解压即可:

使用方式

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
 -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)
 -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.
 -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
 -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)

使用PerfTest

runjava com.rabbitmq.perf.PerfTest -h amqp://guest:guest@127.0.0.1:5672 -e xxx_exchange -k xxx_route -s 50 -x 5 -y 0 --body-content-type application/json -t topic -p

使用2个发布者和4个消费者:

runjava com.rabbitmq.perf.PerfTest -x 2 -y 4 -u "test-2" -a --id "test 2"

此修改将消费者切换到手动确认:

runjava com.rabbitmq.perf.PerfTest -x 1 -y 2 -u "test-3" --id "test 3"

修改将消息大小从默认(12字节)更改为4 kB:

runjava com.rabbitmq.perf.PerfTest -x 1 -y 2 -u "test-4" --id "test 4" -s 4000

使用持久队列和持久消息:

runjava com.rabbitmq.perf.PerfTest -x 1 -y 2 -u "test-5" --id "test-5" -f persistent

选项说明:

  • -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,-- 允许使用预先声明的对象
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值