I’ve been having a bit of an issue with my AWS app going to sleep and taking a long time to handle initial requests.
I’m using .NET with Elastic Beanstalk on a T2 Micro Instance and MSSQL Server Express on RDS. My FrontEnd is a static ReactJS app that sits in S3 behind CloudFront. There’s also a load balancer across the backend.
My frontend was always instant but my initial Api calls were timing out. This ruled out S3 and CloudFront, leaving the following:
- Load balancer
After a bit of Googling I came across something that looked fairly promising – MSSQL Server Express has a property called AutoClose set to ‘ON’ by default. AWS appears to correct this as mine was off however it’s worth checking:
-- If set to zero then auto close is off SELECT DATABASEPROPERTY('mydatabasename','IsAutoShrink') -- Check all instances at once SELECT name,is_auto_close_on FROM sys.databases -- Turn off if on ALTER DATABASE myDB SET AUTO_CLOSE OFF
In my case the actual problem turned out to be IIS idle timeout. By default IIS automatically times out an application after 20 minutes. In order to disable this create the following ebextension:
commands: setIdleTimeoutToZero: cwd: "C:\windows\system32\inetsrv" command: "appcmd set apppool /apppool.name:DefaultAppPool /.processModel.idleTimeout:0.00:00:00"
If you haven’t done this before, all you need to do is create a folder called .ebextensions under your project directory. Then create a new file called iis-idle-timeout.config and add the yaml to it. If you need more information on iis timing out check out this great blog post: https://notebookheavy.com/2017/06/21/set-iis-idle-timeout-elastic-beanstalk/
Thanks to these sources for the solutions:
Disable auto_close: https://stackoverflow.com/a/1750400/522859
IIS Timeout: https://notebookheavy.com/2017/06/21/set-iis-idle-timeout-elastic-beanstalk/
EBExtension Info: http://notebookheavy.com/2017/05/01/auto-install-newrelic-agent-elastic-beanstalk/
Leave a Reply