Request is sent to new instance of Function app before Warmup trigger completes

Sanketh Iyer 20 Reputation points
2024-02-12T13:32:58.12+00:00

I have a function app which uses dedicated plan and has a autoscale configured based on CPU and memory. Default minimum instance is 3 and max number of instances is 5. We have created a warmup trigger which gets executed on an autoscale event. However, the warmup trigger takes around 8 secs to complete based on our current logic. We have observed that the new instance starts accepting traffic as soon as its ready and even before the warmuptrigger is completed. Is there a way to ensure that the new instance only accepts requests after the warmuptrigger is completed?

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
5,910 questions
Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
8,933 questions
0 comments No comments
{count} votes

Accepted answer
  1. MuthuKumaranMurugaachari-MSFT 22,441 Reputation points Moderator
    2024-02-20T20:47:02.46+00:00

    Sanketh Iyer Thanks for posting your question in Microsoft Q&A. This is per design, and this could happen if the app takes longer time to initialize dependencies or other factors. The warmup trigger is best effort, and the recommendation is to use lazy loading pattern so that the application have ability to cope with dependencies not preloaded.

    Hence, we suggest not to rely on warmup trigger as described in doc Azure Functions warmup trigger. User's image

    However, I understand there are gaps in the doc such as status of warmup trigger, other discussion like Warmup trigger behavior on Dedicated plan scale out and passed on feedback to our product team internally. Currently, they are reviewing and will make necessary changes in the doc to answer those questions.

    I hope this helps and let me know if any questions.


    If you found the answer to your question helpful, please take a moment to mark it as Yes for others to benefit from your experience. Or simply add a comment tagging me and would be happy to answer your questions.

    1 person found this answer helpful.
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Achraf Ben Alaya 1,311 Reputation points MVP
    2024-02-15T14:02:22.58+00:00

    One of the solutions :

    Azure Functions Proxies: Set up an Azure Functions Proxy to intercept incoming requests and direct them to your function app. This allows you to control the routing and add custom middleware to handle request processing.

    1. Custom Middleware: Implement custom middleware within your function app to check the status of the warm-up trigger before allowing requests to be processed. This middleware will intercept incoming requests, check if the warm-up trigger is completed, and either allow or reject the request based on the warm-up status.
    2. Update Warm-up Trigger: Ensure that your warm-up trigger function completes its initialization logic before signaling that it is ready to accept requests. This may involve optimizing the warm-up trigger logic to reduce execution time.
    3. Integration with Azure Functions: Integrate the custom middleware into your Azure Functions runtime environment to intercept incoming requests before they are passed to your function handlers. Testing and Monitoring: Thoroughly test your solution to ensure that new instances only accept requests after the warm-up trigger is completed. Monitor the execution time of the warm-up trigger and adjust as necessary to meet performance requirements.

    By combining Azure Functions Proxies with custom middleware, you can implement fine-grained control over request routing and ensure that new instances are fully initialized before handling incoming requests. This approach provides flexibility and scalability while maintaining control over initialization processes.

    1 person found this answer helpful.

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.