worker.rst 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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 when used together will result in the rate limit being
  28. observed with the task being scheduled after the ETA.
  29. Timer
  30. -----
  31. The timer schedules internal functions, like cleanup and internal monitoring,
  32. but also it schedules ETA tasks and rate limited tasks.
  33. If the scheduled tasks ETA has passed it is moved to the execution pool.
  34. TaskPool
  35. --------
  36. This is a slightly modified :class:`multiprocessing.Pool`.
  37. It mostly works the same way, except it makes sure all of the workers
  38. are running at all times. If a worker is missing, it replaces
  39. it with a new one.