Search code examples
web-applicationsamazon-ecsshiny-serveraws-fargateamazon-elb

Fargate webserver in AWS ECS has long response time after idle period (but sometimes not)


I have packaged an R Shiny application in docker and deployed it to AWS ECS on a Fargate instance with an application load balancer whose listener holds the SSL certificate. I can see that the task is running and healthy, but when I go to the URL after some idle period, it takes a full 30 seconds to load (again, this is not from the instance startup/provisioning time since it is already up and healthy). I can then open up a new browser and go to the same link, and it will load immediately. What could be causing this? I'm honestly not even sure what to search.

Note: When I run the container locally, the app does take a few seconds to start, but that is only when the container initially starts. It runs very quickly after that initial startup time regardless of idle time. Therefore, I don't think it's shiny-server. The instances that I am referring to above are already running, and I would expect them to behave accordingly.

I read about load balancer idle timeout, but would that take 30 seconds to reconnect after it ends the connection? I'm not very experienced when it comes to the inner workings of web apps, but it seems unlikely. At the same time, it seems like increasing the idle timeout did help, but the behavior is kind of erratic so that might just be confirmation bias.

I can provide more details about the configuration if needed. I just hoped that someone might know what details I should share instead of sharing my entire Terraform directory.


Solution

  • I ended up solving this by noticing that only one of my two associated subnets was public. If you have a public load-balancer, you need to have both of the associated subnets public as well (and private if private...)