套接字关闭,使用RabbitMQ错过了客户端Celery工作者的心跳

时间:2018-12-29 15:59:40

标签: python rabbitmq celery

我创建了Flask应用程序服务器,该服务器允许在一个端点上生成Celery worker。然后,您可以将任务应用于连接到worker的特定队列。

一切正常,直到不超过2分钟不使用工作程序为止。 然后RabbitMQ记录消息

rabbit_1         | 2018-12-29 15:51:21.573 [error] <0.30372.0> closing AMQP connection <0.30372.0> (172.18.0.1:50058 -> 172.18.0.4:5672):
rabbit_1         | missed heartbeats from client, timeout: 60s

来自应用的堆栈跟踪

> [2018-12-29 16:51:26,526] ERROR in app: Exception on /sentiment [POST]
> Traceback (most recent call last):   File
> "/home/konrad/anaconda3/lib/python3.6/site-packages/flask/app.py",
> line 1612, in full_dispatch_request
>     rv = self.dispatch_request()   File "/home/konrad/anaconda3/lib/python3.6/site-packages/flask/app.py",
> line 1598, in dispatch_request
>     return self.view_functions[rule.endpoint](**req.view_args)   File "/home/konrad/anaconda3/lib/python3.6/site-packages/flask_restplus/api.py",
> line 325, in wrapper
>     resp = resource(*args, **kwargs)   File "/home/konrad/anaconda3/lib/python3.6/site-packages/flask/views.py",
> line 84, in view
>     return self.dispatch_request(*args, **kwargs)   File "/home/konrad/anaconda3/lib/python3.6/site-packages/flask_restplus/resource.py",
> line 44, in dispatch_request
>     resp = meth(*args, **kwargs)   File "/home/konrad/Documents/ubuntu-docs/python-dev/crypto-ticker-sentiment/sentinet/evaluation_server/routes/sentiment.py",
> line 25, in post
>     prediction = predict_sentiment(queue, text)   File "/home/konrad/Documents/ubuntu-docs/python-dev/crypto-ticker-sentiment/sentinet/evaluation_server/services/evaluation.py",
> line 17, in predict_sentiment
>     task_result = task.get()   File "/home/konrad/anaconda3/lib/python3.6/site-packages/celery/result.py",
> line 224, in get
>     on_message=on_message,   File "/home/konrad/anaconda3/lib/python3.6/site-packages/celery/backends/async.py",
> line 188, in wait_for_pending
>     for _ in self._wait_for_pending(result, **kwargs):   File "/home/konrad/anaconda3/lib/python3.6/site-packages/celery/backends/async.py",
> line 255, in _wait_for_pending
>     on_interval=on_interval):   File "/home/konrad/anaconda3/lib/python3.6/site-packages/celery/backends/async.py",
> line 56, in drain_events_until
>     yield self.wait_for(p, wait, timeout=1)   File "/home/konrad/anaconda3/lib/python3.6/site-packages/celery/backends/async.py",
> line 65, in wait_for
>     wait(timeout=timeout)   File "/home/konrad/anaconda3/lib/python3.6/site-packages/celery/backends/rpc.py",
> line 63, in drain_events
>     return self._connection.drain_events(timeout=timeout)   File "/home/konrad/anaconda3/lib/python3.6/site-packages/kombu/connection.py",
> line 301, in drain_events
>     return self.transport.drain_events(self.connection, **kwargs)   File
> "/home/konrad/anaconda3/lib/python3.6/site-packages/kombu/transport/pyamqp.py",
> line 103, in drain_events
>     return connection.drain_events(**kwargs)   File "/home/konrad/anaconda3/lib/python3.6/site-packages/amqp/connection.py",
> line 491, in drain_events
>     while not self.blocking_read(timeout):   File "/home/konrad/anaconda3/lib/python3.6/site-packages/amqp/connection.py",
> line 496, in blocking_read
>     frame = self.transport.read_frame()   File "/home/konrad/anaconda3/lib/python3.6/site-packages/amqp/transport.py",
> line 243, in read_frame
>     frame_header = read(7, True)   File "/home/konrad/anaconda3/lib/python3.6/site-packages/amqp/transport.py",
> line 426, in _read
>     raise IOError('Socket closed') OSError: Socket closed

我认为这可能是Celery工作者或RabbitMQ问题引起的心跳。 我在工作程序生成时添加了-without-heartbeat 选项,但是它没有用。 在RabbitMQ上禁用心跳会有所帮助吗?

更新

我在RabbitMQ doc页上找到了它,但没有说明如何实现。

  

如何禁用心跳通过设置   客户端和服务器端的超时间隔均为0。

     

或者,可以使用非常高的值(例如1800秒)   两端可以有效禁用心跳,因为帧传输将   太不实用了,没什么用。

     

除非建议使用TCP Keepalive,否则均不推荐任何做法   闲置检测时间足够短

更新2

我在{strong> rabbitmq.conf 文件中添加了heartbeat = 0,但仍然无法正常工作。

0 个答案:

没有答案