问题
I have an azure function that is dealing with requests for an Alexa skill, but every so often I get a timeout due to the azure function not responding within 10 seconds (requirement of an alexa skill):
The requested application took too long to respond
Request Identifier: amzn1.echo-api-request.xxxxx.xxx Application must respond within 10 seconds of the request being sent.
I'm guessing the azure function app is getting teared down after inactivity to save on resources similar to azure websites.
The azure function app is running under a Consumption Plan and I can't seem to find an option to have it always on like the azure websites.
The only other option I can think of doing is creating a function within the function app to ping to keep the azure function alive. It just seems a bit hacky so I wondered if there is a better way to keep the azure function app alive?
回答1:
You are correct in that this is by design of the Consumption plan. If all functions on the Application have not received a request for processing for a given amount of time, the instance will be 'torn down' and you will have to 'warm up' for the next request that is accepted.
- You can, as you suggested, 'ping' a function to keep it up. The best way to do this is probably to deploy a new function to the same application with a timer based trigger that simply returns straight away. Please note this may incur more 'cost' as you are using up execution time, albeit very small.
Preventing to change to cold-start mode is quite easy. Just add a time trigger function within the same function app which executes every 5 minutes. But be aware that this may cause additional costs if your free execution credit is exceeded.
Cold Start and Warm Start on Consumption Plan
- Alternatively, you can go with an App Service Plan which does have the Always On feature, however, you may need to weigh up the cost/benefits of this approach vs option 1
If you run on an App Service plan, you should enable the Always On setting so that your function app runs correctly. On an App Service plan, the functions runtime will go idle after a few minutes of inactivity, so only HTTP triggers will "wake up" your functions. This is similar to how WebJobs must have Always On enabled. Always On is available only on an App Service plan. On a Consumption plan, the platform activates function apps automatically.
Always On
来源:https://stackoverflow.com/questions/46129727/alexa-timeout-with-azure-functions