worker.rst 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. .. _internals-worker:
  2. =======================
  3. Internals: The worker
  4. =======================
  5. .. contents::
  6. :local:
  7. Introduction
  8. ============
  9. The worker consists of 4 main components: the consumer, the scheduler,
  10. the mediator and the task pool. All these components runs in parallel working
  11. with two data structures: the ready queue and the ETA schedule.
  12. Data structures
  13. ===============
  14. timer
  15. -----
  16. The timer uses :mod:`heapq` to schedule internal functions.
  17. It's very efficient and can handle hundred of thousands of entries.
  18. Components
  19. ==========
  20. Consumer
  21. --------
  22. Receives messages from the broker using `Kombu`_.
  23. .. _`Kombu`: http://pypi.python.org/pypi/kombu
  24. When a message is received it's converted into a
  25. :class:`celery.worker.request.Request` object.
  26. Tasks with an ETA, or rate-limit are entered into the `timer`,
  27. messages that can be immediately processed are sent to the execution pool.
  28. Timer
  29. -----
  30. The timer schedules internal functions, like cleanup and internal monitoring,
  31. but also it schedules ETA tasks and rate limited tasks.
  32. If the scheduled tasks eta has passed it is moved to the execution pool.
  33. TaskPool
  34. --------
  35. This is a slightly modified :class:`multiprocessing.Pool`.
  36. It mostly works the same way, except it makes sure all of the workers
  37. are running at all times. If a worker is missing, it replaces
  38. it with a new one.