worker.rst 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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 :pypi:`Kombu`.
  23. When a message is received it's converted into a
  24. :class:`celery.worker.request.Request` object.
  25. Tasks with an ETA, or rate-limit are entered into the `timer`,
  26. messages that can be immediately processed are sent to the execution pool.
  27. ETA and rate-limit are 2 incompatible parameters, and the ETA is overriding
  28. the rate-limit by default. A task with both will follow its ETA and ignore its
  29. rate-limit.
  30. Timer
  31. -----
  32. The timer schedules internal functions, like cleanup and internal monitoring,
  33. but also it schedules ETA tasks and rate limited tasks.
  34. If the scheduled tasks ETA has passed it is moved to the execution pool.
  35. TaskPool
  36. --------
  37. This is a slightly modified :class:`multiprocessing.Pool`.
  38. It mostly works the same way, except it makes sure all of the workers
  39. are running at all times. If a worker is missing, it replaces
  40. it with a new one.