减少 RabbitMQ 内存使用
我正在尝试在小型 VPS(512mb RAM)上运行 RabbitMQ 以及 Nginx 和其他一些程序。我已经能够毫无困难地调整其他所有内容的内存使用情况,但我似乎无法让 RabbitMQ 使用更少的 RAM。
我认为我需要减少 Erlang 用于 RabbitMQ 的线程数量,但我无法让它工作。我还尝试将 vm_memory_high_watermark
设置为低于默认值(40%)的几个不同值,甚至低至 5%。
部分问题可能是 VPS 提供商 (MediaTemple) 允许我查看分配的内存,因此当使用 free 或 top 时,它显示服务器有大约 900mb。
有什么建议可以减少 RabbitMQ 的内存使用量,或者限制 Erlang 创建的线程数量?我相信 Erlang 使用 30 个线程,基于我在 process 命令中看到的 -A30 标志。
理想情况下,我希望 RabbitMQ 内存使用量低于 100mb。
编辑:
将vm_memory_high_watermark
设置为5%(或配置文件中的0.05)时,RabbitMQ日志报告RabbitMQ的内存限制设置为51mb。我不确定 51mb 从哪里来。当前 VPS 分配的内存为 924mb,因此其中 5% 应该在 46mb 左右。
根据启动 RabbitMQ 之前的 htop/free,我使用的内存约为 453mb,启动 RabbitMQ 后,我的内存约为 650mb。增加了近200mb。难道 200mb 是 RabbitMQ 运行的下限吗?
编辑2
这里是启动 RabbitMQ 前后 ps aux 和 free 的一些屏幕截图以及图表显示 RabbitMQ 启动时的内存峰值。
编辑3
我还检查了没有启用插件的情况,结果几乎没有什么区别。看来我的插件(管理及其先决条件)只增加了大约 8mb 的内存使用量。
编辑 4
我不再用此服务器进行测试,但是,有一个conf设置delegate_count
,默认设置为16。据我所知,这为rabbitmq生成16个sup-procs。在较小的服务器上降低此数字可能有助于减少内存占用。不知道这是否真的有效,或者它如何影响性能,但这是值得尝试的事情。
I'm trying to run RabbitMQ on a small VPS (512mb RAM) along with Nginx and a few other programs. I've been able to tweak the memory usage of everything else without difficulty, but I can't seem to get RabbitMQ to use any less RAM.
I think I need to reduce the number of threads Erlang uses for RabbitMQ, but I've not been able to get it to work. I've also tried setting the vm_memory_high_watermark
to a few different values below the default (of 40%), even as low as 5%.
Part of the problem might be that the VPS provider (MediaTemple) allows me to go over my allocated memory, so when using free or top, it shows that the server has around 900mb.
Any suggestions to reduce memory usage by RabbitMQ, or limit the number of threads that Erlang will create? I believe Erlang is using 30 threads, based on the -A30 flag that I've seen on the process command.
Ideally I'd like RabbitMQ mem usage to be below 100mb.
Edit:
With vm_memory_high_watermark
set to 5% (or 0.05 in the config file), the RabbitMQ logs report that RabbitMQ's memory limit is set to 51mb. I'm not sure where 51mb is coming from. Current VPS allocated memory is 924mb, so 5% of that should be around 46mb.
According to htop/free before starting up RabbitMQ, I'm sitting around 453mb of used ram, and after start RabbitMQ I'm around 650mb. Nearly 200mb increase. Could it be that 200mb is the lower limit that RabbitMQ will run with?
Edit 2
Here are some screenshots of ps aux and free before and after starting RabbitMQ and a graph showing the memory spike when RabbitMQ is started.
Edit 3
I also checked with no plugins enabled, and it made very little difference. It seems the plugins I had (management and its prerequisites) only added about 8mb of ram usage.
Edit 4
I no longer have this server to test with, however, there is a conf setting delegate_count
that is set to a default of 16. As far as I know, this spawns 16 sup-procs for rabbitmq. Lowering this number on smaller servers may help reduce the memory footprint. No idea if this actually works, or how it impacts performance, but it's something to try.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
限制 RabbitMQ 中内存使用的适当方法是使用
vm_memory_high_watermark
。你说:这应该可以工作,但它的行为可能不符合您的预期。在日志中,您会发现一行告诉您绝对内存限制是什么,如下所示:
您需要根据需要调整内存限制 - Rabbit 可能会看到您的系统具有比您想象的更多的 RAM如果您在 VPS 环境上运行,则有。
有时,Rabbit 无法判断您所在的系统,并使用 1GB 作为基点(因此默认情况下您得到的限制为 410MB)。
另外,请确保您运行的 RabbitMQ 版本支持
vm_memory_high_watermark
设置 - 理想情况下,您应该使用最新的稳定版本运行。The appropriate way to limit memory usage in RabbitMQ is using the
vm_memory_high_watermark
. You said:This should work, but it might not be behaving the way you expect. In the logs, you'll find a line that tells you what the absolute memory limit is, something like this:
You need to tweak the memory limit as needed - Rabbit might be seeing your system as having a lot more RAM than you think it has if you're running on a VPS environment.
Sometimes, Rabbit can't tell what system you're on and uses 1GB as the base point (so you get a limit of 410MB by default).
Also, make sure you are running on a version of RabbitMQ that supports the
vm_memory_high_watermark
setting - ideally you should run with the latest stable release.确保设置适当的 QoS 预取值。默认情况下,如果有客户端,Rabbit 服务器会将该客户端队列中的任何消息发送给该客户端。这会导致客户端和服务器上的大量内存使用。服务器。
将预取限制降低到合理的值,比如 100,Rabbit 会将剩余的消息保留在服务器的磁盘上,直到客户端真正准备好处理它们,并且客户端和客户端上的内存使用量都会大幅下降。服务器。
请注意,建议的 100 只是一个合理的起点 - 它肯定胜过无穷大。要真正优化该数字,您需要考虑客户端每秒能够处理的消息数、网络延迟以及每条消息的平均大小。
Make sure to set an appropriate QoS prefetch value. By default, if there's a client, the Rabbit server will send any messages it has for that client's queue to the client. This results in extensive memory usage both on the client & the server.
Drop the prefetch limit down to something reasonable, like say 100, and Rabbit will keep the remaining messages on disk on the server until the client is really ready to process them, and your memory usage will go way way down on both the client & the server.
Note that the suggestion of 100 is just a reasonable place to start - it sure beats infinity. To really optimize that number, you'll want to take into consideration the messages/sec your client is able to process, the latency of your network, and also how large each of your messages is on average.