rabbitmq性能测试工具rabbitmq-perf-test(官网阅读笔记)

Java Tools

翻译:limuitech

时间:201811月

官网连接:http://www.rabbitmq.com/java-tools.html

以下内容为官网资料,非全部翻译,只是自己在阅读的时候,随手在关键部分加了自己的翻译。

翻译英文技术文档的难点除了语言之外,更重要的是对语言内容的理解,否则翻译出来也会觉得别扭。翻译能力有限,如果有问题,请大家指正;

 

This page documents some Java-based utility programs (PerfTest, Tracer).

PerfTest

RabbitMQ has a basic throughput testing tool, PerfTest (docs, source code and releases), that is based on the Java client and can be configured to simulate basic workloads. PerfTest has extra tools that produce HTML graphs of the output. A RabbitMQ cluster can be limited by a number of factors, from infrastructure-level constraints (e.g. network bandwidth) to RabbitMQ configuration and topology to applications that publish and consume. PerfTest can demonstrate baseline performance of a node or a cluster of nodes.PerfTest能够演示对一个rabbitmq节点或集群节点的基准性能测试;

 

Installation

PerfTest is distributed as a binary build archive from Bintray and GitHub releases as well. It is also available on Maven Central if one needs to use it as library. Note the documentation below can cover features available only in milestone releases or release candidates, available in our Java Tools milestones repository and in GitHub releases as well.

The distribution contains a script (bin/runjava or bin/runjava.bat) to run Java with the class path correctly configured, e.g. bin/runjava com.rabbitmq.perf.PerfTest runs the PerfTest Java class.

To verify a PerfTest installation, use

bin/runjava com.rabbitmq.perf.PerfTest --help

 

下载2.0.0版本:

RabbitMQ Performance Testing Tool 介绍:

https://www.rabbitmq.com/java-tools.html

RabbitMQ Performance Testing Tool 下载:

https://github.com/rabbitmq/rabbitmq-perf-test/releases

https://bintray.com/rabbitmq/java-tools/perf-test

cd /opt/software

wget https://github.com/rabbitmq/rabbitmq-perf-test/releases/download/v2.0.0/rabbitmq-perf-test-2.0.0-bin.tar.gz

tar -xvz -f ./rabbitmq-perf-test-2.0.0-bin.tar.gz

cd ./rabbitmq-perf-test-2.0.0

 

Using PerfTest

