Skip to content

Thread count increases dramatically regardless of maxConcurrentRequests #1008

Description

@will-beta

Here is my simple http triggered function app.
Function1.cs

    public class Function1
    {
        [FunctionName(nameof(Function1))]
        public static async Task RunAsync(
            [HttpTrigger("POST")]string body,
            [Queue("myqueue")]ICollector<string> queue,
            [Blob("mycontainer/{rand-guid}")]CloudBlockBlob cbc,
            ILogger logger
            )
        {
            try
            {
                logger.LogWarning(new EventId(-1, "FunctionStart"), $"{body?.Length}");

                if (body != null)
                {
                    try
                    {
                        await cbc.UploadTextAsync(body);
                    }
                    finally
                    {
                        queue.Add(cbc.Name);
                    }
                }

                logger.LogWarning(new EventId(-1, "FunctionEnd"), $"{body?.Length}");
            }
            catch (Exception gex)
            {
                logger.LogError(new EventId(-1, "FunctionError"), gex, body);
            }
        }
    }

host.json

{
  "version": "2.0",
  "functionTimeout": "00:05:00",
  "healthMonitor": {
    "enabled": true,
    "healthCheckInterval": "00:00:10",
    "healthCheckWindow": "00:02:00",
    "healthCheckThreshold": 6,
    "counterThreshold": 0.80
  },
  "extensions": {
    "http": {
      // the maximum number of outstanding requests that will be held at any given time. The default is unbounded (-1).
      "maxOutstandingRequests": -1,
      // the maximum number of http functions that will be executed in parallel. The default is unbounded (-1).
      "maxConcurrentRequests": 5,
      // The default is false.
      "dynamicThrottlesEnabled": true
    }
  }
}

In my opinion, the thread count should depend on the maxConcurrentRequests .
But it would go up to more than 300 even I had stopped creating new requests from JMeter. Then it took quite some time to decrease to 30 or so.
My VS2017 gave me the following information when I attached it to the process,
image

Making the function Sync solves the problem on my local computer, but it still happens when I deploy the app onto the Azure.
Function1.cs

    public class Function1
    {
        [FunctionName(nameof(Function1))]
        public static void Run(
            [HttpTrigger("POST")]string body,
            [Queue("myqueue")]ICollector<string> queue,
            [Blob("mycontainer/{rand-guid}")]CloudBlockBlob cbc,
            ILogger logger
            )
        {
            try
            {
                logger.LogWarning(new EventId(-1, "FunctionStart"), $"{body?.Length}");

                if (body != null)
                {
                    try
                    {
                        cbc.UploadTextAsync(body).Wait();
                    }
                    finally
                    {
                        queue.Add(cbc.Name);
                    }
                }

                logger.LogWarning(new EventId(-1, "FunctionEnd"), $"{body?.Length}");
            }
            catch (Exception gex)
            {
                logger.LogError(new EventId(-1, "FunctionError"), gex, body);
            }
        }
    }

The same thing recurs after I replace the await cbc.UploadTextAsync(body) with await Task.Delay(1000).
So, my question is : maxConcurrentRequests is not capable of limiting the thread count? How does it work exactly?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions