Why heartbeat param not in amqp.get_producer

From @ornoone on Mon Sep 18 2017 12:09:39 GMT+0000 (UTC)

this is a question to understand why the heartbeat feature is not used for all connections.

in fact, we found out that our very small micro-service stack (5 micro-services) was consuming more and more memory of our small rabbitmq server (> 400mb ) for 1 message every minutes.

we found out that more connection (which consume around 16Mb each) was created over the time, without being closed. the «stale» connections was without heartbeat.

I investigated to find that nameko was opening $max_woker connections to the rabbitmq during medium load via get_produced function, but these connections was without the heartbeat parameters, and was not closed after use.

I just ask if this is intended, or if this should be reworked.

after some experiment, it seem the add of heartbeat for get_producer remove the extra connection after the load has passed and thus the memory used by rabbitmq is lower for a small cluster of services.

version for testing:

nameko latest master (commit 286d141af2e0fe3fc5b592228c4cea93ca495d81)
amqp==1.4.9

RabbitMQ 3.6.10, Erlang 19.3

Copied from original issue: https://github.com/nameko/nameko/issues/473

From @mattbennett on Wed Sep 20 2017 13:52:14 GMT+0000 (UTC)

Kombu (the library we use to send and receive AMQP messages) only supports heartbeats for consumer connections. Publishers use a pool of connections managed by Kombu, and at least within Nameko there’s no mechanism to regularly send the heartbeats down these connections (unlike the consumers, which have a thread each).

You can probably improve your memory consumption by limiting the size of the pools.

By adding the heartbeat parameter to get_producer you’re probably configuring the underlying connection with a heartbeat, but never actually sending the beat from the client side. The server will close the connection after two heats are missed, which is probably why you get your memory back. It’s very inefficient though, since every connection lives for a maximum of 2 * heartbeat seconds.

Ultimately I’d love to support heartbeats for publisher connections, but we’d need to replace kombu with a better AMQP library to do so.