Back

Cloud function execution is too slow due to database operations

  • 0
  • Databases
  • Functions
  • Cloud
anmot.
11 Dec, 2023, 19:04

Database read / write operations are very slow when running on cloud functions (appwrite cloud). Each operation takes 2-3 seconds and overall function execution takea around 3-6 seconds.

  1. Function execution
TypeScript
{"startTime":"Mon Dec 11 2023 18:45:30 GMT+0000 (Coordinated Universal Time)"}
[[1] get document by id] "1462.120"
[[4] create document in db] "2804.059"
function duration: 4854.733 ms
{"executionTime":4853,"endTime":"Mon Dec 11 2023 18:45:34 GMT+0000 (Coordinated Universal Time)"}
  1. Function execution
TypeScript
{"startTime":"Mon Dec 11 2023 18:51:11 GMT+0000 (Coordinated Universal Time)"}
[[2] third party API call] "148.158"
[[3] create document in db] "994.708"
[[4] create document in db] "2002.438"
function duration: 3776.766 
{"executionTime":3776,"endTime":"Mon Dec 11 2023 18:51:15 GMT+0000 (Coordinated Universal Time)"}

3.Function execution

TypeScript
{"startTime":"Mon Dec 11 2023 18:53:26 GMT+0000 (Coordinated Universal Time)"}
[[2] third party API call] "121.156"
[[3] create document in db] "1284.590"
[[4] create document in db] "2619.728"
function duration: 4729.293 
{"executionTime":4729,"endTime":"Mon Dec 11 2023 18:53:30 GMT+0000 (Coordinated Universal Time)"}
TL;DR
The execution of cloud functions is taking too long due to slow database operations. Creating a document without relationships takes around 300-400 ms per write operation. Creating child documents and parent documents with child document reference also have long durations. The function execution time ranges from 3-6 seconds. Solution: To improve the performance, optimize the database operations and consider using relationships more efficiently. Additionally, upgrading to the Pro plan may help reduce operation times.
Drake
11 Dec, 2023, 22:41

Do you use relationships?

anmot.
11 Dec, 2023, 22:46

Yes.

Below durations are for creating child documents [[3] create document in db] "994.708" [[3] create document in db] "1284.590"

Below duration are for creating parent document with child document reference (not nested syntax) [[4] create document in db] "2804.059" [[4] create document in db] "2002.438" [[4] create document in db] "2619.728"

Below duration is for getting the child document [[1] get document by id] "1462.120"

Drake
11 Dec, 2023, 22:49

ya...relationships can slow things down a bit..

anmot.
11 Dec, 2023, 23:24

Creating a document without relationship takes 300~400 ms for each write operation. Is this consistent with the benchmarks or expectations you have observed?

[PostService::[0] create document in db with no relations] "384.234" [PostService::[5] create document in db with no relations] "306.835"

Drake
11 Dec, 2023, 23:37

hmmmm possibly yes...

anmot.
12 Dec, 2023, 01:07

Is it possible that the upcoming Pro plan could reduce these operation times?

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