introduction.rst 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. .. _intro:
  2. ========================
  3. Introduction to Celery
  4. ========================
  5. .. contents::
  6. :local:
  7. :depth: 1
  8. What is a Task Queue?
  9. =====================
  10. Task queues are used as a mechanism to distribute work across threads or
  11. machines.
  12. A task queue's input is a unit of work called a task. Dedicated worker
  13. processes constantly monitor task queues for new work to perform.
  14. Celery communicates via messages, usually using a broker
  15. to mediate between clients and workers. To initiate a task, a client adds a
  16. message to the queue, which the broker then delivers to a worker.
  17. A Celery system can consist of multiple workers and brokers, giving way
  18. to high availability and horizontal scaling.
  19. Celery is written in Python, but the protocol can be implemented in any
  20. language. In addition to Python there's node-celery_ for Node.js,
  21. and a `PHP client`_.
  22. Language interoperability can also be achieved
  23. by :ref:`using webhooks <guide-webhooks>`.
  24. .. _`PHP client`: https://github.com/gjedeer/celery-php
  25. .. _node-celery: https://github.com/mher/node-celery
  26. What do I need?
  27. ===============
  28. .. sidebar:: Version Requirements
  29. :subtitle: Celery version 4.0 runs on
  30. - Python ❨2.7, 3.4, 3.5❩
  31. - PyPy ❨5.1, 2.4❩
  32. This is the last version to support Python 2.7,
  33. and from the next version (Celery 5.x) Python 3.6 or newer is required.
  34. If you are running an older version of Python, you need to be running
  35. an older version of Celery:
  36. - Python 2.6: Celery series 3.1 or earlier.
  37. - Python 2.5: Celery series 3.0 or earlier.
  38. - Python 2.4 was Celery series 2.2 or earlier.
  39. Celery is a project with minimal funding,
  40. so we do not support Microsoft Windows.
  41. Please do not open any issues related to that platform.
  42. *Celery* requires a message transport to send and receive messages.
  43. The RabbitMQ broker transport is feature complete,
  44. but there's also support for SQS and Apache Qpid.
  45. *Celery* can run on a single machine, on multiple machines, or even
  46. across data centers.
  47. Get Started
  48. ===========
  49. If this is the first time you're trying to use Celery, or if you haven't
  50. kept up with development in the 3.1 version and are coming from previous versions,
  51. then you should read our getting started tutorials:
  52. - :ref:`first-steps`
  53. - :ref:`next-steps`
  54. Celery is…
  55. ==========
  56. .. _`mailing-list`: http://groups.google.com/group/celery-users
  57. .. topic:: \
  58. - **Simple**
  59. Celery is easy to use and maintain, and it *doesn't need configuration files*.
  60. It has an active, friendly community you can talk to for support,
  61. including a `mailing-list`_ and an :ref:`IRC channel <irc-channel>`.
  62. Here's one of the simplest applications you can make:
  63. .. code-block:: python
  64. from celery import Celery
  65. app = Celery('hello', broker='amqp://guest@localhost//')
  66. @app.task
  67. def hello():
  68. return 'hello world'
  69. - **Highly Available**
  70. Workers and clients will automatically retry in the event
  71. of connection loss or failure, and some brokers support
  72. HA in way of *Master/Master* or *Master/Slave* replication.
  73. - **Fast**
  74. A single Celery process can process millions of tasks a minute,
  75. with sub-millisecond round-trip latency (using RabbitMQ,
  76. librabbitmq, and optimized settings).
  77. - **Flexible**
  78. Almost every part of *Celery* can be extended or used on its own,
  79. Custom pool implementations, serializers, compression schemes, logging,
  80. schedulers, consumers, producers, broker transports and much more.
  81. .. topic:: It supports
  82. .. hlist::
  83. :columns: 2
  84. - **Brokers**
  85. - :ref:`RabbitMQ <broker-rabbitmq>`
  86. - :ref:`Amazon SQS <broker-sqs>` and more…
  87. - **Concurrency**
  88. - prefork (multiprocessing),
  89. - Eventlet_, gevent_
  90. - `solo` (single threaded)
  91. - **Result Stores**
  92. - AMQP, Redis
  93. - Memcached,
  94. - SQLAlchemy, Django ORM
  95. - Apache Cassandra, Elasticsearch
  96. - **Serialization**
  97. - *pickle*, *json*, *yaml*, *msgpack*.
  98. - *zlib*, *bzip2* compression.
  99. - Cryptographic message signing.
  100. Features
  101. ========
  102. .. topic:: \
  103. .. hlist::
  104. :columns: 2
  105. - **Monitoring**
  106. A stream of monitoring events is emitted by workers and
  107. is used by built-in and external tools to tell you what
  108. your cluster is doing -- in real-time.
  109. :ref:`Read more… <guide-monitoring>`.
  110. - **Work-flows**
  111. Simple and complex work-flows can be composed using
  112. a set of powerful primitives we call the "canvas",
  113. including grouping, chaining, chunking and more.
  114. :ref:`Read more… <guide-canvas>`.
  115. - **Time & Rate Limits**
  116. You can control how many tasks can be executed per second/minute/hour,
  117. or how long a task can be allowed to run, and this can be set as
  118. a default, for a specific worker or individually for each task type.
  119. :ref:`Read more… <worker-time-limits>`.
  120. - **Scheduling**
  121. You can specify the time to run a task in seconds or a
  122. :class:`~datetime.datetime`, or or you can use
  123. periodic tasks for recurring events based on a
  124. simple interval, or Crontab expressions
  125. supporting minute, hour, day of week, day of month, and
  126. month of year.
  127. :ref:`Read more… <guide-beat>`.
  128. - **Resource Leak Protection**
  129. The :option:`--maxtasksperchild <celery worker --maxtasksperchild>`
  130. option is used for user tasks leaking resources, like memory or
  131. file descriptors, that are simply out of your control.
  132. :ref:`Read more… <worker-maxtasksperchild>`.
  133. - **User Components**
  134. Each worker component can be customized, and additional components
  135. can be defined by the user. The worker is built up using "bootsteps" — a
  136. dependency graph enabling fine grained control of the worker's
  137. internals.
  138. .. _`Eventlet`: http://eventlet.net/
  139. .. _`gevent`: http://gevent.org/
  140. Framework Integration
  141. =====================
  142. Celery is easy to integrate with web frameworks, some of which even have
  143. integration packages:
  144. +--------------------+------------------------+
  145. | `Django`_ | `django-celery`_ |
  146. +--------------------+------------------------+
  147. | `Pyramid`_ | `pyramid_celery`_ |
  148. +--------------------+------------------------+
  149. | `Pylons`_ | `celery-pylons`_ |
  150. +--------------------+------------------------+
  151. | `Flask`_ | not needed |
  152. +--------------------+------------------------+
  153. | `web2py`_ | `web2py-celery`_ |
  154. +--------------------+------------------------+
  155. | `Tornado`_ | `tornado-celery`_ |
  156. +--------------------+------------------------+
  157. The integration packages are not strictly necessary, but they can make
  158. development easier, and sometimes they add important hooks like closing
  159. database connections at :manpage:`fork(2)`.
  160. .. _`Django`: http://djangoproject.com/
  161. .. _`Pylons`: http://pylonshq.com/
  162. .. _`Flask`: http://flask.pocoo.org/
  163. .. _`web2py`: http://web2py.com/
  164. .. _`Bottle`: http://bottlepy.org/
  165. .. _`Pyramid`: http://docs.pylonsproject.org/en/latest/docs/pyramid.html
  166. .. _`pyramid_celery`: http://pypi.python.org/pypi/pyramid_celery/
  167. .. _`django-celery`: http://pypi.python.org/pypi/django-celery
  168. .. _`celery-pylons`: http://pypi.python.org/pypi/celery-pylons
  169. .. _`web2py-celery`: http://code.google.com/p/web2py-celery/
  170. .. _`Tornado`: http://www.tornadoweb.org/
  171. .. _`tornado-celery`: https://github.com/mher/tornado-celery/
  172. Quick Jump
  173. ==========
  174. .. topic:: I want to ⟶
  175. .. hlist::
  176. :columns: 2
  177. - :ref:`get the return value of a task <task-states>`
  178. - :ref:`use logging from my task <task-logging>`
  179. - :ref:`learn about best practices <task-best-practices>`
  180. - :ref:`create a custom task base class <task-custom-classes>`
  181. - :ref:`add a callback to a group of tasks <canvas-chord>`
  182. - :ref:`split a task into several chunks <canvas-chunks>`
  183. - :ref:`optimize the worker <guide-optimizing>`
  184. - :ref:`see a list of built-in task states <task-builtin-states>`
  185. - :ref:`create custom task states <custom-states>`
  186. - :ref:`set a custom task name <task-names>`
  187. - :ref:`track when a task starts <task-track-started>`
  188. - :ref:`retry a task when it fails <task-retry>`
  189. - :ref:`get the id of the current task <task-request-info>`
  190. - :ref:`know what queue a task was delivered to <task-request-info>`
  191. - :ref:`see a list of running workers <monitoring-control>`
  192. - :ref:`purge all messages <monitoring-control>`
  193. - :ref:`inspect what the workers are doing <monitoring-control>`
  194. - :ref:`see what tasks a worker has registered <monitoring-control>`
  195. - :ref:`migrate tasks to a new broker <monitoring-control>`
  196. - :ref:`see a list of event message types <event-reference>`
  197. - :ref:`contribute to Celery <contributing>`
  198. - :ref:`learn about available configuration settings <configuration>`
  199. - :ref:`get a list of people and companies using Celery <res-using-celery>`
  200. - :ref:`write my own remote control command <worker-custom-control-commands>`
  201. - :ref:`change worker queues at runtime <worker-queues>`
  202. .. topic:: Jump to ⟶
  203. .. hlist::
  204. :columns: 4
  205. - :ref:`Brokers <brokers>`
  206. - :ref:`Applications <guide-app>`
  207. - :ref:`Tasks <guide-tasks>`
  208. - :ref:`Calling <guide-calling>`
  209. - :ref:`Workers <guide-workers>`
  210. - :ref:`Daemonizing <daemonizing>`
  211. - :ref:`Monitoring <guide-monitoring>`
  212. - :ref:`Optimizing <guide-optimizing>`
  213. - :ref:`Security <guide-security>`
  214. - :ref:`Routing <guide-routing>`
  215. - :ref:`Configuration <configuration>`
  216. - :ref:`Django <django>`
  217. - :ref:`Contributing <contributing>`
  218. - :ref:`Signals <signals>`
  219. - :ref:`FAQ <faq>`
  220. - :ref:`API Reference <apiref>`
  221. .. include:: ../includes/installation.txt