Reputation: 667
If I have a Function app like so
public static class Function1
{
private static readonly HttpClient httpClient = new HttpClient();
[FunctionName("SomeRandomFunction")]
public static async Task<IActionResult> Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req, ILogger log)
{
ulong i = 0;
Thread.Sleep(10000);
return (ActionResult)new OkObjectResult($"Hello thread Finished.");
}
}
Are different instances of the function created if different e.g. mobile devices trigger the function at the same time?
I had inferred this from this quote "When you're using the Premium plan, instances of the Azure Functions host are added and removed based on the number of incoming events just like the Consumption plan". I'm on S1 plan.
However when I tested a thread.sleep in function "SomeRandomFunction" like above with two calls for this same function from two different private browser windows, the second call only starts when the first one finished. Why does this happen if it's possible to create several instances of the same function app?
Or is a multi-threading implementation required to have several instances running at the same time?
Thank you
Upvotes: 1
Views: 6571
Reputation: 89071
Are different instances of the function created if different e.g. mobile devices trigger the function at the same time?
Yes. From the docs:
The unit of scale for Azure Functions is the function app. When the function app is scaled out, additional resources are allocated to run multiple instances of the Azure Functions host. Conversely, as compute demand is reduced, the scale controller removes function host instances. The number of instances is eventually scaled in to zero when no functions are running within a function app.
Azure Functions scale and hosting
Upvotes: 2