Parcourir la source

Optimizing guide: Section on transient queues

Ask Solem il y a 11 ans
Parent
commit
6177c5f7e6

+ 2 - 0
celery/task/__init__.py

@@ -15,6 +15,8 @@ from celery._state import current_app, current_task as current
 from celery.five import MagicModule, recreate_module
 from celery.local import Proxy
 
+print("IMPORTING TASK")
+
 __all__ = [
     'BaseTask', 'Task', 'PeriodicTask', 'task', 'periodic_task',
     'group', 'chord', 'subtask', 'TaskSet',

+ 3 - 0
celery/tests/compat_modules/test_compat.py

@@ -2,6 +2,9 @@ from __future__ import absolute_import
 
 from datetime import timedelta
 
+import sys
+sys.modules.pop('celery.task', None)
+
 from celery.schedules import schedule
 from celery.task import (
     periodic_task,

+ 37 - 0
docs/userguide/optimizing.rst

@@ -79,6 +79,43 @@ You can tweak the :setting:`BROKER_POOL_LIMIT` setting to minimize
 contention, and the value should be based on the number of
 active threads/greenthreads using broker connections.
 
+.. _optimizing-transient-queues:
+
+Using Transient Queues
+----------------------
+
+Queues created by Celery are persistent by default.  This means that
+the broker will write messages to disk to ensure that the tasks will
+be executed even if the broker is restarted.
+
+But in some cases it's fine that the message is lost, so not all tasks
+require durability.  You can create a *transient* queue for these tasks
+to improve performance:
+
+.. code-block:: python
+
+    from kombu import Exchange, Queue
+
+    CELERY_QUEUES = (
+        Queue('celery', routing_key='celery'),
+        Queue('transient', routing_key='transient',
+              delivery_mode=1),
+    )
+
+
+The ``delivery_mode`` changes how the messages to this queue are delivered.
+A value of 1 means that the message will not be written to disk, and a value
+of 2 (default) means that the message can be written to disk.
+
+To direct a task to your new transient queue you can specify the queue
+argument (or use the :setting:`CELERY_ROUTES` setting):
+
+.. code-block:: python
+
+    task.apply_async(args, queue='transient')
+
+For more information see the :ref:`routing guide <guide-routing>`.
+
 .. _optimizing-worker-settings:
 
 Worker Settings