轉自:http://windwrite.com/archives/603html
咱們現有的業務就面臨此問題,消息生產太快,消費不過來,致使隊列堆積很長,把服務器內存耗盡,這時RabbitMQ的處理能力很低下。ubuntu
我在RabbitMQ社區發郵件問了下:服務器
We have the queue publisher and subscriber, the subscriber is going with multi-threads.ide
The problem is the queue has been increasing too quickly, the consumers can not follow the increment speed, as you see:ui
root@ubuntu:~# for i in `seq 1 10`;do rabbitmqctl list_queues -p /actionlog;sleep 1;done
Listing queues …
queue_storm_actionlog 12665787
…done.
Listing queues …
queue_storm_actionlog 12670873
…done.
Listing queues …
queue_storm_actionlog 12667975
…done.
Listing queues …
queue_storm_actionlog 12672645
…done.
After one day or about, the queue size can be more than 20 millions, thus RabbitMQ becomes high load and the consuming process is very slow.orm
收到的答覆郵件內容以下:htm
Increase # of throughput of consumers or reduce publishing rate. If consumers cannot
catch up, hardware upgrades will only offset the moment when systems starts running
low on resources.rabbitmqIf messages can be lost, 3.1 introduces a new feature, queue length limit:
http://www.rabbitmq.com/maxlength.html隊列Further to the suggestion of imposing a maximum queue length, you could
also consider imposing a maximum message age and instruct the broker to
discard messages that become stale: http://www.rabbitmq.com/ttl.html內存
總結起來解決方案大致包括: