eventlet.rst 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. .. _concurrency-eventlet:
  2. ===========================
  3. Concurrency with Eventlet
  4. ===========================
  5. .. _eventlet-introduction:
  6. Introduction
  7. ============
  8. The `Eventlet`_ homepage describes eventlet as,
  9. a concurrent networking library for Python that allows you to
  10. change how you run your code, not how you write it.
  11. * It uses epoll or libevent for `highly scalable non-blocking I/O`_.
  12. * `Coroutines`_ ensure that the developer uses a blocking style of
  13. programming that is similar to threading, but provide the benefits of
  14. non-blocking I/O.
  15. * The event dispatch is implicit, which means you can easily use Eventlet
  16. from the Python interpreter, or as a small part of a larger application.
  17. Celery supports Eventlet as an alternative execution pool implementation.
  18. It is in some cases superior to multiprocessing, but you need to ensure
  19. your tasks do not perform any blocking calls, as this will halt all
  20. other operations in the worker.
  21. The multiprocessing pool can take use of many processes, but it is often
  22. limited to a few processes per CPU. With eventlet you can efficiently spawn
  23. hundreds of concurrent couroutines. In an informal test with a feed hub
  24. system the Eventlet pool could fetch and process hundreds of feeds every
  25. second, while the multiprocessing pool spent 14 seconds processing 100 feeds.
  26. But this is exactly the kind of application evented I/O is good for.
  27. You may want a a mix of both eventlet and multiprocessing workers,
  28. depending on the needs of your tasks.
  29. Enabling Eventlet
  30. =================
  31. You can enable the Eventlet pool by using the `-P` option to
  32. :program:`celeryd`::
  33. $ celeryd -P eventlet -c 1000
  34. .. _eventlet-examples:
  35. Examples
  36. ========
  37. See the `Eventlet examples`_ directory in the Celery distribution for
  38. some examples taking use of Eventlet support.
  39. .. _`Eventlet`: http://eventlet.net
  40. .. _`highly scalable non-blocking I/O`:
  41. http://en.wikipedia.org/wiki/Asynchronous_I/O#Select.28.2Fpoll.29_loops
  42. .. _`Coroutines`: http://en.wikipedia.org/wiki/Coroutine
  43. .. _`Eventlet examples`:
  44. https://github.com/ask/celery/tree/master/examples/eventlet