The most basic way of running PerfTest only specifies a URI to connect to, a number of publishers to use (say, 1) and a number of consumers to use (say, 2). Note that RabbitMQ Java client can achieve high rates for publishing (up to 80 to 90K messages per second per connection), given enough bandwidth and when some safety measures (publisher confirms) are disabled, so overprovisioning publishers is rarely necessary (unless that's a specific objective of the test).

执行PerfTest最基本的方法是指定要使用的URL(ampq(s)://username:password@host:port/vhostname)、生产者数量(比如说1)和消费者数量(比如2)。注意,rabbitmq java客户端能够达到较高的发布速度(每个connection每秒发布可以达到80000到90000个消息),这是在带宽充足,并且关闭了一些安全措施(生产者确认),因此,没必要提供过量的生产者(除非那是一个确定的测试目标)。

The following command runs PerfTest with a single publisher without publisher confirms, two consumers (each receiving a copy of every message) that use automatic acknowledgement mode and a single queue named “throughput-test-x1-y2”. Publishers will publish as quickly as possible, without any rate limiting. Results will be prefixed with “test 1” for easier identification and comparison:

下面的命令在关闭了生产者确认机制的情况下,执行性能测试(PerfTest),这个测试中有1个生产者、2个消费者(每个消费者接收每条消息的一个副本)和一个名为“throughput-test-x1-y2”的队列,其中,消费者开启了自动的确认机制(acknowledgement mode)模式。生产者将会尽快发布消息,没有任何速度限制。结果以“test 1”位前缀用来更容易验证和对比:

bin/runjava com.rabbitmq.perf.PerfTest -x 1 -y 2 -u "throughput-test-1" -a --id "test 1"

选项说明:

-x,--producers producer count(生产者数量)

-y,--consumers consumer count(消费者数量)

-u,--queue queue name(队列名称)

-a,--autoack auto ack,客户端在处理完messages之后会给服务端返回一个ack确认信息,服务端在收到该ack信息之后才会把messages删除;

-d,--id test ID(本次测试的编号,身份标识)

This modification will use 2 publishers and 4 consumers, typically yielding higher throughput given enough CPU cores on the machine and RabbitMQ nodes:下面修改为2个生产者和4个消费者,如果机器上的CPU核数和RabbitMQ节点数量充足的话,明显会产生更高的吞吐量。

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

This modification switches consumers to manual acknowledgements:这里把消费者切换为手动确认(译者注:去掉了-a选项)。

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

译者注:

为了保证数据不被丢失,RabbitMQ支持消息确认机制,即ack。为了保证数据能被正确处理而不仅仅是被Consumer收到,我们就不能采用no-ack或者auto-ack,我们需要手动ack(manual-ack)。在数据处理完成后手动发送ack,这个时候Server才将Message删除。()

This modification changes message size from default (12 bytes) to 4 kB:这里把消息的大小改为了4kb(默认值为12字节):

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

选项说明:

-s,--size message size in bytes(消息大小,单位是字节)

PerfTest can use durable queues and persistent messages:PerfTest可以使用持久化的队列和持久化的消息(注意:queue和message是两个不同的概念):

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

选项说明:

-f,--flag message flag(s) separated by commas. Supported values: persistent and mandatory(消息标志,多个可以用逗号隔开,支持的值:persistent 和 mandatory)

译者注:

消息持久化和队列持久化是两个操作,队列持久化了,不代表消息也会持久化,二者的持久化需要在代码中各自独立的配置。(我有个疑问:publisher和consumer的持久化配置与否,跟rabbitmq集群中的disk节点有什么关系?与设置镜像队列策略有什么关系?在使用2个ram节点+1个disk节点的rabbitmq集群的时候,如果用户的应用没有设置队列和消息的持久化,那么这些消息和队列是否会写入磁盘?从网上找到的资料:RabbitMQ对于queue中的message的保存方式有两种方式:disc和ram。如果采用disc,则需要对exchange/queue/delivery mode都要设置成durable模式。也就是说,rabbitmq服务器设置了磁盘节点,还要配合publisher应用和consumer应用对相关元素的持久化设置才能实现真正的持久化。那默认值是什么?)

 

如过将queue的持久化标识durable设置为true,则代表是一个持久的队列,那么在服务重启之后,也会存在,因为服务会把持久化的queue存放在硬盘上,当服务重启的时候,会重新什么之前被持久化的queue。队列(queues)是可以被持久化,但是里面的消息(messages)是否为持久化那还要看消息的持久化设置。也就是说,重启之前那个queue里面存在还没有发出去的消息的话,重启之后那队列里面是不是还存在原来的消息,这个就要取决于发生着在发送消息时对消息的设置了。

如果要在重启后保持消息的持久化必须设置消息是持久化的标识。

When PerfTest is running, it is important to monitor various publisher and consumer metrics provided by the management UI. For example, it is possible to see how much network bandwidth a publisher has been using recently on the connection page.

当运行PerfTest的时候,有一点很重要,那就是通过management UI监控生产者和消费者的各项指标。例如,可以在connection页面看到生产者最近使用的网络带宽是多少。

 

Queue page demonstrates message rates, consumer count, acknowledgement mode used by the consumers, consumer utilisation and message location break down (disk, RAM, paged out transient messages, etc). When durable queues and persistent messages are used, node I/O and message store/queue index operation metrics become particularly important to monitor.

Queue页面展示了消息速度,消费者数量,消费者使用的确认模式,消费者使用率和消息发生故障的地方(磁盘、内存、短暂消息的页置换等)。当使用了持久化队列和持久化消息的时候,对节点I/O和消息存储/队列索引操作指标的监控变得尤其重要;

 

Consumers can ack multiple messages at once, for example, 100 in this configuration:消费者可以一次确认多条消息,例如,下面是100条消息确认一次

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

选项说明:

-A,--multi-ack-every multi ack every(每多少条消息返回一次ack信息给服务器端)

Consumer prefetch (QoS) can be configured as well (in this example to 500):我们也可以配置消费者预读取(QoS)(译者注:prefetch是每次从一次性从broker里面取的待消费的消息的个数)。

bin/runjava com.rabbitmq.perf.PerfTest -x 1 -y 2 -u "throughput-test-7" --id "test-7" -f persistent --multi-ack-every 200 -q 500

选项说明:

-q,--qos consumer prefetch count(消费者预读取的数量)

Publisher confirms can be used with maximum of N outstanding publishes:生产者确认机制开启之后,能够设置未解决的发布的最大值(译者注:生产者将信道(channel)设置成confirm模式,一旦信道(channel,confirm是信道的一种工作模式)进入confirm模式,所有在该信道上面发布的消息都会被指派一个唯一的ID(从1开始),一旦消息被投递到所有匹配的队列(queue)之后,broker(一个消息服务器实例)就会发送一个确认(confirm)给生产者(包含消息的唯一ID),这就使得生产者知道消息已经正确到达目的队列了,如果消息和队列是可持久化的,那么确认消息会将消息写入磁盘之后发出(这样会有延迟吧?),broker回传给生产者的确认消息中deliver-tag域包含了确认消息的序列号,此外broker也可以设置basic.ack的multiple域,表示到这个序列号之前的所有消息都已经得到了处理。)

bin/runjava com.rabbitmq.perf.PerfTest -x 1 -y 2 -u "throughput-test-8" --id "test-8" -f persistent -q 500 -c 500

选项说明:

-c,--confirm max unconfirmed publishes(未确认消息发布的最大值)

PerfTest can publish only a certain number of messages instead of running until shut down:这里配置了PerfTest从运行到关闭期间,发布指定数量的消息。

bin/runjava com.rabbitmq.perf.PerfTest -x 1 -y 2 -u "throughput-test-10" --id "test-10" -f persistent -q 500 -pmessages 100000

选项说明:

-C,--pmessages producer message count(生产者要生成的消息的数量,译者注:在此次性能测试中,生产者一旦生成了指定数量的消息,就会停止。)

Publisher rate can be limited:我们可以限制生产者的速度;

bin/runjava com.rabbitmq.perf.PerfTest -x 1 -y 2 -u "throughput-test-11" --id "test-11" -f persistent -q 500 --rate 5000

选项说明:

-r,--rate producer rate limit(生产者速度限制)

Consumer rate can be limited as well to simulate slower consumers or create a backlog:我们也可以限制消费者的消费速度,通过模拟耗时的消费者或者创建一个backlog队列:

bin/runjava com.rabbitmq.perf.PerfTest -x 1 -y 2 -u "throughput-test-12" --id "test-12" -f persistent --rate 5000 --consumer-rate 2000

选项说明:

-R,--consumer-rate consumer rate limit(消费者速度限制)

Note that the consumer rate limit is applied per consumer, so in the configuration above the limit is actually 2 * 2000 = 4000 deliveries/second.

注意:上面对消费者速度的限制是应用于每一个消费者的,因此上面配置中的限速实际上是2 * 2000 = 4000转发/s

 

PerfTest can be configured to run for a limited amount of time in seconds with the -z option:PerfTesT的-z选项,可以让其运行指定的一段时间长度。

bin/runjava com.rabbitmq.perf.PerfTest -x 1 -y 2 -u "throughput-test-13" --id "test-13" -f persistent -z 30

选项说明:

-z,--time run duration in seconds (unlimited by default)(运行时间,单位是秒(默认没有限制))。

Running PerfTest without consumers and with a limited number of messages can be used to pre-populate a queue, e.g. with 1M messages 1 kB in size each:没有消费者同时指定有限数量的消息,这种配置的性能测试可以用预生成队列,比如1M条消息,每条大小为1k的。

bin/runjava com.rabbitmq.perf.PerfTest -y0 -p -u "throughput-test-14" -s 1000 -C 1000000 --id "test-14" -f persistent

选项说明:

-p,--predeclared allow use of predeclared objects(允许使用预定义的对象)

Use the -D option to limit the number of consumed messages. Note the -z (time limit), -C (number of published messages), and -D (number of consumed messages) options can be used together but their combination can lead to funny results. -r 1 -x 1 -C 10 -y 1 -D 20 would for example stop the producer once 10 messages have been published, letting the consumer wait forever the remaining 10 messages (as the publisher is stopped).

使用-D选项来限制消费消息的数量。注意,-z(时间限制选项),-C(生成消息的数量)和-D(被消费的消息的数量)选项能够被一起使用,但是它们的整合可能会导致有趣的结果;例如,-r 1 -x 1 -C 10 -y 1 -D 20配置:一旦发布了10条消息,就会停止生产者,导致消费者会永远等待剩下的10条消息(因为生产者已经停止了)。

To consume from a pre-declared and pre-populated queue without starting any publishers, use:如果要想从预定义(pre-declared)和安装(pre-populated)队列中进行消费而不启用任何生产者,可以使用如下命令:

bin/runjava com.rabbitmq.perf.PerfTest -x0 -y10 -p -u "throughput-test-14" --id "test-15"

选项说明:

-D,--cmessages consumer message count(消费者要消费的消息数量,译者注:也就是指定这次测试中消费者一共要消费多少条消息,一旦消费者消费了这么多条消息,消费者就会被停止)

PerfTest is useful for establishing baseline cluster throughput with various configurations but does not simulate many other aspects of real world applications. It is also biased towards very simplistic workloads that use a single queue, which provides limited CPU utilisation on RabbitMQ nodes and is not recommended for most cases. Multiple PerfTest instances running simultaneously can be used to simulate more realistic workloads.

如果只是对rabbitmq集群做基准性能的吞吐量测试,而不需要模拟真实世界应用的诸多方面,那么PerfTest的各种配置还是比较有用的。过于简单的工作负荷会导致测试结果有些偏差,比如使用一个queue,这样会限制RabbitMQ节点上的CPU利用率(译者注:也就是比如你的服务器是8核的,而只启用一个queue),大多数情况下都不建议这样做(译者注:过于简单的工作负荷)。你也可以通过同时运行多个PerfTest实例来模拟更真实复杂的工作负载。

 

Customising queues and messages(自定义队列和消息)

PerfTest can create queues using provided queue arguments:PerfTest通过队列参数可以自定义创建队列;

bin/runjava com.rabbitmq.perf.PerfTest --queue-arguments x-max-length=10

选项说明:

-qa,--queue-args queue arguments as key/pair values, separated by commas, e.g. x-max-length=10 队列参数键值对,使用逗号隔开,例如x-max-length=10。(译者注:参考笔记共目录下的《(重要参考)rabbitmq queue_declare arguments参数注释》一文)

x-max-length

该参数是非负整数值

官方文档

限制加入queue中消息的条数。先进先出原则,超过10条后面的消息会顶替前面的消息。

The previous command will create a queue with a length limit of 10. You can also provide several queue arguments by separating the key/value pairs with commas:上面的命令将会创建一个限制了长度为10的队列(译者注:队列长度是指可以容纳的消息的条数)。你也可以通过使用以逗号分开的键值对提供多个队列参数:

bin/runjava com.rabbitmq.perf.PerfTest --queue-arguments x-max-length=10,x-dead-letter-exchange=some.exchange.name

队列参数说明:

x-dead-letter-routing-key

x-dead-letter-exchange

官方文档

创建queue时参数arguments设置了x-dead-letter-routing-key和x-dead-letter-exchange,会在x-message-ttl时间到期后把消息放到x-dead-letter-routing-key和x-dead-letter-exchange指定的队列中达到延迟队列的目的。

arguments = { 'x-message-ttl': 10000, # 延迟时间 (毫秒) 'x-dead-letter-exchange': exchange, # 延迟结束后指向交换机(死信收容交换机) 'x-dead-letter-routing-key': queue, # 延迟结束后指向队列(死信收容队列),可直接设置queue name也可以设置routing-key } channel.queue_declare( queue='test', durable=True, arguments=arguments )

You can also specify message properties with key/value pairs separated by commas:你也可以使用逗号隔开的键值对指定消息属性;

bin/runjava com.rabbitmq.perf.PerfTest --message-properties priority=5,timestamp=2007-12-03T10:15:30+01:00

选项说明:

-mp,--message-properties message properties as key/pair values, separated by commas, e.g. priority=5 消息属性以逗号隔开的键值对方式,比如priority=5.

The supported property keys are: contentType, contentEncoding, deliveryMode, priority, correlationId, replyTo, expiration, messageId, timestamp, type, userId, appId, clusterId. If some provided keys do not belong to the previous list, the pairs will be considered as headers (arbitrary key/value pairs): 支持的属性键(keys)有:contentType, contentEncoding, deliveryMode, priority, correlationId, replyTo, expiration, messageId, timestamp, type, userId, appId, clusterId。如果提供的某些key不属于上面的列表,那么你所提供的键值对将会被认为时头部(任意的键值对):

bin/runjava com.rabbitmq.perf.PerfTest --message-properties priority=10,header1=value1,header2=value2

You can mimic real messages by specifying their content and content type. This can be useful when plugging real application consumers downstream. The content can come from one or several files and the content-type can be specified: 你可以通过指定它们的内容和内容类型来模拟真实场景的消息。当在下游插入真实消费者应用的时候很有用,(译者注:估计是为工具添加新的jar包,这个新jar包是真实的消费者应用吧)。消息的内容可以来自一个或多个文件,并且你也可以指定content-type,内容的类型(译者注:能指定的类型值有哪些?)。

bin/runjava com.rabbitmq.perf.PerfTest --body content1.json,content2.json --body-content-type application/json \ --consumers 0

选项说明:

-B,--body comma-separated list of files to use in message bodies 使用逗号分隔的文件列表,用在消息的内容中(译者注:这里是多个由逗号分隔开的文件名,把文件中的内容作为消息体写入到指定queue中)

-T,--body-content-type body content-type 消息体内容类型

-y,--consumers consumer count

 

Working with many queues(使用多个queues)

PertTest supports balancing the publishing and the consumption across a sequence of queues, e.g.: PerfTest支持跨一系列queues来实现对生产和消费操作的负载;

bin/runjava com.rabbitmq.perf.PerfTest --queue-pattern 'perf-test-%d' --queue-pattern-from 1 --queue-pattern-to 10 \ --producers 100 --consumers 100

选项说明:

-qp,--queue-pattern queue name pattern for creating queues in sequence 按顺序依次创建的队列名称模式

-F,--queue-pattern-from sequence start for queue pattern(included) 队列模式的开始(包含)

-T,--queue-pattern-to sequence end for queue pattern(included) 队列模式的结束(包含)

The previous command would create the perf-test-1, perf-test-2, ..., perf-test-10 queues and spreads the producers and consumers across them. This way each queue will have 10 consumers and 10 producers sending messages to it. 上面的命令将会创建perf-test-1、perf-test-2、......,perf-test-10这几个名称的队列,然后在这10个queue之间展开生产者和消费者(译者注:也就是一种负载均衡,把那些生产者和消费者按照某种算法负载到各个队列上。)

 

Load is balanced in a round-robin fashion:负载均衡使用的是轮询算法:

bin/runjava com.rabbitmq.perf.PerfTest --queue-pattern 'perf-test-%d' --queue-pattern-from 1 --queue-pattern-to 10 --producers 15 --consumers 30

 

With the previous command, queues from perf-test-1 to perf-test-5 will have 2 producers, and queues from perf-test-6 to perf-test-10 will have only 1 producer. Each queue will have 3 consumers.

使用上面的命令,从perf-test-1到perf-test-5队列将会有2个生产者,从perf-test-6到perf-test-10的队列将会只有一个生产者。每个queue将会有3个消费者。

Note the --queue-pattern value is a Java printf-style format string. The queue index is the only argument passed in. The formatting is very closed to C's printf. --queue-pattern 'perf-test-%03d' --queue-pattern-from 1 --queue-pattern-to 500 would for instance create queues from perf-test-001 to perf-test-500.

注意:--queue-pattern的值是一个Java printf-style格式的字符串。队列索引是唯一传递的参数(译者注:这里说的队列索引其实就是上面命令中说的%d,模式指定的开始和结束这一系列的数字,将会作为这一系列队列名称的索引用来区分各队列名)。它的格式与C语言的printf格式非常接近。--queue-pattern 'perf-test-%03d' --queue-pattern-from 1 --queue-pattern-to 500将会为实例创建名称为from perf-test-001到perf-test-500的队列。

 

 

Simulating High Loads(模拟高负载)

PerfTest can easily run hundreds of connections on a simple desktop machine. Each producer and consumer use a Java thread and a TCP connection though, so a PerfTest process can quickly run out of file descriptors, depending on the OS settings. A simple solution is to use several PerfTest processes, on the same machine or not. This is especially handy when combined with the queue sequence feature:

PerfTest在一台PC机器上可以很容易的运行数以百计的connections,每个生产者和消费者都使用一个java线程和一个TCP连接(connection),然而,也正因为如此,一个PerfTest进程会很快耗完系统上配置的文件描述符。一个简单的解决办法就是在同一台机器上使用多个PerfTest进程。这一点尤其方便,当你需要结合队列序列(queue sequence)功能使用的时候。

# This first PerfTest process creates 500 queues (from 'perf-test-1' to 'perf-test-500'). # Each queue will have 3 consumers and 1 producer sending messages to it. bin/runjava com.rabbitmq.perf.PerfTest --queue-pattern 'perf-test-%d' --queue-pattern-from 1 --queue-pattern-to 500 --producers 500 --consumers 1500 # This second PerfTest process creates 500 queues (from 'perf-test-501' to 'perf-test-1000'). # Each queue will have 3 consumers and 1 producer sending messages to it.(译者注:1500/500=3,500/500=1) bin/runjava com.rabbitmq.perf.PerfTest --queue-pattern 'perf-test-%d' --queue-pattern-from 501 --queue-pattern-to 1000 --producers 500 --consumers 1500

rabbitmq性能测试工具rabbitmq-perf-test(官网阅读笔记)_第1张图片

Those 2 processes will simulate 1000 producers and 3000 consumers spread across 1000 queues. 上面那2个进程将模拟1000个生产者和3000个消费者横跨1000个队列。

 

A PerfTest process can exhaust its file descriptors limit and throw java.lang.OutOfMemoryError: unable to create new native thread exceptions. A first way to avoid this is to reduce the number of Java threads PerfTest uses with the --heartbeat-sender-threads option: 一个PerfTest进程能够耗尽它的文件描述符限制进而抛出java.lang.OutOfMemoryError错误:无法创建新的本地线程的异常;避免这个问题的第一种方法是通过使用--heartbeat-sender-threads选项来减少PerfTest进程所使用的Java线程。

bin/runjava com.rabbitmq.perf.PerfTest --queue-pattern 'perf-test-%d' --queue-pattern-from 1 --queue-pattern-to 1000 --producers 1000 --consumers 3000 --hearteat-sender-threads 10

选项说明:

-hst,--heartbeat-sender-threads number of threads for producers and consumers heartbeat senders 生产者和消费者的心跳发送者的线程数量

By default, each producer and consumer connection uses a dedicated thread to send heartbeats to the broker, so this is 4000 threads for heartbeats in the previous sample. Considering producers and consumers always communicate with the broker by publishing messages or sending acknowledgments, connections are never idle, so using 10 threads for heartbeats for the 4000 connections should be enough. Don't hesitate to experiment to come up with the appropriate --heartbeat-sender-threads value for your use case.

默认地,每个生产者和消费者的连接(connection)都有一个专门的线程向broker发送心跳信息(译者注:从本段下面描述可以看出,线程和connections可以不是一一对应的,线程可以是跨多个connections共享的,也就是说模拟一个消费者或一个生产者,其组成元素为一个java线程和一个TCP连接,但二者是相互独立的,也就是说connections数量必定是与你所模拟的消费者和生产者数量之和是一致的,而通过connections发送数据(所有数据)的java线程数量却可以是随意的,因为就rabbitmq而言,一个消费者或一个生产者,必然会产生一个与broker进行通信的connection,只要connections有4000个,不论你那边是1个线程在发数据,还是100个线程在发数据,rabbitmq都会以为就是有4000个并发的客户端(包括生产者和消费者)存在。),因此,上面的例子中会产生4000个用于发送心跳信息的线程。考虑到生产者和消费者总是通过发布消息(publishing messages)或者发送确认信息(acknowledgments)来与broker进行通信,连接(connections)不会是空闲的(译者注:是不是意味着这里假设connection不会超时断开?),因此使用10个线程来为4000个连接(connections)发送心跳信息应该是足够的(译者注:我的理解是因为线程是进程的子集,所以运行一个PerfTest进程,可以指定用10个线程用来为那4000个消费者和生产者发送心跳信息,每个消费者和生产者都是PerfTest的一个线程)。不要怀疑,记得在你的使用场景中,为--heartbeat-sender-threads选项设置适当的值进行实验。

 

Another way to avoid java.lang.OutOfMemoryError: unable to create new native thread exceptions is to tune the number of file descriptors allowed per process at the OS level, as some distributions use very low limits. Here the recommendations are the same as for the broker, so you can refer to our networking guide.

另外一种避免 java.lang.OutOfMemoryError: unable to create new native thread exceptions的方法就是从操作系统级别调整每个进程允许使用的文件描述符数量,因为一些操作系统发行版使用非常低的限制。建议这里的设置值与broker所在机器上的配置一致,你可以参考我们的网络手册(networking guide)

 

Running Producers and Consumers on Different Machines(在不同的机器上运行生产者和消费者)

If you run producers and consumers on different machines or even in different processes, and you want PerfTest to calculate latency, you need to use the --use-millis flag. E.g. for sending messages from one host: 如果你在不同的机器上运行生产者和消费者,甚至是不同的进程,你想让PerfTest计算延迟,这时候你需要使用--use-millis选项。比如,从一台主机上发送消息。

bin/runjava com.rabbitmq.perf.PerfTest --producers 1 --consumers 0 --predeclared --routing-key rk --queue q --use-millis

选项说明:

-ms,--use-millis should latency be collected in milliseconds, default is false. Set to true if producers are consumers run on different machines. 是否收集延迟时间,单位毫秒。默认是关闭的。如果生产者和消费者在不同的主机上运行,那么就将其设置成为true。

And for consuming messages from another host:

bin/runjava com.rabbitmq.perf.PerfTest --producers 0 --consumers 1 --predeclared --routing-key rk --queue q --use-millis

选项说明:

-p,--predeclared allow use of predeclared objects(允许使用预声明对象,预声明是什么意思?)

Note that as soon as you use --use-millis, latency is calculated in milliseconds instead of microseconds. Note also the different machines should have their clock synchronised, e.g. by NTP. If you don't run producers and consumers on different machines or if you don't want PerfTest to calculate latency, you don't need the --use-millis flag.

注意:你一旦使用了 --use-millis选项,延迟就会以ms(毫秒)而不是us(微秒)为单位来计算。还有一点需要注意,不同机器之间应该进行时间同步。比如通过NTP服务器。如果你没有在不同的机器上运行生产者和消费者,或者你没有想让PerfTest计算延迟,你就不需要使用 --use-millis标志(译者注:命令行中,带横杠的叫做选项,选项后面的值叫做参数,没有值的选项叫做flag,标志。)。

Why does one need to care about the --use-millis flag? PerfTest uses by default System.nanoTime() in messages to calculate latency between producers and senders. System.nanoTime() provides nanosecond precision but must be used only in the same Java process. So PerfTest can fall back to System.currentTimeMillis(), which provides only milliseconds precision, but is reliable between different machines as long as their clocks are synchronised.

为什么需要关心--use-millis标志呢?PerfTest默认使用System.nanoTime()方法来计算消息中生产者和senders之间的时间延迟。System.nanoTime()方法提供了ns(纳秒)精度但只能用在同一个java进程中。因此PerfTest可以转而调用System.currentTimeMillis(),虽然这个函数只提供毫秒级的精度,但在不同机器之间是可靠的,只要机器的时间是同步的。

 

 

How It Works

If a queue name is defined (-u "queue-name"), PerfTest will create a queue with this name and all consumers will consume from this queue. The queue will be bound to the direct exchange with its name as the routing key. The routing key will be used by producers to send messages. This will cause messages from all producers to be sent to this single queue and all consumers to receive messages from this single queue.

如果你在命令行中定义了一个队列名称(-u "queue-name"),PerfTest将创建一个队列并以此命名,该PerfTest进程的所有消费者都会从这个queue中消费。这个queue会使用它自身的名字作为路由键(routing key)绑定到直接交换机(direct exchange)。路由key将会被生产者发送消息的时候用到。这会导致所有生产者发布的消息都会被送到这一个queue中,同时,所有的消费者也从这一个queue中接收消息。

If the queue name is not defined, PerfTest will create a random UUID routing key with which producers will publish messages. Each consumer will create its own anonymous queue and bind it to the direct exchange with this routing key. This will cause each message from all producers to be replicated to multiple queues (number of queues equals number of consumers), while each consumer will be receiving messages from only one queue.

如果没有定义queue的名称,PerfTest将创建一个随机的UUID路由键,生产者将使用这个路由键来发布消息。每个消费者会创建它自己的匿名队列并且使用这个随机的UUID路由键将这个队列绑定到直接路由(direct exchange)。

参考文章:

《RabbitMQ Exchange类型详解》https://www.cnblogs.com/julyluo/p/6265775.html

 

TLS Support

PerfTest can use TLS to connect to a node that is configured to accept TLS connections. To enable TLS, simply specify a URI that uses the amqps schema:

bin/runjava com.rabbitmq.perf.PerfTest -h amqps://localhost:5671

By default PerfTest automatically trusts the server and doesn't present any client certificate (a warning shows up in the console). In many benchmarking or load testing scenarios this may be sufficient. If peer verification is necessary, it is possible to use the appropriate JVM properties on the command line to override the default SSLContext. For example, to trust a given server:

JAVA_OPTS="-Djavax.net.ssl.trustStore=/path/to/server_key.p12 -Djavax.net.ssl.trustStorePassword=bunnies -Djavax.net.ssl.trustStoreType=PKCS12" \ bin/runjava com.rabbitmq.perf.PerfTest -h amqps://localhost:5671

The previous snippet uses a one-liner to define the JAVA_OPTS environment variable while running PerfTest. Please refer to the TLS guide to learn about how to set up RabbitMQ with TLS. A convenient way to generate a CA and some self-signed certificate/key pairs for development and QA environments is with tls-gen. tls-gen's basic profile is a good starting point. How to run PerfTest with a certificate/key pair generated by the aforementioned profile:

JAVA_OPTS="-Djavax.net.ssl.trustStore=/path/to/server_key.p12 -Djavax.net.ssl.trustStorePassword=bunnies -Djavax.net.ssl.trustStoreType=PKCS12 -Djavax.net.ssl.keyStore=/path/to/client_key.p12 -Djavax.net.ssl.keyStorePassword=bunnies -Djavax.net.ssl.keyStoreType=PKCS12" \ bin/runjava com.rabbitmq.perf.PerfTest -h amqps://localhost:5671

 

Result Reporting in HTML(测试报告)

The PerfTest HTML extension are a set of tools that can help you run automated benchmarks by wrapping around the PerfTest benchmarking framework. You can provide benchmark specs, and the tool will take care of running the benchmark, collecting results and displaying them in an HTML page. Learn more here.

rabbitmq-perf-test/README.md at master · rabbitmq/rabbitmq-perf-test · GitHub:

https://github.com/rabbitmq/rabbitmq-perf-test/blob/master/html/README.md

PerfTest HTML扩展是一套工具,它通过封装PerfTest 基准测试框架,能帮助你运行自动化基准测试。你可以提供基准测试配置参数,然后这个工具将谨慎的运行基准测试,收集结果并将其显示在一个HTML页面中。

 

Tracer

The tracer is a very basic, very simple AMQP 0-9-1 protocol analyzer, similar in purpose to Wireshark. Use it with the runtracer or runtracer.bat script:

runtracer listenPort connectHost connectPort

listenPort

port to listen for incoming AMQP connections on - defaults to 5673.

connectHost

hostname to use when making an outbound connection in response to an incoming connection - defaults to localhost.

connectPort

port number to use when making an outbound connection - defaults to 5672.

 

Download and source code

Releases: Bintray GitHub releases

Source code

 

 

 

附录:

测试工具的帮助信息:

./runjava com.rabbitmq.perf.PerfTest --help

usage:

-?,--help show usage

-A,--multi-ack-every multi ack every

-a,--autoack auto ack

-ad,--auto-delete should the queue be auto-deleted,

default is true

-B,--body comma-separated list of files to

use in message bodies

-b,--heartbeat heartbeat interval

-C,--pmessages producer message count

-c,--confirm max unconfirmed publishes

-ct,--confirm-timeout waiting timeout for unconfirmed

publishes before failing (in seconds)

-D,--cmessages consumer message count

-d,--id test ID

-e,--exchange exchange name

-F,--queue-pattern-from sequence start for queue pattern

(included)

-f,--flag message flag(s) separated by

commas. Supported values: persistent and mandatory

-H,--uris connection URIs (separated by

commas)

-h,--uri connection URI

-hst,--heartbeat-sender-threads number of threads for producers

and consumers heartbeat senders

-i,--interval sampling interval in seconds

-K,--random-routing-key use random routing key per

message

-k,--routing-key routing key

-L,--consumer-latency consumer latency in microseconds

-l,--legacy-metrics display legacy metrics

(min/avg/max latency)

-M,--framemax frame max

-m,--ptxsize producer tx size

-mp,--message-properties message properties as key/pair

values, 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

-o,--output-file output file for timing results

-p,--predeclared allow use of predeclared objects

-Q,--global-qos channel prefetch count

-q,--qos consumer prefetch count

-qa,--queue-args queue arguments as key/pair

values, separated by commas, e.g. x-max-length=10

-qp,--queue-pattern queue name pattern for creating

queues in sequence

-R,--consumer-rate consumer rate limit

-r,--rate producer rate limit

-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

-T,--queue-pattern-to sequence end for queue pattern

(included)

-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

-X,--producer-channel-count channels per producer

-x,--producers producer count

-Y,--consumer-channel-count channels per consumer

-y,--consumers consumer count

-z,--time run duration in seconds

(unlimited by default)

你可能感兴趣的:(RabbitMQ)