【发布时间】:2016-03-18 01:36:45
【问题描述】:
我有基于 Celery 的任务队列,其中 RabbitMQ 作为代理。我每天处理大约 100 条消息。我没有设置后端。
我这样启动任务大师:
broker = os.environ.get('AMQP_HOST', None)
app = Celery(broker=broker)
server = QueueServer((default_http_host, default_http_port), app)
...我这样启动工人:
broker = os.environ.get('AMQP_HOST', None)
app = Celery('worker', broker=broker)
app.conf.update(
CELERYD_CONCURRENCY = 1,
CELERYD_PREFETCH_MULTIPLIER = 1,
CELERY_ACKS_LATE = True,
)
服务器正常运行了很长一段时间,但大约两周后它突然停止。我已经追踪到 RabbitMQ 由于内存耗尽而不再接收消息:
Feb 25 02:01:39 render-mq-1 docker/e654ac167b10[2189]: vm_memory_high_watermark set. Memory used:252239992 allowed:249239961
Feb 25 02:01:39 render-mq-1 docker/e654ac167b10[2189]: =WARNING REPORT==== 25-Feb-2016::02:01:39 ===
Feb 25 02:01:39 render-mq-1 docker/e654ac167b10[2189]: memory resource limit alarm set on node rabbit@e654ac167b10.
Feb 25 02:01:39 render-mq-1 docker/e654ac167b10[2189]: **********************************************************
Feb 25 02:01:39 render-mq-1 docker/e654ac167b10[2189]: *** Publishers will be blocked until this alarm clears ***
Feb 25 02:01:39 render-mq-1 docker/e654ac167b10[2189]: **********************************************************
问题是我无法弄清楚需要进行哪些不同的配置以防止这种耗尽。显然某处没有清除某些东西,但我不明白是什么。
例如,大约 8 天后,rabbitmqctl status 向我显示:
{memory,[{total,138588744},
{connection_readers,1081984},
{connection_writers,353792},
{connection_channels,1103992},
{connection_other,2249320},
{queue_procs,428528},
{queue_slave_procs,0},
{plugins,0},
{other_proc,13555000},
{mnesia,74832},
{mgmt_db,0},
{msg_index,43243768},
{other_ets,7874864},
{binary,42401472},
{code,16699615},
{atom,654217},
{other_system,8867360}]},
...刚开始时它要低得多:
{memory,[{total,51076896},
{connection_readers,205816},
{connection_writers,86624},
{connection_channels,314512},
{connection_other,371808},
{queue_procs,318032},
{queue_slave_procs,0},
{plugins,0},
{other_proc,14315600},
{mnesia,74832},
{mgmt_db,0},
{msg_index,2115976},
{other_ets,1057008},
{binary,6284328},
{code,16699615},
{atom,654217},
{other_system,8578528}]},
...即使所有队列都为空(当前正在处理的一项作业除外):
root@dba9f095a160:/# rabbitmqctl list_queues -q name memory messages messages_ready messages_unacknowledged
celery 61152 1 0 1
celery@render-worker-lg3pi.celery.pidbox 117632 0 0 0
celery@render-worker-lkec7.celery.pidbox 70448 0 0 0
celeryev.17c02213-ecb2-4419-8e5a-f5ff682ea4b4 76240 0 0 0
celeryev.5f59e936-44d7-4098-aa72-45555f846f83 27088 0 0 0
celeryev.d63dbc9e-c769-4a75-a533-a06bc4fe08d7 50184 0 0 0
我不知道如何找到内存消耗的原因。任何帮助将不胜感激。
【问题讨论】:
-
似乎您的队列(或交换)正在进入流动状态。请检查一下 - 它在 rabbitmq 网络用户界面中可见
-
此特定服务器未安装或配置 Web UI。有没有使用rabbitmqctl 或其他命令行工具查找这些信息的简单方法?另外,通过阅读Understanding flow control,我不确定这是怎么回事,因为描述暗示服务器无法跟上传入的连接,但请求从未超过每分钟 3-4 个。
-
我不知道命令行...是的,流意味着发布者/s对于服务器来说太快了。这也可以解释为消费者太慢了处理消息,但最后似乎只有发布者冷导致此。 rabbitmq.com/memory.html
-
我很确定这不是问题所在。我在等待处理的队列中从来没有超过 20 个项目。
-
服务器的总内存是多少? 2GB 是 rabbitmq 内存消耗的适当限制吗?您是否检查过
dmesg输出以查看是否在任何阶段调用了内核OOM 杀手?你有没有运行htop来查看服务器上的整体内存利用率是多少?