Back

[SOLVED] How to keep runtime container alive (for higher responsiveness)?

  • 0
  • Functions
THE-E
1 May, 2023, 16:00

Is it possible to start the docker container of the appwrite functions manually? My use case: I have several functions (20+) which don't have a timeout, so they are always up and running for quick responses. But in the case that I restart my server, the functions will be slow on the first run.

I thought I could simply use the command

TypeScript
docker start <project-id>-<deployment-id>

But the docker containers of the appwrite functions aren't restartable as far as I can tell.

Do I need to trigger the 20+ endpoints using a REST request, in order to get all the functions up and running or is there a more elegant way?

My aim is, that the appwrite functions are always highly responsive, even after a restart.

TL;DR
To keep the runtime container alive for higher responsiveness, there are a few approaches you can try: 1. Increase function threshold time: Set the `_APP_FUNCTIONS_INACTIVE_THRESHOLD` variable to a longer time, like 24 hours, so functions consume less RAM when idle. 2. Gather functions together: Combine the logic of multiple functions into one and use a variable to determine which inner function to run. 3. Keep alive: Create another function triggered by a CRON job every hour. This function will call all the other functions with a special parameter (e.g., "keep_alive"), ensuring they stay "alive" by returning a success response
Binyamin
1 May, 2023, 16:10

The starting process of a function is inside the Appwrite **executor **container

You can post a rest request to it http://appwrite-executor/v1/execution from a custom-made-by-you container that will have to be in the appwrite network, with the necessary data. This can become tricky real fast.

You can find more details here: https://github.com/appwrite/appwrite/blob/master/app/executor.php#L458

For you use-case, you can try one of the following approaches

Increase function threshold time You can just increase the value of _APP_FUNCTIONS_INACTIVE_THRESHOLD to lets say 24hours in seconds. Doing so will increase your function timeline and it each function will consume only RAM when it is on idle mode.

See more here: https://appwrite.io/docs/environment-variables#functions

Gather functions together If you don't want to have to many function keep running around, then you can encapsulate the logic of few function into one, then you can add another variable to know which inner-function you want to run.

Keep alive If you want to keep the threshold to be in a small value, or you don't want to change it. you can create another function, then, let be trigger by CRON job once a hour.

This function will call all the function with a special parameter - keep_alive for example - and any of your function when they will see the keep_alive parameter will just return res.json success.

This way you'll make sure that your function will stay "alive".

With this method you also be able to quickly to start all the function, All you need to do is to just execute the new one.

THE-E
1 May, 2023, 19:55

In that case I will probably choose the keep alive variant. I will just trigger that function on start up. Thanks for the hints and tips 🙂

Drake
1 May, 2023, 20:01

[SOLVED] How to keep runtime container alive (for higher responsiveness)?

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