4

I am testing my Azure function (v2 targeting .Net Core) with QueueTrigger locally with the following configs in host.json file

"queues": { "batchSize": 1, "newBatchThreshold": 0 }

The intent is to limit each Function App instance to only process one queue msg at a time.

According to this Azure function doc,

If you want to minimize parallel execution for queue-triggered functions in a function app, you can set the batch size to 1. This setting eliminates concurrency only so long as your function app runs on a single virtual machine (VM).

In host.json file, have these configs

{ "queues": { "maxPollingInterval": 2000, "visibilityTimeout" : "00:00:30", "batchSize": 16, "maxDequeueCount": 5, "newBatchThreshold": 8 } }

In our case, I'm not trying to eliminate concurrency, but I am trying to make sure each function app instance will only process one queue msg at a time. Then if we scale out the function app to run on multiple VMs, each VM is guaranteed to only process one queue msg at a time. To be more specific, the plan is to run the azure function under App Service plan, instead of Consumption plan (b/c you have very little control with the Consumption plan), and set the Scale Out rule to monitor a queue, up to N number of instances (VMs). This setup allows us to dedicate each VM to run ONE azure function app instance at a time, up to N VMs.

When I'm testing this locally, my azure function always grabs multiple msgs from the queue at the same time, even with the "BatchSize: 1" config in host.json file. I'm wondering if it's b/c I'm testing this in the local Azure function run time. I have not tested this in Azure yet. Hopefully it works as expected in Azure.

Chuck
  • 332
  • 4
  • 15
  • 1
    Does your host.json follow this shape? `{ "version":"2.0", "extensions": { "queues": { "batchSize": 1, "newBatchThreshold": 0 } } }` (see docs: https://learn.microsoft.com/en-us/azure/azure-functions/functions-bindings-storage-queue#hostjson-settings) – Marie Hoeger Dec 05 '18 at 18:17
  • 1
    Thanks for replying. No, it was not. I didn't have the "queues" section inside "extensions". I didn't know I needed to do that. It was { "version":"2.0", "queues": { "batchSize": 1, "newBatchThreshold": 0 } }. So I corrected it, and tried again, now I get the ArgumentOutOfRangeException on NewBatchThreadhold being 0. The exception occurs inside Microsoft.Azure.WebJobs.Host.QueuesOptions class. – Chuck Dec 05 '18 at 19:24
  • Also, I tried "newBatchThreshold: 1" instead of 0, and confirmed that it was processing 2 queue msgs at a time, as expected. – Chuck Dec 05 '18 at 19:32

1 Answers1

9

The issue turned out to be that "queues" wasn't nested under "extensions"

Example:

{
    "version": "2.0",
    "extensions": {
        "queues": {
            "maxPollingInterval": "00:00:02",
            "visibilityTimeout" : "00:00:30",
            "batchSize": 16,
            "maxDequeueCount": 5,
            "newBatchThreshold": 8
        }
    }
}

The referenced extension (Microsoft.Azure.WebJobs.Extensions.Storage should also be at least 3.0.1 for this case, as there was previously a bug with setting newBatchThreshold to 0.

Marie Hoeger
  • 1,261
  • 9
  • 11
  • 1
    yep, that was it. I was using Microsoft.Azure.WebJobs.Extensions.Storage v3.0.0. As soon as I updated it to v3.0.2, and set "newBatchThreshold" to 0, it worked as expected, ie, only processing 1 queue msg at a time. – Chuck Dec 05 '18 at 19:51