简体   繁体   中英

Azure function not running parallel

I have created an azure function in python. I am calling it via C# and I am expected to send out about 1000 request simultaneously. What I need it for this function is to process those request in parallel and not one after the other, but I cant make it happen.

Here is my test code that sends 10 requests in parallel.

static void Main(string[] args)
    {
        List<string> symbols = new List<string> { "MSFT", "AAPL", "NFLX", "JNJ", "INTC", "GOOG", "AMZN", "FB", "TSLA", "TSM" };           
        List<string> results = new List<string>();
        List<string> urls = new List<string>();
        Parallel.ForEach(symbols, (symbol) =>
        {
            Trace.WriteLine("Getting - " + symbol);
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create("MY FUNCTION URL");
            request.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;

            using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
            using (Stream stream = response.GetResponseStream())
            using (StreamReader reader = new StreamReader(stream))
            {
                Trace.WriteLine(reader.ReadToEnd());
            }
            Trace.WriteLine("Finished - " + symbol);
        });
        Console.ReadKey();

    }

I can see that the requests are sent all together. but the processing is one after the other. here is my host.json file:

{
  "version": "2.0",
  "logging": {
    "applicationInsights": {
      "samplingSettings": {
        "isEnabled": true,
        "excludedTypes": "Request"
      }
    }
  },
  "extensionBundle": {
    "id": "Microsoft.Azure.Functions.ExtensionBundle",
    "version": "[2.*, 3.0.0)"
  },
  "extensions": {
    "queues": {
      "batchSize": 1
    },
    "http": {
    "routePrefix": "api",
    "maxOutstandingRequests": 200,
    "maxConcurrentRequests": 1
    }
 

} }

As far as I understood setting "maxConcurrentRequests" to 1 enforces the function app to scale out and create multiple instances. I have tried setting this value to 10 and 100 and it did nothing.

I have also tried adding the following configuration values to the function app:

FUNCTIONS_WORKER_PROCESS_COUNT = 10.

PYTHON_THREADPOOL_THREAD_COUNT = 32.

that did not make any difference as well.

I can see in the azure analytics that the functions are processed one after the other according to their timestamps. and also the accumulated time is ~ 10 * a single run.

I am pretty sure its a configuration issue, what have I missed?

Thanks

Amit

Have look at this documentation which says

The maximum number of HTTP functions that are executed in parallel. This value allows you to control concurrency, which can help manage resource utilization. For example, you might have an HTTP function that uses a large number of system resources (memory/cpu/sockets) such that it causes issues when concurrency is too high. Or you might have a function that makes outbound requests to a third-party service, and those calls need to be rate limited. In these cases, applying a throttle here can help. *The default for a Consumption plan is 100. The default for a Dedicated plan is unbounded (-1).

Setting it to 1, is basically telling it NOT to process the requests in parallel. If you set it to 100, it will attempt to process 100 at a time. If the memory or CPU required is more and there are still more requests in queue, functions will start automatically scaling up (assuming you are on consumption plan).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM