简体   繁体   中英

Is there a no activity timeout delay with MVC running on Windows Azure with the SQL Server?

I have a new application with no users. I know the first time when I publish to Azure there's a delay as code is compiled. However after the application has been used if I try to access it again in about 30 minutes it seems very slow initially and faster once I have accessed it. My application using MVC4 and connects to a SQL Server for login authentication.

Is there some timeout or delay? Does the service go into a sleep mode to be woken up when used for a while?

By default, IIS shuts down the application pool after 20 minutes of inactivity in order to conserve server resources. http://technet.microsoft.com/en-us/library/cc771956(v=ws.10).aspx

Now, to make things more interesting on Azure, as far as I know, you cannot configure this setting from the web.config file of your application, but rather either through the UI, command line or machine.config file. But there is hope!

This is assuming that you are using web/worker roles and not the new Web Sites thing they came out with

You have to create a startup task for your web role that will do the IIS configuration for you. Its a simple batch file that you instruct the web role to run on startup. There is more information here but basically the .cmd file would look something like this:

REM *** This keeps this file from running on your local emulator. 
if "%EMULATED%"=="true" goto :EOF

REM *** Prevent the IIS app pools from shutting down due to being idle. 
%windir%\system32\inetsrv\appcmd set config -section:applicationPools -applicationPoolDefaults.processModel.idleTimeout:00:00:00

REM *** Prevent IIS app pool recycles from recycling on the default schedule of 1740 minutes (29 hours). 
%windir%\system32\inetsrv\appcmd set config -section:applicationPools -applicationPoolDefaults.recycling.periodicRestart.time:00:00:00

And in your serviceDefintion.csdef file, add the following schema element (assuming you placed the file in a startup folder of your web application and named it disableTimeout.cmd):

<Startup>
  <Task commandLine="startup\disableTimeout.cmd" executionContext="elevated" />
</Startup>

Remember, there can be good reasons to recycle and idle timeout your application pool, but they can be adjusted if you have low traffic site to not happen so frequently.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM