異步任務隊列:celery
celery是一個異步任務隊列/基于分布式消息傳遞的作業隊列。它側重于實時操作,但對調度支持也很好。
celery用于生產系統每天處理數以百萬計的任務。
celery是用Python編寫的,但該協議可以在任何語言實現。它也可以與其他語言通過webhooks實現。
建議的消息代理RabbitMQ的,但提供有限支持Redis, Beanstalk, MongoDB, CouchDB, ,和數據庫(使用SQLAlchemy的或Django的 ORM) 。
Celery is...
-
Simple
Celery is easy to use and maintain, and does not need configuration files.
It has an active, friendly community you can talk to for support, including a mailing-list and and an IRC channel.
Here's one of the simplest applications you can make:
from celery import Celery celery = Celery('hello', broker='amqp://guest@localhost//') @celery.task def hello(): return 'hello world'
-
Highly Available
Workers and clients will automatically retry in the event of connection loss or failure, and some brokers support HA in way of Master/Master or Master/Slave replication.
-
Fast
A single Celery process can process millions of tasks a minute, with sub-millisecond round-trip latency (using RabbitMQ, py-librabbitmq, and optimized settings).
-
Flexible
Almost every part of Celery can be extended or used on its own, Custom pool implementations, serializers, compression schemes, logging, schedulers, consumers, producers, autoscalers, broker transports and much more.
It supports...
Brokers
Concurrency
Result Stores
- AMQP, Redis
- memcached, MongoDB
- SQLAlchemy, Django ORM
- Apache Cassandra, IronCache
Serialization
- pickle, json, yaml, msgpack.
- zlib, bzip2 compression.
- Cryptographic message signing.
Framework Integration
Celery is easy to integrate with web frameworks, some of which even have integration packages:
Django django-celery Pyramid pyramid_celery Pylons celery-pylons Flask not needed web2py web2py-celery Tornado tornado-celery
The integration packages are not strictly necessary, but they can make development easier, and sometimes they add important hooks like closing database connections at fork.