The post got quite long so here is the gist :) Are multiple functions within a function app reusing the same host? I tried to keep the host warm using a time triggered small function, but it didn't help to improve the response time of another http triggered function within that function app.
First of all, I really like the promise of Azure Functions, I truly hope that they evolve and one day provide us with the opportunities to write truly serverless code.
I'm currently evaluating Azure Functions for API use cases (Where a function would fully replace a hosted API in a Web app or something similar) and wanted to explore the cold start issues. This is my setup:
The code can be found here
1 Function app that triggers http requests (Timer: 1 minute, trigger-function.js)
4 Function app that are http end points (Http Trigger, api-function.js)
All function apps are in isolated resource groups but in the same region, all are on the dynamic plan.
The idea of my test was to find out when an API end point is hit by the cold start issue. For that, the four http functions are called in different intervals: every 5 minutes, every 10, 15 and 30 minutes. You can read the full logs here*, but let's look at the relevant part:
6-07-28T08:30:00.144 https://<my function api host for5 minutes>/api/HttpTriggerNodeJS1 needed 141ms to complete the request
2016-07-28T08:30:00.175 https://<my function api host for5 minutes>/api/HttpTriggerNodeJS1 needed 172ms to complete the request
2016-07-28T08:30:03.314 https://<my function api host for30 minutes>/api/HttpTriggerNodeJS1 needed 3311ms to complete the request
2016-07-28T08:30:03.393 https://<my function api host for30 minutes>/api/HttpTriggerNodeJS1 needed 3390ms to complete the request
2016-07-28T08:30:03.610 https://<my function api host for15 minutes>/api/HttpTriggerNodeJS1 needed 3607ms to complete the request
2016-07-28T08:30:03.642 https://<my function api host for15 minutes>/api/HttpTriggerNodeJS1 needed 3639ms to complete the request
2016-07-28T08:30:07.234 https://<my function api host for10 minutes>/api/HttpTriggerNodeJS1 needed 7230ms to complete the request
2016-07-28T08:30:07.234 Function completed (Success, Id=4015d7f4-8eed-4d93-8184-252ef02713ef)
2016-07-28T08:30:07.265 https://<my function api host for10 minutes>/api/HttpTriggerNodeJS1 needed 7262ms to complete the request
As you can see, only the API that is repeatedly called every 5 minutes has a sane response time, every other endpoint has brutal response times above 3 seconds.
I then tried to put another time triggered function into the 30 minute API function app and have it be called repeatedly every 5 minutes. I thought that this would keep the host "warm" but it had no effect and the 30 minute API function still needed way too long to respond. Is each function hosted in its own host, even though they are part of the same function app?
*The logs are from the functions portal/web interface and seem to be missing a lot of invocations. I think that it should be mostly fine however, since the trigger function lists all API calls correctly.
Side remarks that I found during developing:
Keep up the good work! :)
Multiple functions do reuse the same host, but that host can be scaled to multiple VMs (each potentially running several of the functions in the app).
Hosts that are unused for 5 minutes get idled out. So having your timer be every 5 minutes puts you right on the Edge.
In term of testing host reuse, you may want to try incrementing a static variable to tell apart new host vs reuse. This will be more reliable than clock time.
I know I didn't address everything in your issue, and it may be better to open separate issues for unrelated things, like the code not running correctly.
I should add that we are working on optimizing the cold start scenario.
I'll respond quickly to a few of the points you brought up, but I agree with David that for any specific issues you should open separate bugs. Thanks for the feedback!
in the .5 version, I can see response time up to 1-5 MINUTES on a dynamic plan. This is with a keep alive hitting my endpoint every 4 minutes. Going nuts here.
Being discussed in #298.