RabbitMQ吞吐量測試-PerfTest上
PerfTest
RabbitMQ有一個基本的吞吐量測試工具PerfTest(文檔,源代碼和版本),它基於Java客戶端,可以配置為模擬基本工作負載。PerfTest有額外的工具可以生成輸出的HTML圖形。RabbitMQ集群可能受到很多因素的限制,從基礎設施級限制(如網絡帶寬)到RabbitMQ配置和拓撲到發布和使用的應用程序。PerfTest可以演示節點或節點集群的基准性能。
安裝
PerfTest也是從Bintray和 GitHub發布的二進制版本庫中分發的 。 如果需要將它作為庫,也可以在Maven Central上使用。
Bintray:https://bintray.com/rabbitmq/java-tools/perf-test
GitHub:https://github.com/rabbitmq/rabbitmq-perf-test/releases
Maven Central:http://search.maven.org/#search|ga|1|g%3A"com.rabbitmq" AND a%3A"perf-test"
要驗證PerfTest安裝,請使用
bin/runjava com.rabbitmq.perf.PerfTest --help
can@can:/usr/local/mq/rabbitmq_server-3.6.14/rabbitmq-perf-test-2.0.0.RC4$ 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)
使用PerfTest
運行PerfTest的最基本的方法只是指定要連接的URI,要使用的發布者(比如說1)和一些消費者(比如2)。請注意,RabbitMQ Java客戶端可以實現較高的發布速率(每個連接每秒高達80至90K條消息),給予足夠的帶寬,並且當某些安全措施(發行商確認)被禁用時,很少需要過度配置發布者(除非這是特定的測試目標)。
bin/runjava com.rabbitmq.perf.PerfTest -x 1 -y 2 -u "throughput-test-1" -a --id "test 1"
使用2個發布者和4個消費者:
bin/runjava com.rabbitmq.perf.PerfTest -x 2 -y 4 -u "throughput-test-2" -a --id "test 2"
此修改將消費者切換到手動確認:
bin/runjava com.rabbitmq.perf.PerfTest -x 1 -y 2 -u "throughput-test-3" --id "test 3"
修改將消息大小從默認(12字節)更改為4 kB:
bin/runjava com.rabbitmq.perf.PerfTest -x 1 -y 2 -u "throughput-test-4" --id "test 4" -s 4000
使用持久隊列和持久消息:
bin/runjava com.rabbitmq.perf.PerfTest -x 1 -y 2 -u "throughput-test-5" --id "test-5" -f persistent