introduction.txt 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. :Version: 1.0.0-pre1
  2. :Keywords: task queue, job queue, asynchronous, rabbitmq, amqp, redis,
  3. django, python, webhooks, queue, distributed
  4. --
  5. Celery is a task queue/job queue based on distributed message passing.
  6. It is focused on real-time operation, but has support for scheduling as well.
  7. The execution units, called tasks, are executed concurrently on one or more
  8. worker servers, asynchronously (in the background) or synchronously
  9. (wait until ready).
  10. Celery is already used in production to process millions of tasks a day.
  11. It was first created for Django, but is now usable from Python as well.
  12. It can also `operate with other languages via HTTP+JSON`_.
  13. .. _`operate with other languages via HTTP+JSON`: http://bit.ly/CgXSc
  14. Overview
  15. ========
  16. This is a high level overview of the architecture.
  17. .. image:: http://cloud.github.com/downloads/ask/celery/Celery-Overview-v4.jpg
  18. The broker pushes tasks to the worker servers.
  19. A worker server is a networked machine running ``celeryd``. This can be one or
  20. more machines, depending on the workload.
  21. The result of the task can be stored for later retrieval (called its
  22. "tombstone").
  23. Example
  24. =======
  25. You probably want to see some code by now, so I'll give you an example task
  26. adding two numbers:
  27. .. code-block:: python
  28. from celery.decorators import task
  29. @task
  30. def add(x, y):
  31. return x + y
  32. You can execute the task in the background, or wait for it to finish::
  33. >>> result = add.delay(4, 4)
  34. >>> result.wait() # wait for and return the result
  35. 8
  36. Simple!
  37. Features
  38. ========
  39. +-----------------+----------------------------------------------------+
  40. | Messaging | Supported brokers include `RabbitMQ`_, `Stomp`_, |
  41. | | `Redis`_, and the most common SQL databases. |
  42. +-----------------+----------------------------------------------------+
  43. | Robust | Using `RabbitMQ`, celery survives most error |
  44. | | scenarios, and your tasks will never be lost. |
  45. +-----------------+----------------------------------------------------+
  46. | Distributed | Runs on one or more machines. Supports |
  47. | | `clustering`_ when used in combination with |
  48. | | `RabbitMQ`_. You can set up new workers without |
  49. | | central configuration (e.g. use your dads laptop |
  50. | | while the queue is temporarily overloaded). |
  51. +-----------------+----------------------------------------------------+
  52. | Concurrency | Tasks are executed in parallel using the |
  53. | | :mod:`multiprocessing` module. |
  54. +-----------------+----------------------------------------------------+
  55. | Scheduling | Supports recurring tasks like cron, or specifying |
  56. | | an exact date or countdown for when after the task |
  57. | | should be executed. |
  58. +-----------------+----------------------------------------------------+
  59. | Performance | Able to execute tasks while the user waits. |
  60. +-----------------+----------------------------------------------------+
  61. | Return Values | Task return values can be saved to the selected |
  62. | | result store backend. You can wait for the result, |
  63. | | retrieve it later, or ignore it. |
  64. +-----------------+----------------------------------------------------+
  65. | Result Stores | Database, `MongoDB`_, `Redis`_, `Tokyo Tyrant`, |
  66. | | `AMQP`_ (high performance). |
  67. +-----------------+----------------------------------------------------+
  68. | Webhooks | Your tasks can also be HTTP callbacks, enabling |
  69. | | cross-language communication. |
  70. +-----------------+----------------------------------------------------+
  71. | Rate limiting | Supports rate limiting by using the token bucket |
  72. | | algorithm, which accounts for bursts of traffic. |
  73. | | Rate limits can be set for each task type, or |
  74. | | globally for all. |
  75. +-----------------+----------------------------------------------------+
  76. | Routing | Using AMQP you can route tasks arbitrarily to |
  77. | | different workers. |
  78. +-----------------+----------------------------------------------------+
  79. | Remote-control | You can rate limit and delete (revoke) tasks |
  80. | | remotely. |
  81. +-----------------+----------------------------------------------------+
  82. | Monitoring | You can capture everything happening with the |
  83. | | workers in real-time by subscribing to events. |
  84. | | A real-time web monitor is in development. |
  85. +-----------------+----------------------------------------------------+
  86. | Serialization | Supports Pickle, JSON, YAML, or easily defined |
  87. | | custom schemes. One task invocation can have a |
  88. | | different scheme than another. |
  89. +-----------------+----------------------------------------------------+
  90. | Tracebacks | Errors and tracebacks are stored and can be |
  91. | | investigated after the fact. |
  92. +-----------------+----------------------------------------------------+
  93. | UUID | Every task has an UUID (Universally Unique |
  94. | | Identifier), which is the task id used to query |
  95. | | task status and return value. |
  96. +-----------------+----------------------------------------------------+
  97. | Retries | Tasks can be retried if they fail, with |
  98. | | configurable maximum number of retries, and delays |
  99. | | between each retry. |
  100. +-----------------+----------------------------------------------------+
  101. | Task Sets | A Task set is a task consisting of several |
  102. | | sub-tasks. You can find out how many, or if all |
  103. | | of the sub-tasks has been executed, and even |
  104. | | retrieve the results in order. Progress bars, |
  105. | | anyone? |
  106. +-----------------+----------------------------------------------------+
  107. | Made for Web | You can query status and results via URLs, |
  108. | | enabling the ability to poll task status using |
  109. | | Ajax. |
  110. +-----------------+----------------------------------------------------+
  111. | Error e-mails | Can be configured to send e-mails to the |
  112. | | administrators when tasks fails. |
  113. +-----------------+----------------------------------------------------+
  114. | Supervised | Pool workers are supervised and automatically |
  115. | | replaced if they crash. |
  116. +-----------------+----------------------------------------------------+
  117. .. _`RabbitMQ`: http://www.rabbitmq.com/
  118. .. _`clustering`: http://www.rabbitmq.com/clustering.html
  119. .. _`AMQP`: http://www.amqp.org/
  120. .. _`Stomp`: http://stomp.codehaus.org/
  121. .. _`MongoDB`: http://www.mongodb.org/
  122. .. _`Redis`: http://code.google.com/p/redis/
  123. .. _`Tokyo Tyrant`: http://tokyocabinet.sourceforge.net/
  124. Documentation
  125. =============
  126. The `latest documentation`_ with user guides, tutorials and API reference
  127. is hosted at Github.
  128. .. _`latest documentation`: http://ask.github.com/celery/
  129. Installation
  130. =============
  131. You can install ``celery`` either via the Python Package Index (PyPI)
  132. or from source.
  133. To install using ``pip``,::
  134. $ pip install celery
  135. To install using ``easy_install``,::
  136. $ easy_install celery
  137. Downloading and installing from source
  138. --------------------------------------
  139. Download the latest version of ``celery`` from
  140. http://pypi.python.org/pypi/celery/
  141. You can install it by doing the following,::
  142. $ tar xvfz celery-0.0.0.tar.gz
  143. $ cd celery-0.0.0
  144. $ python setup.py build
  145. # python setup.py install # as root
  146. Using the development version
  147. ------------------------------
  148. You can clone the repository by doing the following::
  149. $ git clone git://github.com/ask/celery.git