introduction.rst 11 KB

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