4

我在用着:

celery==3.1.12
kombu==3.0.19
amqp==1.4.5

芹菜工人开始了:

celery worker --without-gossip --without-heartbeat --without-mingle

芹菜设置:

CELERY_ALWAYS_EAGER = False
CELERY_EAGER_PROPAGATES_EXCEPTIONS = True
BROKER_URL = 'amqp://guest:guest@127.0.0.1:5672//'
BROKER_CONNECTION_TIMEOUT = 30
CELERY_RESULT_BACKEND = "amqp"
CELERY_TASK_RESULT_EXPIRES = 18000  # 5 hours.
CELERY_RESULT_PERSISTENT = True

有时我会收到此错误:

Traceback (most recent call last):

  File "/usr/local/lib/staging/kava/.envf322d0e225b48a1bb90126f74d73812df3b92994/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 112, in get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)

  File "/usr/local/lib/staging/kava/.envf322d0e225b48a1bb90126f74d73812df3b92994/local/lib/python2.7/site-packages/newrelic-2.18.1.15/newrelic/hooks/framework_django.py", line 492, in wrapper
    return wrapped(*args, **kwargs)

  File "/usr/local/lib/staging/kava/.envf322d0e225b48a1bb90126f74d73812df3b92994/local/lib/python2.7/site-packages/django_restapi/resource.py", line 143, in __call__
    return self.dispatch(request, self, *args, **kwargs)

  File "/usr/local/lib/staging/kava/.envf322d0e225b48a1bb90126f74d73812df3b92994/local/lib/python2.7/site-packages/django_restapi/resource.py", line 76, in dispatch
    return target.create(request, *args, **kwargs)

  File "./kavyarnya/api/post_deploy.py", line 110, in create
    process_commit.delay(project.id, commit, post_deploy_call.id)

  File "/usr/local/lib/staging/kava/.envf322d0e225b48a1bb90126f74d73812df3b92994/local/lib/python2.7/site-packages/celery/app/task.py", line 358, in delay
    return self.apply_async(args, kwargs)

  File "/usr/local/lib/staging/kava/.envf322d0e225b48a1bb90126f74d73812df3b92994/local/lib/python2.7/site-packages/celery/app/task.py", line 474, in apply_async
    **options)

  File "/usr/local/lib/staging/kava/.envf322d0e225b48a1bb90126f74d73812df3b92994/local/lib/python2.7/site-packages/celery/app/amqp.py", line 249, in publish_task
    **kwargs

  File "/usr/local/lib/staging/kava/.envf322d0e225b48a1bb90126f74d73812df3b92994/local/lib/python2.7/site-packages/kombu/messaging.py", line 164, in publish
    routing_key, mandatory, immediate, exchange, declare)

  File "/usr/local/lib/staging/kava/.envf322d0e225b48a1bb90126f74d73812df3b92994/local/lib/python2.7/site-packages/kombu/connection.py", line 470, in _ensured
    interval_max)

  File "/usr/local/lib/staging/kava/.envf322d0e225b48a1bb90126f74d73812df3b92994/local/lib/python2.7/site-packages/kombu/connection.py", line 396, in ensure_connection
    interval_start, interval_step, interval_max, callback)

  File "/usr/local/lib/staging/kava/.envf322d0e225b48a1bb90126f74d73812df3b92994/local/lib/python2.7/site-packages/kombu/utils/__init__.py", line 217, in retry_over_time
    return fun(*args, **kwargs)

  File "/usr/local/lib/staging/kava/.envf322d0e225b48a1bb90126f74d73812df3b92994/local/lib/python2.7/site-packages/kombu/connection.py", line 246, in connect
    return self.connection

  File "/usr/local/lib/staging/kava/.envf322d0e225b48a1bb90126f74d73812df3b92994/local/lib/python2.7/site-packages/kombu/connection.py", line 761, in connection
    self._connection = self._establish_connection()

  File "/usr/local/lib/staging/kava/.envf322d0e225b48a1bb90126f74d73812df3b92994/local/lib/python2.7/site-packages/kombu/connection.py", line 720, in _establish_connection
    conn = self.transport.establish_connection()

  File "/usr/local/lib/staging/kava/.envf322d0e225b48a1bb90126f74d73812df3b92994/local/lib/python2.7/site-packages/kombu/transport/pyamqp.py", line 115, in establish_connection
    conn = self.Connection(**opts)

  File "/usr/local/lib/staging/kava/.envf322d0e225b48a1bb90126f74d73812df3b92994/local/lib/python2.7/site-packages/amqp/connection.py", line 136, in __init__
    self.transport = create_transport(host, connect_timeout, ssl)

  File "/usr/local/lib/staging/kava/.envf322d0e225b48a1bb90126f74d73812df3b92994/local/lib/python2.7/site-packages/amqp/transport.py", line 264, in create_transport
    return TCPTransport(host, connect_timeout)

  File "/usr/local/lib/staging/kava/.envf322d0e225b48a1bb90126f74d73812df3b92994/local/lib/python2.7/site-packages/amqp/transport.py", line 99, in __init__
    raise socket.error(last_err)

error: timed out

RabbitMq 有默认设置。https://www.rabbitmq.com/configure.html

/etc/default/rabbitmq-server : `ulimit -n 16384`

兔子日志:

=WARNING REPORT==== 19-Mar-2016::00:02:17 ===
closing AMQP connection <0.30881.4> (127.0.0.1:26762 -> 127.0.0.1:5672):
connection_closed_abruptly

最大套接字数:

# sysctl -a | grep somax 
net.core.somaxconn = 32768

我尝试通过以下方式解决此问题:

  1. 设置 BROKER_HEARTBEAT = 10 - 我遇到了更糟糕的情况
  2. 设置 BROKER_POOL_LIMIT = None - 与当前状态相比没有任何变化
  3. 将 BOKER_CONNECTION_TIMEOUT 设置为 10、20、30 - 更大的超时值带来更少的错误

我假设增加超时值只是隐藏了真正的问题。这个问题的原因是什么,我该如何解决?谢谢

4

1 回答 1

1

您尝试处理的请求率是多少?

您能否分享在您看到超时时运行 RabbitMQ 的机器上的 CPU 利用率、内存消耗、磁盘 IO 统计数据会发生什么?

Rabbit 似乎无法足够快地处理连接。

作为盲目猜测,我建议增加 Erlang VM I/O 线程池大小(请参阅此处的“Erlang VM I/O 线程池”部分https://www.rabbitmq.com/networking.html

也许可以稍微玩一下 rabbit 的“Connection Backlog”(参见相同的链接)。

总有可能你没有足够的资源来处理你收到的请求数量,所以你可能想要扩展你的 Rabbit 安装。

于 2016-03-25T11:08:19.497 回答