Narasimhan Ramaswamy

10/25/2020, 10:04 PM
Copy code
from prefect import task, case, apply_map,Flow,unmapped
import prefect
from prefect.tasks.control_flow import merge
from import ShellTask
from prefect.engine.results import LocalResult
from prefect.tasks.control_flow import case
from import Docker
import docker 

def test2(name):
    logger = prefect.context.get("logger")
    <|>("Inside Task 2")
    a = ShellTask(name=name, command="ls", return_all=True, log_stderr=True)
    return a

def inc_if_even(x):
    logger = prefect.context.get("logger")

    name = r'Shell' + str(x)
    b = test2(name).run()
    return 1

def reduce(x):
    z = sum(x)
    if z > 1:
        return True
        return False

def return_num(x):
    return x + 10

def logger_st(status):
    logger = prefect.context.get("logger")
    <|>(f"Task Failed - {status}")
    return 1

from prefect.engine.executors import DaskExecutor,LocalDaskExecutor
from prefect.environments import LocalEnvironment

with Flow("test-flow",environment=LocalEnvironment(executor=DaskExecutor())) as flow:
    logger = prefect.context.get("logger")
    return_nums =[1,2,3,4,5,6,7])
    result =
    reduced = reduce(result)
Hi All, just a quick question on DaskExecutor() - when running using, the mapped tasks works in parallel. but when running on cloud, it runs in sequence. My setup is agent running on Kubernetes. can you please help on what i should be doing?
👀 2

Jimmy Le

11/08/2020, 4:57 PM
@Narasimhan Ramaswamy I ran into a similar problem. I was able to run the flows in parallel locally, but when running on the cloud, it was running in serial. By setting the executor in my environment, I was able to achieve parallel flow running on the cloud. Now my computer is a space heater 🔥
Copy code
with Flow("flow name", schedule=schedule) as f:
    # mapped flow

# set flow label
f.environment = LocalEnvironment(labels=["flow-label"], executor=LocalDaskExecutor())

# set flow storage = Local(

Narasimhan Ramaswamy

11/16/2020, 11:24 AM
thanks @Jimmy Le - i was able to make it work in cloud as well. What worked well was KubernetesDaskEnvironment - it was more faster than the localdaskexecutor.KubernetesDaskEnvironment creates its own workers with separate cpu and memory - it helped the jobs run quite faster.
🙌 1