Commit Graph

25528 Commits

Author SHA1 Message Date
Victor Gaiva 4b0b92631b
Update PROTOCOL.adoc
Fix missing ResponseCode in type definition.
2022-05-16 21:15:40 -03:00
Michael Klishin 949f7e37db
Bump credentials_obfuscation to 3.1.0 2022-05-16 23:54:32 +04:00
David Ansari 4472ddf71c Increase receiving throughput from a stream via AMQP
This commit increases consumption throughput from a stream via AMQP 0.9.1
for 1 consumer by 83k msg/s or 55%,
for 4 consumers by 140k msg/s or 44%.

This commit tries to follow https://www.erlang.org/doc/efficiency_guide/binaryhandling.html
by reusing match contexts instead of creating new sub-binaries.

The CPU and mmap() memory flame graphs show that
when producing and consuming from a stream via AMQP 0.9.1
module amqp10_binary_parser requires
before this commit: 10.1% CPU time and 8.0% of mmap system calls
after this commit:  2.6% CPU time 2.5% of mmap system calls

Performance tests

Start rabbitmq-server without any plugins enabled and with 4 schedulers:
```
make run-broker PLUGINS="" RABBITMQ_SERVER_ADDITIONAL_ERL_ARGS="+JPperf true +S 4"
```

Test 1

Perf test client:
```
-x 1 -y 2 -qa x-queue-type=stream -ad false -f persistent -u s1 --qos 10000 --multi-ack-every 1000 -z 30
```

master branch:
sending rate avg msg/s 143k - 146k
receiving rate avg msg/s 188k - 194k

PR:
sending rate avg 133k - 138k
receiving rate avg 266k - 276k

This shows that with AMQP 0.9.1 and a stream, prior to this commit the broker could not
deliver messages to consumers as fast as they were published.
After this commit, it can.

Test 2

First, produce a few millions messages:
```
-x 1 -y 0 -qa x-queue-type=stream -ad false -f persistent -u s2
```
Then, consume them:
```
-x 0 -y 1 -qa x-queue-type=stream -ad false -f persistent -u s2 --qos 10000 --multi-ack-every 1000 -ca x-stream-offset=first -z 30
```

receving rate avg msg/s
master branch:
147k - 156k

PR:
230k - 237k

Improvement: 83k / 55%

Test 3

-x 0 -y 4 -qa x-queue-type=stream -ad false -f persistent -u s2 --qos 10000 --multi-ack-every 1000 -ca x-stream-offset=first -z 30

receving rate avg msg/s
master branch:
313k - 319k

PR:
450k - 461k

Improvement: 140k / 44%
2022-05-16 09:07:46 +00:00
Michael Klishin 5cf3a43523
Revert "Make master depend on credentials_obfuscation main branch"
This reverts commit 62819f3bcc.

This commit has served its QA purpose.

Will either update Bazel dependency to use git or pin to
a new release instead.
2022-05-14 02:58:07 +04:00
Michael Klishin 62819f3bcc
Make master depend on credentials_obfuscation main branch 2022-05-14 01:42:09 +04:00
Michael Klishin 149a7e78cf
Merge pull request #4803 from rabbitmq/rabbitmq-server-4799
Report crypto library version in 'rabbitmq-diagnostics status'
2022-05-12 16:42:40 +04:00
Michael Klishin 7ccd9821d7
Merge pull request #4801 from rabbitmq/less-mmap
Save memory when acking messages to quorum queue
2022-05-12 16:24:37 +04:00
Michael Klishin 2b80ed5c5e
Report crypto library version in 'rabbitmq-diagnostics status'
Just like we do in the node startup banner.

Closes #4799.
2022-05-12 16:19:41 +04:00
David Ansari a45ea01841 Save memory when acking messages to quorum queue
List `MsgIds` has fewer elements than list `Settles`.
Therefore, put it on the left side of the `++` operator.

The memory flame graph revealed that before this commit
5%-8% of all mmap() system calls happened in function
rabbit_fifo_client:settle/3.

