We tested the scaleout feature of Azure Functions with a more heavyweight console app, with HTTP trigger, and Consumption Service Plan. So we expected a parallel execution with scale out. We execute the console app in a new AppDomain, because funcion instances are running in the same process. In the console app we do sqlite database operations on an in memory db.
First we executed the function only 1 time, and measured the execution time. Let it be x :) We initiated continuously an increased number of parallel threads. We experienced that the execution time of 1 function app instance in these cases was x * num_of_threads. So as if the function instances would have been serialized and not executed parallel.
- What can be the reason for this? Why are they not executed parallel?
- What hardware is there by default? It is quite slow. Can it be somehow upgraded in Consumption Plan. Why it was not scaled out? Can sg block scale out feature?
Thanks for you help.
EDIT: The basic source code of my app:
using System.Net;
using System;
public static HttpResponseMessage Run(HttpRequestMessage req, TraceWriter log, ExecutionContext context)
{
string testThreadId = req.GetQueryNameValuePairs()
.FirstOrDefault(q => string.Compare(q.Key, "id", true) == 0)
.Value;
var funcId = context.InvocationId.ToString();
var homePath = Environment.GetEnvironmentVariable("HOME");
var folderName = Path.Combine(homePath,@"site\wwwroot\JanoRunTime2");
var fileName = Path.Combine(folderName,"AzureFunctionTest.exe");
var configFile = Path.Combine(folderName,"AzureFunctionTest.exe.config");
var setup = new AppDomainSetup();
setup.ApplicationBase = folderName;
setup.ConfigurationFile = configFile;
var newDomain = AppDomain.CreateDomain("JanoTestExecutorDomain_" + funcId, null, setup );
try{
newDomain.ExecuteAssembly(fileName, new []{testThreadId, funcId});
return req.CreateResponse(HttpStatusCode.OK );
}
catch(Exception e){
return req.CreateResponse(HttpStatusCode.InternalServerError);
}
finally{
AppDomain.Unload(newDomain);
}
}