PerfTest对RabbitMQ进行压力测试

下载地址:

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

下载后进行解压即可:

PerfTest对RabbitMQ进行压力测试_第1张图片

使用方式

runjava com.rabbitmq.perf.PerfTest --help
usage: 
 -?,--help                                   show usage
 -a,--autoack                                auto ack
 -A,--multi-ack-every                   multi ack every
 -ad,--auto-delete                      should the queue be
                                             auto-deleted, default is true
 -b,--heartbeat                         heartbeat interval
 -B,--body                              comma-separated list of files
                                             to use in message bodies
 -bc,--body-count                       number of pre-generated
                                             message bodies. Use with
                                             --json-body. Default is 100.
 -bfc,--body-field-count                number of pre-generated
                                             fields and values for body.
                                             Use with --json-body. Default
                                             is 1000.
 -c,--confirm                           max unconfirmed publishes
 -C,--pmessages                         producer message count
 -ca,--consumer-args                    consumer arguments as
                                             key/values pairs, separated
                                             by commas, e.g. x-priority=10
 -cri,--connection-recovery-interval    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                  waiting timeout for
                                             unconfirmed publishes before
                                             failing (in seconds)
 -ctp,--consumers-thread-pools          number of thread pools to use
                                             for all consumers, default is
                                             to use a thread pool for each
                                             consumer
 -d,--id                                test ID
 -D,--cmessages                         consumer message count
 -dcr,--disable-connection-recovery          disable automatic connection
                                             recovery
 -e,--exchange                          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                              message flag(s), supported
                                             values: persistent and
                                             mandatory. Use the option
                                             several times to specify
                                             several values.
 -h,--uri                               connection URI
 -H,--uris                              connection URIs (separated by
                                             commas)
 -hst,--heartbeat-sender-threads        number of threads for
                                             producers and consumers
                                             heartbeat senders
 -i,--interval                          sampling interval in seconds
 -jb,--json-body                             generate a random JSON
                                             document for message body.
                                             Use with --size.
 -k,--routing-key                       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                  consumer latency in
                                             microseconds
 -m,--ptxsize                           producer tx size
 -M,--framemax                          frame max
 -mh,--metrics-help                          show metrics usage
 -mp,--message-properties               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                           consumer tx size
 -na,--nack                                  nack and requeue messages
 -niot,--nio-threads                    number of NIO threads to use
 -niotp,--nio-thread-pool               size of NIO thread pool,
                                             should be slightly higher
                                             than number of NIO threads
 -o,--output-file                       output file for timing
                                             results
 -p,--predeclared                            allow use of predeclared
                                             objects
 -P,--publishing-interval               publishing interval in
                                             seconds (opposite of producer
                                             rate limit)
 -pi,--polling-interval                 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    max random delay in seconds
                                             to start producers
 -pst,--producer-scheduler-threads      number of threads to use when
                                             using --publishing-interval
 -q,--qos                               consumer prefetch count
 -Q,--global-qos                        channel prefetch count
 -qa,--queue-args                       queue arguments as key/value
                                             pairs, separated by commas,
                                             e.g. x-max-length=10
 -qp,--queue-pattern                    queue name pattern for
                                             creating queues in sequence
 -qpf,--queue-pattern-from              queue name pattern range
                                             start (inclusive)
 -qpt,--queue-pattern-to                queue name pattern range end
                                             (inclusive)
 -r,--rate                              producer rate limit
 -R,--consumer-rate                     consumer rate limit
 -rkcs,--routing-key-cache-size         size of the random routing
                                             keys cache. See
                                             --random-routing-key.
 -S,--slow-start                             start consumers slowly (1 sec
                                             delay between each)
 -s,--size                              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         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                 shutdown timeout, default is
                                             5 seconds
 -sul,--servers-up-limit                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                              exchange type
 -T,--body-content-type                 body content-type
 -u,--queue                             queue name
 -udsc,--use-default-ssl-context             use JVM default SSL context
 -v,--version                                print version information
 -vr,--variable-rate                    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                    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                         producer count
 -X,--producer-channel-count            channels per producer
 -y,--consumers                         consumer count
 -Y,--consumer-channel-count            channels per consumer
 -z,--time                              run duration in seconds
                                             (unlimited by default)

使用PerfTest

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

PerfTest对RabbitMQ进行压力测试_第2张图片

使用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 queue  队列参数键值对,使用逗号隔开,例如x-max-length=10
  • -mp,--  消息属性以逗号隔开的键值对方式,比如priority=5.
  • -B,-- 使用逗号分隔的文件列表,用在消息的内容中(这里是多个由逗号分隔开的文件名,把文件中的内容作为消息体写入到指定queue中)
  • -T,-- 消息体内容类型
  • -qp,--  按顺序依次创建的队列名称模式
  • -F,--  队列模式的开始(包含)
  • -T,-- 队列模式的结束(包含)
  • -hst,--heartbeat-sender-threads   生产者和消费者的心跳发送者的线程数量
  • -ms,-- 是否收集延迟时间,单位毫秒。默认是关闭的。如果生产者和消费者在不同的主机上运行,那么就将其设置成为true。
  • -p,-- 允许使用预先声明的对象

你可能感兴趣的:(RabbitMQ)