After this commit only 1.6% - 1.8% of all mmap() system calls happen in
this function.

Note that we cannot do the same for discarded messages (`Discards`)
because the order in which messages will be dead lettered need to be
preserved.
2022-05-12 11:38:40 +00:00
David Ansari 04938f1d6a Fix unit test
The new default format of the log level is the full name.
2022-05-12 10:01:04 +00:00
David Ansari bcc742c834 Change default format of log level to full name
The default format of how the log level gets printed should be the full
name. For example, we want "debug" instead of "dbug".

This was also the default behaviour before commit aca638abbb
2022-05-12 09:23:14 +00:00
Michael Klishin 7107e3ea9e
Merge pull request #4793 from cloudamqp/log_levels
Clarify documented/allowed log_level arg of rabbitmqctl set_log_level
2022-05-12 00:22:06 +04:00
Péter Gömöri 542ffeebb5 Clarify documented/allowed log_level arg of rabbitmqctl set_log_level
The `critical` log level is already documented on the website/logging section.
2022-05-11 19:22:28 +02:00
David Ansari 3ed7dfd800 Resolve direct_exchange_routing_v2 deadlock
Before this commit, when importing definitions with many bindings
and then enabling the feature flag direct_exchange_routing_v2 in
parallel a dead lock occurred.

The process that did the migration was hanging in:
```
(rabbit@r1-server-2.r1-nodes.default)42> erlang:process_info(<0.1447.0>, [current_stacktrace]).
[{current_stacktrace,[{gen,do_call,4,
                           [{file,"gen.erl"},{line,214}]},
                      {gen_server2,call,3,[{file,"gen_server2.erl"},{line,342}]},
                      {rabbit_misc,execute_mnesia_transaction,1,
                                   [{file,"rabbit_misc.erl"},{line,561}]},
                      {rabbit_core_ff,direct_exchange_routing_v2_migration,3,
                                      [{file,"rabbit_core_ff.erl"},{line,213}]},
                      {rabbit_feature_flags,run_migration_fun,3,
                                            [{file,"rabbit_feature_flags.erl"},{line,1621}]},
                      {rabbit_feature_flags,do_enable,1,
                                            [{file,"rabbit_feature_flags.erl"},{line,1523}]},
                      {erpc,execute_call,4,[{file,"erpc.erl"},{line,392}]}]}]
```

while all 8 worker processes under process `definition_import_pool_sup`
were hanging in:
```
(rabbit@r1-server-2.r1-nodes.default)38> erlang:process_info(<0.592.0>, [current_stacktrace]).
[{current_stacktrace,[{global,random_sleep,1,
                              [{file,"global.erl"},{line,2505}]},
                      {global,set_lock,4,[{file,"global.erl"},{line,421}]},
                      {rabbit_feature_flags,is_enabled,2,
                                            [{file,"rabbit_feature_flags.erl"},{line,581}]},
                      {rabbit_binding,sync_index_route,3,
                                      [{file,"rabbit_binding.erl"},{line,469}]},
                      {rabbit_binding,add,4,
                                      [{file,"rabbit_binding.erl"},{line,182}]},
                      {mnesia_tm,apply_fun,3,[{file,"mnesia_tm.erl"},{line,842}]},
                      {mnesia_tm,execute_transaction,5,
                                 [{file,"mnesia_tm.erl"},{line,818}]},
                      {rabbit_misc,'-execute_mnesia_transaction/1-fun-0-',1,
                                   [{file,"rabbit_misc.erl"},{line,565}]}]}]
```

So, all worker processes which imported the bindings were blocked
because rabbit_feature_flags:is_enabled/1 blocks because the feature
flag is in state_changing.

At the same time, the process which enables the feature flag could not
proceed because it was waiting for a lock held by the worker processes.

In this commit, we resolve the dead lock by not blocking in
rabbit_feature_flags:is_enabled/2.

