Hi, I have a very small flow (visualization attach...
# ask-community
e
Hi, I have a very small flow (visualization attached) but the execution of this flow tasks around 6 seconds, for only 1 record Why is it so slow? can I make it faster somehow?
pipeline.fire_and_forget
runs
client.create_flow_run
this part takes 100ms, the majority of the time is while waiting
a
Since you trigger it to run remotely via API call, it generates an additional overhead. What would be faster would be running it directly locally - this way, you don’t need to make the API call, which reduces latency:
Copy code
flow.run()
Overall, this is what is recommended for running flows locally. Running it via API call is something what you would typically do when the flow is already deployed. I believe, this is not what you are interested in doing because you trigger all flows from the API somehow, correct?
e
i can’t run
flow.run()
because it is blocks the main thread and I can’t do that
a
Yeah I remember 🙂 in which region do you run your flows? and just to confirm: do you run it with Prefect Cloud or Server? Perhaps you could reduce the latency a bit by running it in the same region as Prefect Cloud API - I would have to ask the team about that.
e
this is all local right now, will it run faster on the cloud?
a
With local you mean Server? It could be, Cloud has performance enhancements that a single Server instance doesn't have. Which region would your agent be running in?
e
i run it all local on my mac. both server and agents
a
But do you ever plan to deploy it somewhere to run in a production setting? Anyway, coming back to the original problem you reported, I'm not sure what else to recommend other than what was already mentioned: trying to run without backend or try to achieve a closer regional distance between the backend API (e g. Prefect Cloud) and the execution layer.
k
No it will be slower on the Cloud because the API calls you are doing when they are all on the same machine don’t pass through a network. But with Prefect Cloud, they will so there will be some added overhead. This added overhead is fixed of course and will only be noticeable for tasks that are meant to run super quickly. For tasks that are a bit longer, it should be less noticeable.
e
fixed when?
k
Not fixed as in there is something broken. Fixed as in constant overhead.
e
ha got it. I need to run the my flow very quickly and get a response and waiting for a flow run dosen’t seems like a good solution because it is very very slow another approche is to save the flow to a pickle file and load it before running. it runs much faster. but that way I have 2 ways of running the same flow and it is pretty suck
this is the how I run the my env
Copy code
prefect server start
prefect agent local start
this is the optimal way?
a
@Eric Feldman correct, this is how you would normally start Prefect Server and a local agent.
e
tried to use local agent on my mac and the server of the cloud prefect, took 10 second as well
k
I think there is nothing left to optimize here for current Prefect. Orion aims to reduce overhead but for current Prefect, I don’t think there is a way to reduce that latency. Server and agent on local will already be the fastest. I think the lower bound for Prefect flows to be performant is 1 minute (maybe 30 seconds)
upvote 1