Back

How to run function concurrently

  • 0
  • Functions
  • Cloud
CodingXeer01
27 Jun, 2024, 20:09

I'm trying to create faction which fetch data from database and return value according to that now I was thinking that if 20 user execute function at the same time then 20th person will get the response after the all 19th execution completed !?

TL;DR
Developers are discussing running functions concurrently. The issue seems to be related to Python not handling concurrency well compared to Node.js. Most likely, the delay in responses is due to serial execution in Python. They suggest using async execution and explaining how Appwrite Cloud can handle large amounts of concurrent executions. Real-time response is crucial for better user experience. In the provided Python code, the bcrypt key should be secured. To optimize performance, consider async execution and ensuring functions don't take long to run.
Joshi
27 Jun, 2024, 20:48

Yes. If the server is powerful you won't notice a thing

Joshi
27 Jun, 2024, 20:48

And since Appwrite cloud will spin up more containers to handle the load you really do not have to worry about that

CodingXeer01
27 Jun, 2024, 20:49

then i wonder, how could be this happened:

i tried, execute using domain and this function contains 2s of sleep and i send request using postman to execute function so it was: 2.53s 3.75s 4.52s 8.30s 11.65s

CodingXeer01
27 Jun, 2024, 20:49

i should get response in 2.53s in all

Joshi
27 Jun, 2024, 20:50

Because it runs in sync it needs to wait for the previous execution to finish before the next execution can run

Joshi
27 Jun, 2024, 20:51

If you run a function in sync you want to avoid such long function running times

CodingXeer01
27 Jun, 2024, 20:51

thne what can i do?

Joshi
27 Jun, 2024, 20:52

Is that a theoretical question or are you currently being bottlenecked by that?

Joshi
27 Jun, 2024, 20:52

Are you assuming that your function are going to take 2s to execute?

D5
27 Jun, 2024, 20:53

<@760015106947022880> But are you self-hosting?

CodingXeer01
27 Jun, 2024, 20:53

Not really but my project around 25 user it might make delayed in response my assumption

CodingXeer01
27 Jun, 2024, 20:53

Cloud

Joshi
27 Jun, 2024, 20:54

That is not because of that but rather that your users are located in india

Joshi
27 Jun, 2024, 20:54

The servers are still located in germany

Joshi
27 Jun, 2024, 20:54

I do not think that 25 can max out the function cpus

CodingXeer01
27 Jun, 2024, 20:57

the function's excution is average 500ms suppose 5 ppl are using the app at the moment then the last one will get response after 2.5s which is not really good i guess

CodingXeer01
27 Jun, 2024, 20:57

hope you are getting my point

CodingXeer01
27 Jun, 2024, 20:58

and this execution durations has big variation sometimes, 70ms/200/300 someties even 1s

Joshi
27 Jun, 2024, 20:59

What does your function do? What db operations does it use

CodingXeer01
1 Jul, 2024, 03:58

Okay, Let me test once again

Steven
1 Jul, 2024, 04:57

Execute using http? You mean the function domain?

Steven
1 Jul, 2024, 04:58

That's odd it's within 5s on self host...maybe on cloud it was cold start for all the executions

CodingXeer01
2 Jul, 2024, 05:29

Yes.

CodingXeer01
2 Jul, 2024, 05:30

i tested it, it is working perfect now !

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more