Hey everyone! Just wanted to share something I fo...
# data-tricks-and-tips
k
Hey everyone! Just wanted to share something I found interesting. When submitting many
async
tasks, either via
.submit
or
.map
, I've found that using a
SequentialTaskRunner
causes the flow to run much faster than using
ConcurrentTaskRunner
. I'd like to know more about this behavior. Any feedback is appreciated!
p
Interesting! I'll give it a look in just a sec and see what's going on there. The
SequentialTaskRunner
currently submits asynchronously, not sequentially, on map. That's going to be changed soon. But I don't know why it would be faster
1
Do you have an example of the async tasks running faster using
.submit
? I can't reproduce this
k
Hey @Peyton Runyan I mean to say that the same flow code, which has
async
tasks with
.submit
or
.map
, seems to be faster when using a
SequentialTaskRunner
instead of the default.
Copy code
@task(
    name="Greet",
    task_run_name="{name}",
)
async def greet(name: str) -> str:
    message = f"Hello, {name}!"

    await asyncio.sleep(2)

    print(message)

    return message

@flow(
    name="Multi Greeter",
    task_runner=SequentialTaskRunner(),
)
async def multi_greeter():
    names = [
        "Kelvin",
        "Peyton",
    ]
    
    message_states = await greet.map(name=names, return_state=True)

    messages = await asyncio.gather(
        *[state.result(fetch=True) for state in message_states if state.is_completed()]
    )
Copy code
@flow(name="Main")
def main():
    multi_greeter()

if __name__ == "__main__":
    main()
Running this locally, with and without
SequentialTaskRunner
, produces runs with different run durations. Adding more
names
makes this difference larger
j