Back

Functions Design

  • 4
  • Self Hosted
  • Functions
Nour
27 Nov, 2023, 10:20

I have a function that can handle 30 synchronous requests simultaneously. However, I’ve noticed that the worker function processes these requests sequentially, similar to a single thread handling multiple tasks by serving them partially. This method increases the total execution time and leads to uneven completion times for some calls. On the other hand, if I duplicate the same function across multiple deployments and distribute the calls among them, it could significantly reduce the execution time. In other words, creating multiple threads to handle the calls. However, this would involve duplicating the same function across multiple deployments. Is this second option the better choice?

Is there anything I can do to make the worker function execute as multi-threaded?

I attempted to double the _APP_WORKER_PER_CORE, but it didn’t result in any improvement. Any advice would be appreciated.

TL;DR
The user is trying to find a way to execute their functions in a multi-threaded manner in the context of the Appwrite platform. They have tested executing multiple calls simultaneously, but the execution time becomes uneven and slower. One suggestion in the thread is to duplicate the same function across multiple deployments to distribute the load. The user has also attempted to increase the _APP_WORKER_PER_CORE setting but it didn't improve the performance. No solution is provided in the thread.
Drake
27 Nov, 2023, 16:21

How are you executing the function?

Nour
28 Nov, 2023, 06:52

Synchronous From the SDK

Nour
29 Nov, 2023, 06:19

??

Runpace
29 Nov, 2023, 11:12

Are you looking for something like this? https://github.com/appwrite/appwrite/issues/1425

Nour
29 Nov, 2023, 12:33

I believe my issue is related to this in some ways. My tests were conducted on a function that requires 4 seconds to complete execution for one call. If I execute it 8 times at the same time, it will execute all calls without any delay in the execution time, each taking 4 seconds. However, if I increase the calls to more than 8, it will delay some of them, as I mentioned in my first message (similar to a single thread handling multiple tasks by serving them partially).So Let's consider a scenario where I call it 24 times at the same time. In this case, some executions need 14 seconds to finish and some them need 8 seconds and so on. But, if I duplicate the same function in other deployments, say 3 times, and distribute the calls among them, then each deployed function has to handle 8 calls. In this scenario, there won't be any delay in the call execution.

Nour
30 Nov, 2023, 06:12

.

WhiteWalker72
30 Nov, 2023, 13:40

@Nour just wondering: are you using cloud? When I tested this the functions were executing sequentially. So the next execution would wait for the previous one to complete. I'm using self hosted i'm guessing these executions are managed when using cloud.

Nour
3 Dec, 2023, 06:32

I’m also using the self-hosted version of Appwrite. Have you figured out the asynchronous flag for execution? It should be set to False for parallel execution and True for sequential executions.

Drake
3 Dec, 2023, 14:36

Synchronous shouldn't be blocked like this...what language is your runtime?

Drake
3 Dec, 2023, 14:37

How many cores does your server have?

Nour
4 Dec, 2023, 06:19

Python 3.11

Nour
4 Dec, 2023, 06:22

8 CPUs.

Nour
4 Dec, 2023, 06:23

And

Nour
4 Dec, 2023, 06:31

The _APP_FUNCTIONS_CPUS is empty, as stated in the Appwrite documentation. When it’s empty, the CPU limit will be disabled.

Nour
7 Dec, 2023, 08:49

??

punti_z
8 Dec, 2023, 10:33

I have been contemplating duplicating a function multiple times and have a routing function that triggers them sequentially basis last triggered time .. Would that approach work ?

Nour
11 Dec, 2023, 06:44

Hmm, this is an interesting idea.

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