Files
2026-07-13 13:17:40 +08:00

28 lines
1.2 KiB
ReStructuredText
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
Anti-pattern: Processing results in submission order using ray.get increases runtime
====================================================================================
**TLDR:** Avoid processing independent results in submission order using :func:`ray.get() <ray.get>` since results may be ready in a different order than the submission order.
A batch of tasks is submitted, and we need to process their results individually once theyre done.
If each task takes a different amount of time to finish and we process results in submission order, we may waste time waiting for all of the slower (straggler) tasks that were submitted earlier to finish while later faster tasks have already finished.
Instead, we want to process the tasks in the order that they finish using :func:`ray.wait() <ray.wait>` to speed up total time to completion.
.. figure:: ../images/ray-get-submission-order.svg
Processing results in submission order vs completion order
Code example
------------
.. literalinclude:: ../doc_code/anti_pattern_ray_get_submission_order.py
:language: python
:start-after: __anti_pattern_start__
:end-before: __anti_pattern_end__
Other ``ray.get()`` related anti-patterns are:
- :doc:`unnecessary-ray-get`
- :doc:`ray-get-loop`