eileennoonan

eileennoonan

FLAME slow cold starts

I’m deploying an app on Fly.io, and it’s going to involve running headless browsers similarly to World Page Speed. So naturally I’d like to use FLAME to manage the headless browser portion.

The problem is my FLAME nodes have very long cold starts - upwards of 20 seconds even when I boost the machine resources.

I am assuming that this is because I have so many dependencies in my main app - Phoenix, Nx, and Ash + a bunch of Ash extensions are probably the main contenders.

Is that assumption correct?

If so, would it make sense to just create a separate mix app for my headless browser FLAME calls? I think just about the only dependency it would need to boot would be web_driver_client and req. No Ash, no Phoenix. And I see that with FLAME.FlyBackend we can specify which docker image we want our node to spin up.

Is this a normal / recommended way of using FLAME? Any tips before I head down that road? It seems like I might not even need to write any code in the headless browser runner app, just make sure the correct dependencies are loaded.

~Eileen Noonan

Marked As Solved

chrismccord

chrismccord

Creator of Phoenix

What is the size of your app image? What region(s) is your app located? There’s nothing to compile/build since it will be launching the prebuilt docker image from the parent. Are you certain the time is the cold start and not something app specific like the time to load your headless chromedriver process and start your sup tree? worldpagespeed cold starts are in the 5-10s range with the time including actual time to start chrome/chromedriver and start driving the browser. Are you consistently seeing these times or only occasionally? Depending on machine placement, the docker image layers may need to be pulled to a new host, so that can also add time and the size of the image would affect that, but we need to know more. Your fly logs would also be reporting the image pull time.

You can also look into starting with a warm pool min: whatever and min_idle_shutdown_after to idle down below min if no work is needed to avoid deploys causing users to hit a cold pool.

Also Liked

jswanner

jswanner

Welcome Eileen! We met at ElixirConf, good to see you on the forum.

I’ve haven’t used FLAME yet, so I don’t know if there are recommended ways to handle your situation and I’m not speaking from experience. If I were in your position, I would start by modifying the MyApp.Application.start/2 callback (lib/my_app/application.ex) to conditionally specify what should start when run via FLAME or not. FLAME.Parent.get/0 can be used to determine which way the application is being started.

josevalim

josevalim

Creator of Elixir

If you are concerned about the boot time on the number of dependencies, maybe setting RELEASE_MODE=interactive as an env var will help loading less code? You should also consider trimming your Application.start supervision tree.

Last Post!

eileennoonan

eileennoonan

Thanks Chris! I’m marking this as the solution here but my actual reply is over in the fly.io forum. In the future I will just keep these questions to a single forum :sweat_smile:

Where Next?

Popular in Questions Top

minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set? Thanks.
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New

Other popular topics Top

Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
jononomo
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New
sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New

We're in Beta

About us Mission Statement