This should be safe because we still rely on Mnesia locking to get a
consistent migration:
1. The migration process sets both a read lock on the rabbit_route table and a
write lock on the rabbit_index_route table. Therefore, once it acquired
both locks, it can populate the new rabbit_index_route table without any
import binding processes interfering.
2. Mnesia does a good job in avoiding dead locks by restarting
transactions (as long as we don't set out own locks outside of Mnesia,
as done prior to this commit).
2022-05-11 15:25:15 +00:00
David Ansari f4c5694813 Add feature flag direct_exchange_routing_v2 2022-05-11 15:25:15 +00:00
David Ansari 84ff7e6dea Increase routing throughput for direct exchange 2022-05-11 15:25:15 +00:00
David Ansari 70a639cd19 Avoid ETS lookup if no extra_bcc queue set
A queue (Q1) can have an extra_bcc queue (Q2).
Whenever a message is routed to Q1, it must also be routed to Q2.

Commit fc2d37ed1c
puts the logic to determine extra_bcc queues into
rabbit_exchange:route/2.
That is functionally correct because it ensures that messages being dead
lettered to target queues will also route to the target queues'
extra_bcc queues.
For every message being routed, that commit uses ets:lookup/2
just to check for an extra_bcc queue.

(Technically, that commit is not a regression because it does not slow
down the common case where a message is routed to a single target queue
because before that commit rabbit_channel:deliver_to_queues/3
used two ets:lookup/2 calls.)

However we can do better by avoiding the ets:lookup/2 for the common
case where there is no extra_bcc queue set.

One option is to use ets:lookup_element/3 to only fetch the queue
'options' field.

A better option (implemented in this commit) is determining whether to
send to an extra_bcc queue in the rabbit_channel and in the at-most
and at-least once dead lettering modules where the queue records
are already looked up.

This commit speeds up sending throughput by a few thousand messages per
second.
2022-05-11 07:31:30 +00:00
David Ansari 20677395cd Check queue and exchange existence with ets:member/2
This reduces memory usage and improves code readability.
2022-05-10 10:16:40 +00:00
Arnaud Cogoluègnes f6f3f0942b
Merge pull request #3754 from rabbitmq/stream-single-active-consumer
Add single active consumer support for streams

Fixes #3753
2022-05-09 14:17:15 +02:00
Jean-Sébastien Pédron f5ac1c61df
Revert "Pre-launch logging: move type docstrings above the types"
Unlike other elements in an Erlang module, EDoc expects the description
of a type to be below its specification...

This reverts commit 03a8d49de7.
2022-05-09 11:01:52 +02:00
Arnaud Cogoluègnes 85b0625b6c
Address code review comments for stream SAC
References #3753
2022-05-09 10:52:38 +02:00
Arnaud Cogoluègnes 68e8ae8673
Rename function for clarity
References #3753
2022-05-09 10:52:38 +02:00
Arnaud Cogoluègnes 8ccdd7b6f7
Move SAC API to SAC coordinator
As per @ansd's suggestion. This way the stream coordinator
does not have to know about the SAC commands.

References #3753
2022-05-09 10:52:38 +02:00
Arnaud Cogoluègnes f4e2a95e6c
Address code review comments for stream SAC
References #3753
2022-05-09 10:52:37 +02:00
David Ansari 67126a84ae
Use more specific type 2022-05-09 10:52:37 +02:00
Arnaud Cogoluègnes da8c23d7ce
Adapt clause to send_chunk new return type
References #3753
2022-05-09 10:52:36 +02:00
Arnaud Cogoluègnes 7415abe3b5
Log message if message update response code is not OK
References #3753
2022-05-09 10:52:36 +02:00
Arnaud Cogoluègnes ee79237bf6
Return error if SAC has no name
Single active consumer must have a name, which is used as the reference
for storing offsets and as the name of the group the consumer belongs
to in case the stream is a partition of a super stream.

References #3753
2022-05-09 10:52:36 +02:00
Arnaud Cogoluègnes 4cb814dd1c
Check consumer is actually a SAC on SAC event
And do not do anything if it's not.

