Setting a minimum number of instances to keep running when using auto start/stop

hi @manoelcampos

I just wanted to clarify, that the auto start and stop feature is only starting and stopping Machines, never destroying them.

Could you clarify what’s happening when you set min_machines_running = 0? Are you saying the app is unreachable, or the stopped Machine is taking too long to start up when you make a request? The process to auto stop a Machine runs every few minutes and that is not configurable.

Could you post your logs for when the issue is happening (when you have min_machines_running = 0)?

Hello @andie, thanks for replying.

Great. That explains why I don’t see a cold start.

The app is reachable and it restarts right-away (no cold start), but since my web app uses session authentication, the session is destroyed right after I log in, so I’m disconnected. This just happens when I set min_machines_running = 0.

The autoscaling is happening in a timespan smaller than 1 minute.
I’ve seen that in the logs between 2023-12-12 16:15:11.424 and 2023-12-12 16:15:21.078
and that seems to be the issue.

Even I’m being the only user accessing the app at http://competeaqui-staging.fly.dev,
it starts with 0 machines, suddenly scales to 2 (there is no workload to justifies it),
than it scales down to 1. The point is that even if I spend just a couple of seconds to try logging in again, the machines seem to be continuously being scaled up and down.

Logs are available here.

I’m not sure, but something seems to be happening where your app is unreachable for a time and that’s when the second machine starts up.

2023-12-12 16:09:44.613 [competeaqui_fly_io_logs] [INFO] gru eb5d <Machine 1> competeaqui-staging 2023-12-12T19:09:44.613Z  WARN 314 --- [           main] org.hibernate.orm.deprecation            : HHH90000025: PostgreSQLDialect does not need to be specified explicitly using 'hibernate.dialect' (remove the property setting and it will be selected by default)
2023-12-12 16:09:44.966 [competeaqui_fly_io_logs] [ERROR] gru eb5d <Machine 1> competeaqui-staging failed to connect to machine: gave up after 15 attempts (in 8.47330416s)
2023-12-12 16:09:44.996 [competeaqui_fly_io_logs] [INFO] gru 8522 <Machine 2> competeaqui-staging Starting machine

Then Machine 1 seems to come back to life before Machine 2 has fully completed app start up. Machine 2 eventually becomes unreachable in exactly the same way Machine 1 did (after the hibernate WARN). And so on.

The auto start and stop seems to be working as expected, with one exception where it shuts down both Machines within less than a minute (between 2023-12-12 16:15:11.424 and 2023-12-12 16:15:21.078). I don’t know why this happenned (there was an authentication WARN log before that though) but I don’t see it happening at any other point in this app’s logs.

I don’t see any issues in my app. The same code works correctly when setting min number of machines to 1. The authentication warning is shown because the machine is stopped and the user session is lost. When that happens, the warning is shown and the user is redirected to the login page. When I always have 1 machine, that doesn’t happen.

The warning is that one below:

2023-12-12 16:12:56.481 [competeaqui_fly_io_logs] [INFO] gru eb5d 5683003a66e08e competeaqui-staging 2023-12-12T19:12:56.480Z  WARN 314 --- [0.0-8080-exec-9] b.c.c.m.s.CustomAuthenticationEntryPoint : InsufficientAuthenticationException - Full authentication is required to access this resource: GET /inscricao/list