Celery 实战指南

Celery 是

一个简单、灵活和可靠的分布式系统框架,多用作跨进程、多机器协同工作的场景。

场景

如何控制不预取

命令行增加 -O fair 配置文件supervisor中增加

;Late ack means the task messages will be acknowledged after the task has been executed, not just before (the default behavior).
task_acks_late = True
;How many messages to prefetch at a time multiplied by the number of concurrent processes. The default is 4 (four messages for each process). The default setting is usually a good choice, however – if you have very long running tasks waiting in the queue and you have to start the workers, note that the first worker to start will receive four times the number of messages initially. Thus the tasks may not be fairly distributed to the workers.
;To disable prefetching, set worker_prefetch_multiplier to 1. Changing that setting to 0 will allow the worker to keep consuming as many messages as it wants.
worker_prefetch_multiplier = 1

实际在使用时发现后面的无效,可以在命令行中直接写入 prefetch_multiplier=1

Celery 使用 阿里云 RabbitMQ 作为 Broker

阿里云的 RabbitMQ 只支持 PLAIN 认证; 强迫celery使用broker_login_method='PLAIN'

版本

Celery 4.4.0 官网介绍

特性

简单

Celery 使用非常简单,甚至可以无需配置文件。

from celery import Celery

app = Celery('hello', broker='amqp://guest@localhost//')

@app.task
def hello():
    return 'hello world'

高可用

Workers 和 Clients 遇到丢失连接或者连接失败时会自动重试。

快速

单个 Celery 进程每分钟可以处理数百万个任务,具有亚毫秒的往返延迟(使用RabbitMQ、librabbitmq并且优化设置)。

灵活

高度灵活,几乎所有模块都可自定义扩展使用。

支持

Brokers

Concurrency (并发)

Result Stores (任务结果存储)

Serialization (序列化)

Monitoring (监控)

Work-flows(工作流)

Time & Rate Limits (限流)

Scheduling (定时任务调度)

Resource Leak Protection(资源泄露保护)

User Components (用户自定义组件)

任务状态

结果说明
PENDING没有执行 or 状态未知
RECEIVED已接收
STARTED已启动
SUCCESS成功
FAILURE失败
REVOKED已撤销
REJECTED被拒绝
RETRY重试中
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

勤奋的利昂

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值