RabbitMQ(五):RabbitMQ性能测试

背景:最近需要了解RabbitMQ相关知识并对其做个简单的性能测试。RabbitMQ Performance Testing Tools(PerfTest)是一款开源的性能测试工具。

工具:rabbitmq_server-3.7.15 + centos7 + rabbitmq-perf-test-2.12.0 + Window10

1. rabbitmq-perf-test工具下载安装

RabbitMQ有一个测试吞吐量的性能测试工具PerfTest。它是基于Java开发的客户端。可以配置为模拟基本和高级两种负载。源码下载地址:https://bintray.com/rabbitmq/java-tools/perf-test/2.12.0

使用

下载后的源码目录如下:

将html目录中的数据拷贝到bin目录下:

将examples目录中的文件也拷贝到bin目录:

 

2. rabbitmq-perf-test工具使用

切换到bin目录下 runjava com.rabbitmq.perf.PerfTest --help

Parsing failed. Reason: Unrecognized option: --helprunjava
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
 -mc,--metrics-client                            enable client metrics
 -mcl,--metrics-class-loader                     enable JVM class loader
                                                 metrics
 -mda,--metrics-datadog                          enable Datadog metrics
 -mdak,--metrics-datadog-application-key <arg>   Datadog application key
 -mdd,--metrics-datadog-descriptions             if meter descriptions
                                                 should be sent to Datadog
 -mdh,--metrics-datadog-host-tag <arg>           tag that will be mapped
                                                 to "host" when shipping
                                                 metrics to datadog
 -mdk,--metrics-datadog-api-key <arg>            Datadog API key
 -mds,--metrics-datadog-step-size <arg>          step size (reporting
                                                 frequency) to use in
                                                 seconds, default is 10
                                                 seconds
 -mdu,--metrics-datadog-uri <arg>                URI to ship metrics,
                                                 useful when using a
                                                 proxy, default is
                                                 https://app.datadoghq.com
 -mh,--metrics-help                              show metrics usage
 -mjgc,--metrics-jvm-gc                          enable JVM GC metrics
 -mjm,--metrics-jvm-memory                       enable JVM memory metrics
 -mjp,--metrics-processor                        enable processor metrics
                                                 (gathered by JVM)
 -mjt,--metrics-jvm-thread                       enable JVM thread metrics
 -mjx,--metrics-jmx                              enable JMX metrics
 -mp,--message-properties <arg>                  message properties as
                                                 key/value pairs,
                                                 separated by commas, e.g.
                                                 priority=5
 -mpe,--metrics-prometheus-endpoint <arg>        the HTTP metrics
                                                 endpoint, default is
                                                 /metrics
 -mpp,--metrics-prometheus-port <arg>            the port to launch the
                                                 HTTP metrics endpoint on,
                                                 default is 8080
 -mpr,--metrics-prometheus                       enable Prometheus metrics
 -mpx,--metrics-prefix <arg>                     prefix for PerfTest
                                                 metrics, default is
                                                 perftest_
 -ms,--use-millis                                should latency be
                                                 collected in
                                                 milliseconds, default is
                                                 false. Set to true if
                                                 producers are consumers
                                                 run on different
                                                 machines.
 -mt,--metrics-tags <arg>                        metrics tags as key-value
                                                 pairs separated by commas
 -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_s
                                                 sl 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
 -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)

具体使用(切换到bin目录下使用):

(1)一个生产者,一个消费者

runjava com.rabbitmq.perf.PerfTest -x 1 -y 1 -h "amqp://用户名:密码@ip:端口" -u "perf-test1" -a --id "test1"

runjava com.rabbitmq.perf.PerfTest -x 1 -y 1 -h "amqp://cui:123456@10.9.57.112:5672" -u "perf-test1" -a --id "test1"

解释:

-x:生产者计数

-y:消费者计数

-h:mq服务地址

-u:队列名

-a:自动ack回复

--id:测试id

测试结果:平均每秒发送6619条消息,平均接收2302条消息

(2)一个生产者,一个消费者,消息大小从默认(12字节)更改为4 kB

runjava com.rabbitmq.perf.PerfTest -x 1 -y 1 -h "amqp://cui:123456@10.9.57.112:5672" -u "perf-test1" -a --id "test1" -s 4000

测试结果:平均每秒发送1098条消息,平均接收102条消息

 

 

 

评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值