lihongjie0209 / myblog

4 stars 0 forks source link

RabbitMQ : 运维相关 #222

Open lihongjie0209 opened 3 years ago

lihongjie0209 commented 3 years ago

内存管理

RabbitMQ uses Resource-driven alarms to throttle publishers when consumers do not keep up.

By default, RabbitMQ will not accept any new messages when it detects that it's using more than 40% of the available memory (as reported by the OS): vm_memory_high_watermark.relative = 0.4. This is a safe default and care should be taken when modifying this value, even when the host is a dedicated RabbitMQ node.

rabbitmq达到内存限制的时候会拒绝接受消息, 内存限制使用 vm_memory_high_watermark 参数来指定

The OS and file system use system memory to speed up operations for all system processes. Failing to leave enough free system memory for this purpose will have an adverse effect on system performance due to OS swapping, and can even result in RabbitMQ process termination.

哪怕一台服务器专门用来做rabbitmq服务, 也不建议把所有的内存都分配给rabbitmq, 因为rabbitmq最总会进行系统调用进行io读写, 如果操作系统没有内存进行文件缓存, 那么会导致io操作比较慢, 从rabbitmq的角度来看会认为当前的进程出问题了, 然后触发重启.

A few recommendations when adjusting the default vm_memory_high_watermark:

These are some very broad-stroked guidelines. As with every tuning scenario, monitoring, benchmarking and measuring are required to find the best setting for the environment and workload.

lihongjie0209 commented 3 years ago

磁盘管理

Disk Space

The current 50MB disk_free_limit default works very well for development and tutorials. Production deployments require a much greater safety margin. Insufficient disk space will lead to node failures and may result in data loss as all disk writes will fail. 磁盘容量和内存容量是息息相关的, 如果磁盘容量小于内存容量, 那么内存中的数据就无法完全保存到磁盘中, 会造成数据丢失

所以当磁盘容量低于内存容量的时候, rabbitmq会进入只读模式, 避免消息丢失

Why is the default 50MB then? Development environments sometimes use really small partitions to host /var/lib, for example, which means nodes go into resource alarm state right after booting. The very low default ensures that RabbitMQ works out of the box for everyone. As for production deployments, we recommend the following:

磁盘和内存1:1

磁盘和内存 1.5:1 , 比较安全的设置

磁盘和内存 2:1 最安全的配置, 而且也没有增加的必要了