Back

Self Hosted Functions Performance

  • 0
  • Self Hosted
  • Accounts
  • Functions
greends
20 Jun, 2023, 13:54

Hello all, I have a question about the functions working on a self hosted instance.

My function response gets cooked in 30 seconds or so, due to calling different apis, retrieving some information in the cluster somewhere and sorting things through blabla. I have outsourced the heavy parts to other machines but I question if I could use Appwrite functions to combine them all in one place, instead of JWT token validating the user account in those machines.

Question is: Do the self hosted functions run in serial or in parallel? I mean does one request wait for the previous one to finish so it can start working on its current request (right after the first one quit blocking the machine) ? If so, Can I limit the resource that one thread uses so there might be more resources to start other threads? If not, how many functions in parallel can Appwrite handle?

Thank you.

TL;DR
The user is asking if self-hosted Appwrite functions run in serial or parallel and if there is a limit to the number of functions that can run in parallel. The answer is that by default, self-hosted functions run in serial, but you can configure multiple workers to enable concurrent handling of jobs. Each worker allows for multiple executions to occur simultaneously. Additionally, if you create an execution with `async=false`, it is handled by the API server and can run in parallel at a rate of 8 times the number of CPU cores. There is a link provided for more information on how Appwrite functions work on self-hosted instances,
joeyouss
20 Jun, 2023, 13:59

async=false can run in parallel, event-triggered/scheduled/async=true runs in serial, unless you spin up multiple function workers.

Binyamin
20 Jun, 2023, 13:59

First, check this https://github.com/appwrite/appwrite/issues/5629 You'll find a lot of information on how Appwrite function works - specifically on self-hosted.

The semi-solution part will make your function runs much faster and will make the execution of your function much more reliable.

Binyamin
20 Jun, 2023, 14:00

For check how much function Appwrite can handle in parallel, check the table at the bottom of the link.

joeyouss
20 Jun, 2023, 14:01

In the default configuration, there is a queue from which workers read. By default, there is only one worker, which means that only one execution can run at a time. However, you have the option to scale the number of workers by duplicating the functions worker in the docker-compose file. By doing this, you can have multiple workers, such as 2, 3, 5, or even more, depending on your server's capacity. Each worker enables concurrent handling of jobs, allowing multiple executions to occur simultaneously.

By default, the executions run in a serial manner, with only one execution processed at a time. However, if you create an execution with async=false, it is handled by the API server instead of a worker. The API server allows concurrency at a rate of 8 times the number of CPU cores by default. This means that for async=false executions, you can typically run multiple executions concurrently, potentially dozens of them simultaneously.

greends
20 Jun, 2023, 14:01

very valueable information from you both.

greends
20 Jun, 2023, 14:01

I need to make a research and come back

greends
20 Jun, 2023, 14:43

Well... Thank you Appwrite for being transparent about that painpoint and offering a solution, hacky but still.

greends
20 Jun, 2023, 14:45

For the reference I checked Supabase and they're offering a way to host functions on the cloud. (https://www.youtube.com/watch?v=cPGxPl1lx4Y)

greends
20 Jun, 2023, 14:45

But Appwrite has a better solution still

joeyouss
20 Jun, 2023, 14:46

We do have Appwrite Cloud https://cloud.appwrite.io/

greends
20 Jun, 2023, 14:46
greends
20 Jun, 2023, 14:46

pricing information is still not revealed.

greends
20 Jun, 2023, 14:47

I would call functions in the cloud by JWT validating

joeyouss
20 Jun, 2023, 14:47

We are free as of now, the pricing will be released soon but we will have a generous free tier

greends
20 Jun, 2023, 14:47

instead of calllling them on the local machine

greends
20 Jun, 2023, 14:50
TypeScript
const sdk = require('node-appwrite');

let client = new sdk.Client();

client
    .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint
    .setProject('5df5acd0d48c2') // Your project ID
    .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key
    .setSelfSigned() // Use only on dev mode with a self-signed SSL cert
;

I can run this on a Lambda function and get the user information in an instant and do not block the Self Hosted Appwrite Functions

greends
20 Jun, 2023, 14:50

And respond from there.

Binyamin
20 Jun, 2023, 14:52

Yes. That's of course also an option

Binyamin
20 Jun, 2023, 14:52

The use of function its just very easy and make you put all the logic stuff in one place.

greends
20 Jun, 2023, 14:54

And it can 'write' the response to the database for user to read from the local instance

Binyamin
20 Jun, 2023, 14:59

What you mean by write

greends
20 Jun, 2023, 15:55

write to the database

Binyamin
20 Jun, 2023, 15:55

Yes you can do anything you want with the node SDK.

greends
20 Jun, 2023, 15:55

I was thinking that user would read them from there but no need actually

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