References #3753
2022-05-09 10:52:35 +02:00
Arnaud Cogoluègnes 8406e01297
Bump stream coordinator machine version to 3
References #3753
2022-05-09 10:52:35 +02:00
Arnaud Cogoluègnes adba97fe6e
Do not dispatch on credit request is consumer is inactive
A formerly active consumer can have in-flight credit
requests when it becomes inactive. This commit checks
the state of consumer on credit requests and make sure
not to dispatch messages if it's inactive.
2022-05-09 10:52:35 +02:00
Arnaud Cogoluègnes 827fe6f008
Add active and activity_status in stream consumer UI list
The UI handles the case where the 2 fields are not present.
This can happen in a mixed-version cluster, where a node
of a previous version returns records without the fields.
The UI uses default values (active = true, activity status = up),
which is valid as the consumers of the node are "standalone"
consumers (not part of a group).

References #3753
2022-05-09 10:52:34 +02:00
Arnaud Cogoluègnes 073c96d1ce
Tolerate unknown fields in CLI command requests
For stream consumer groups CLI commands. This is useful in case
new fields are needed in further versions. A new version
node can ask for new fields to an old version node. If
the old version node returns a known value for unknown fields
instead of failing, the new node can set up appropriate
default value for these fields in the result of the CLI commands.

References #3753
2022-05-09 10:52:34 +02:00
Arnaud Cogoluègnes a1e92b82a0
Add active and activity_status to list_stream_consumers
References #3753
2022-05-09 10:52:33 +02:00
Arnaud Cogoluègnes b1d0277048
Check active and activity_status metrics field
References #3753
2022-05-09 10:52:33 +02:00
Arnaud Cogoluègnes ad29176723
Add active and activity_status flag to stream consumer metrics
Stream consumers can be active or not with SAC, so these 2 fields
are added to the stream metrics. This is the same as with
regular consumers.

References #3753
2022-05-09 10:52:33 +02:00
Arnaud Cogoluègnes cd22bef50c
Use feature flag public API
References #3753
2022-05-09 10:52:32 +02:00
Arnaud Cogoluègnes 0806fa0b2f
Add stream single active consumer feature flag
Block stream SAC functions if the feature flag is not enabled.

References #3753
2022-05-09 10:52:32 +02:00
Arnaud Cogoluègnes bee4fcab11
Fix stream SAC coordinator unit test
It was broken after introducing the "connection label" field
for the list_stream_group_consumers CLI command.

References #3753
2022-05-09 10:52:31 +02:00
Arnaud Cogoluègnes 0623192130
Handle "active" field for stream consumers
In the regular metrics ETS table, not the one from streams.

References #3753
2022-05-09 10:52:31 +02:00
Arnaud Cogoluègnes 5ad9e349e0
Add list_stream_group_consumers CLI command
References #3753
2022-05-09 10:52:31 +02:00
Arnaud Cogoluègnes fb6481c5da
Add ignore_xref entries 2022-05-09 10:52:30 +02:00
Arnaud Cogoluègnes 434d7b5c54
Add colums argument to list_stream_consumer_groups
References #3753
2022-05-09 10:52:30 +02:00
Arnaud Cogoluègnes c8fea3a503
Indent 2022-05-09 10:52:30 +02:00
Arnaud Cogoluègnes e547972f2a
Fix target name in bazel configuration 2022-05-09 10:52:29 +02:00
Arnaud Cogoluègnes 1ec49a7aa3
Add list_stream_consumer_groups CLI command
References #3753
2022-05-09 10:52:29 +02:00
Arnaud Cogoluègnes de7f5e1088
Do not emit consumer lag for inactive consumer
References #3753
2022-05-09 10:52:28 +02:00
Arnaud Cogoluègnes 29b4b3e6be
Add unit test for SAC in super stream partition
References #3753
2022-05-09 10:52:28 +02:00
Arnaud Cogoluègnes 6b6953e948
Add unit for "simple" SAC group
"simple" meaning not part of a super stream.

References #3753
2022-05-09 10:52:28 +02:00
Arnaud Cogoluègnes d1fea82c80
Use helpers in stream SAC coordinator test
References #3753
2022-05-09 10:52:27 +02:00