Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is a reasonable value for heartbeat in RabbitMQ?

Tags:

rabbitmq

RabbitMQ allows you to "heartbeat" a connection, i.e. from time to time the client and the server check (using empty messages) that the other party is still there and available. So far, so good.

Unfortunately, I was not able to find a place in the documentation where a suggestion is made what a reasonable value for this is. I know that you need to specify the heartbeat in seconds, but what is a real-world best practice value?

Obviously, it should not be too often (traffic), but also not too rare (proxies, …). Any suggestions?

Is 15 seconds fine? 30? 60? …?

like image 337
Golo Roden Avatar asked Sep 22 '14 23:09

Golo Roden


People also ask

What is RabbitMQ heartbeat?

The heartbeat timeout value defines after what period of time the peer TCP connection should be considered unreachable (down) by RabbitMQ and client libraries. This value is negotiated between the client and RabbitMQ server at the time of connection.

What is heartbeat interval?

This attribute specifies the approximate time between heartbeat flows that are to be passed from a sending message channel agent (MCA) when there are no messages on the transmission queue.

How many connections can RabbitMQ handle?

Below is the default TCP socket option configuration used by RabbitMQ: TCP connection backlog is limited to 128 connections.

How do I set connection timeout in RabbitMQ?

The default connection timeout for the RabbitMQ connection factory is 600 seconds (at least in the Java client API), hence your 10 minutes. You can change this by specifying to the connection factory your timeout of choice.


2 Answers

This answer if for RabbitMQ < 3.5.5, for newer versions see the answer from @bmaupin.

It depends on your application needs. Out of the box it is 10 min for RabbitMQ. If you fail to ack heartbeat twice (20min of inactivity), connection will be closed immediately without sending any connection.close method or any error from the broker side.

The case to use heartbeat is firewalls that closes inactive for a long time connection or some other network settings that doesn't allow you to have waiting connections.

In fact, hearbeat is not a must, from RabbitMQ config doc

heartbeat

Value representing the heartbeat delay, in seconds, that the server sends in the connection.tune frame. If set to 0, heartbeats are disabled. Clients might not follow the server suggestion, see the AMQP reference for more details. Disabling heartbeats might improve performance in situations with a great number of connections, but might lead to connections dropping in the presence of network devices that close inactive connections. Default: 580

Note, that having hearbeat interval too short may result in significant network overhead. Keep in mind, that hearbeat frames are sent when there are no other activity on the connection for a hearbeat time interval.

like image 148
pinepain Avatar answered Oct 07 '22 22:10

pinepain


The RabbitMQ documentation now provides a recommended heartbeat timeout value between 5 and 20 seconds:

Setting heartbeat timeout value too low can lead to false positives (peer being considered unavailable while it really isn't the case) due to transient network congestion, short-lived server flow control, and so on. This should be taken into consideration when picking a timeout value.

Several years worth of feedback from the users and client library maintainers suggest that values lower than 5 seconds are fairly likely to cause false positives, and values of 1 second or lower are very likely to do so. Values within the 5 to 20 seconds range are optimal for most environments.

Source: https://www.rabbitmq.com/heartbeats.html#false-positives

In addition, as of RabbitMQ 3.5.5 the default heartbeat timeout value is 60 seconds (https://www.rabbitmq.com/heartbeats.html#heartbeats-timeout)

like image 21
bmaupin Avatar answered Oct 08 '22 00:10

bmaupin