How can I stop my function from scaling up or having concurrency?

Diego Fuentes 0 Reputation points
2024-03-11T20:58:52.8833333+00:00

I have a function that process ServiceBus messeges with the following configuration and packages:

<TargetFramework>net6.0</TargetFramework>
<AzureFunctionsVersion>v4</AzureFunctionsVersion>
<PackageReference Include="Azure.Messaging.ServiceBus" Version="7.17.1" />
<PackageReference Include="Microsoft.Azure.Functions.Extensions" Version="1.1.0" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.ServiceBus" Version="5.8.1" />
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="4.1.3" />
<PackageReference Include="Microsoft.ApplicationInsights.WorkerService" Version="2.22.0" />

In my host.json I have tried to limit my concurrency with the following setting:

"version": "2.0",
  "extensions": {
    "http": {
      "routePrefix": "api",
      "maxOutstandingRequests": 200,
      "maxConcurrentRequests": 1,
      "dynamicThrottlesEnabled": true
    },
    "queues": {
      "batchSize": 1
    },
    "serviceBus": {
      "clientRetryOptions": {
        "mode": "exponential",
        "tryTimeout": "00:05:00",
        "delay": "00:00:00.80",
        "maxDelay": "00:01:00",
        "maxRetries": 3
      },
      "autoCompleteMessages": false,
      "maxConcurrentCalls": 1,
      "maxConcurrentSessions": 1,
      "maxMessageBatchSize": 1
    }
  },
  "concurrency": {
    "dynamicConcurrencyEnabled": false,
    "maximumFunctionConcurrency": 1,
    "cpuThreshold": 0.8,
    "snapshotPersistenceEnabled": true
  },

Also, I have add functionAppScaleLimit=1 in the function configuration.

But all of this had not worked because I still have concurrent Operation_Id in my logs in applicationInsights.
User's image

What can I do to stop the concurrent operations in my function? I just need to them to process sequencially.

Azure Service Bus
Azure Service Bus
An Azure service that provides cloud messaging as a service and hybrid integration.
568 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Claudia Dos Santos Haz (CONCENTRIX CORPORATION) 775 Reputation points Microsoft Vendor
    2024-03-12T15:34:55.8666667+00:00

    Hello @Diego Fuentes,

    Thank you for reaching out to Microsoft Q&A forum!

    Hope this article could help you with this problem:

    https://learn.microsoft.com/en-us/azure/azure-functions/functions-concurrency

    Service Bus

    The Service Bus trigger currently supports three execution models. Dynamic concurrency affects these execution models as follows:

    • Single dispatch topic/queue processing: Each invocation of your function processes a single message. When using static config, concurrency is governed by the MaxConcurrentCalls config option. When using dynamic concurrency, that config value is ignored, and concurrency is adjusted dynamically.
    • Session based single dispatch topic/queue processing: Each invocation of your function processes a single message. Depending on the number of active sessions for your topic/queue, each instance leases one or more sessions. Messages in each session are processed serially, to guarantee ordering in a session. When not using dynamic concurrency, concurrency is governed by the MaxConcurrentSessions setting. With dynamic concurrency enabled, MaxConcurrentSessions is ignored and the number of sessions each instance is processing is dynamically adjusted.
    • Batch processing: Each invocation of your function processes a batch of messages, governed by the MaxMessageCount setting. Because batch invocations are serial, concurrency for your batch-triggered function is always one and dynamic concurrency doesn't apply.

    To enable your Service Bus trigger to use dynamic concurrency, you must use version 5.x of the Service Bus extension.

    Best regards,