0
0
RabbitmqHow-ToBeginner ยท 3 min read

How to Set Memory Limit in RabbitMQ for Stable Performance

To set a memory limit in RabbitMQ, configure the vm_memory_high_watermark setting in the rabbitmq.conf file or via environment variables. This setting controls the maximum memory usage as a fraction of total RAM, helping RabbitMQ manage memory and avoid crashes.
๐Ÿ“

Syntax

The memory limit in RabbitMQ is set using the vm_memory_high_watermark configuration. It accepts either a fraction of total RAM (e.g., 0.4 for 40%) or an absolute value in bytes (e.g., 1GB).

Example options:

  • vm_memory_high_watermark = 0.4 โ€” sets limit to 40% of total RAM
  • vm_memory_high_watermark.absolute = 1073741824 โ€” sets limit to 1GB

This setting can be placed in the rabbitmq.conf file or set as an environment variable RABBITMQ_VM_MEMORY_HIGH_WATERMARK.

conf
vm_memory_high_watermark = 0.4
# or
vm_memory_high_watermark.absolute = 1073741824
๐Ÿ’ป

Example

This example shows how to set the memory limit to 512MB using the rabbitmq.conf file. This helps RabbitMQ stop accepting new messages when memory usage reaches 512MB, preventing crashes.

conf
vm_memory_high_watermark.absolute = 536870912
โš ๏ธ

Common Pitfalls

Common mistakes when setting memory limits in RabbitMQ include:

  • Setting the limit too high, which can cause RabbitMQ to crash when memory is exhausted.
  • Using an invalid format, like a percentage without a decimal (e.g., 40 instead of 0.4).
  • Not restarting RabbitMQ after changing the configuration, so changes do not take effect.

Always verify the configuration syntax and restart the RabbitMQ service after changes.

conf
Wrong:
vm_memory_high_watermark = 40

Right:
vm_memory_high_watermark = 0.4
๐Ÿ“Š

Quick Reference

SettingDescriptionExample Value
vm_memory_high_watermarkMemory limit as fraction of total RAM0.4
vm_memory_high_watermark.absoluteMemory limit as absolute bytes1073741824 (1GB)
RABBITMQ_VM_MEMORY_HIGH_WATERMARKEnvironment variable for memory limit0.3
โœ…

Key Takeaways

Set memory limits using vm_memory_high_watermark in rabbitmq.conf or environment variables.
Use a decimal fraction (e.g., 0.4) or absolute bytes (e.g., 1073741824) to specify limits.
Restart RabbitMQ after changing memory limit settings to apply changes.
Avoid setting memory limits too high to prevent RabbitMQ crashes.
Check configuration syntax carefully to avoid errors.