| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 | .. _optimizing:============ Optimizing============Introduction============The default configuration, like any good default, is full of compromises.It is not tweaked to be optimal for any single use case, but tries tofind middle ground that works *well enough* for most situations.There are key optimizations to be done if your application is mainlyprocessing lots of short tasks, and also if you have fewer but verylong tasks... _optimizing-worker-settings:Worker Settings===============.. _optimizing-prefetch-limit:Prefetch limit--------------*Prefetch* is a term inherited from AMQP, and it is often misunderstood.The prefetch limit is a limit for how many tasks a worker can reservein advance.  If this is set to zero, the worker will keep consumingmessages *ad infinitum*, not respecting that there may be otheravailable worker nodes (that may be able to process them sooner),or that the messages may not fit in memory.The workers initial prefetch count is set by multiplyingthe :setting:`CELERYD_PREFETCH_MULTIPLIER` setting by the numberof child worker processes.  The default is 4 messages per child process.If you have many expensive tasks with a long duration you would wantthe multiplier value to be 1, which means it will only reserve oneunacknowledged task per worker process at a time.However -- If you have lots of short tasks, and throughput/roundtrip latencyis important to you, then you want this number to be large.  Say 64, or 128for example, as the worker is able to process a lot more tasks/s if themessages have already been prefetched in memory.  You may have to experimentto find the best value.If you have a combination of both very long and short tasks, then the bestoption is to use two worker nodes that is configured individually, and routethe tasks accordingly (see :ref:`guide-routing`).Scenario 1: Lots of short tasks===============================.. code-block:: python    CELERYD_PREFETCH_MULTIPLIER = 128    CELERY_DISABLE_RATE_LIMITS = TrueScenario 2: Expensive tasks===========================.. code-block:: python    CELERYD_PREFETCH_MULTIPLIER = 1
 |