azure-sdk-for-net icon indicating copy to clipboard operation
azure-sdk-for-net copied to clipboard

Add new TargetUnprocessedEventThreshold parameter in EventHub Options + Target Based Scaling for Event Hubs

Open chiangvincent opened this issue 2 years ago • 4 comments

Overview

Azure Functions scales event hubs based on the number of unprocessed events distributed across all the partitions in the hub. By default it takes the configured maximum batch size and assumes that each allocated instance will process that many events, and allocates sufficient instances to process all unprocessed events, taking into account that each partition can only be processed by one instance. You can adjust this default behavior by specifying the TargetUnprocessedEventThreshold - the total unprocessed event count will be divided by this value to determine the number of instances, and then we will round that up to an instance count that creates a balanced partition distribution.

This PR introduces the new attribute that users can set to fine-tune the default target based scaling behavior, and it also adds support for target based scaling for Event Hub-triggered functions.

Checklist for Target Based Scaling Changes

  • [x] create EventHubsMetricsProvider
  • [x] remove duplicate logic between EventHubsSaleMonitor, EventHubsMetricsProvider
  • [x] EventHubsListener implementITargetScalerProvider
  • [x] fix unit tests
  • [x] add EventHubsargetScaler
  • [x] add unit tests for EventHubsTargetScaler
  • [x] E2E tests with Event Hub trigger with locally running function app
  • [ ] test with scale controller prototype (dependent on finalizing the scalerfactory implementation)

Logs from E2E Verification With Local Function App

Steps:

  1. Generate a local nuget package with EventHub changes from this PR
  2. Create function app referencing local EventHub nuget packages
  3. Publish and run the application locally with azure-functions-host repo
  4. Enable runtime driven scaling, target based scaling, and add ScmHostingConfigurations.txt to enable EventHubs TBS
  5. Send 200k messages to event hub with 5 partitions, in batches of 300 messages
  6. Ping admin/host/scale/status API using Postman, observe target worker count and local azure-functions-host logs emitted

Target Based Scaling Enabled image

Target Based Scaling Disabled image

image image

target scaler using the targetUnprocessedEventThreshold as the concurrency value in target based scaling image image

image

Resources

Contributing to the Azure SDK

Please see our CONTRIBUTING.md if you are not familiar with contributing to this repository or have questions.

For specific information about pull request etiquette and best practices, see this section.

chiangvincent avatar Jan 25 '23 18:01 chiangvincent

API change check

APIView has identified API level changes in this PR and created following API reviews.

Microsoft.Azure.WebJobs.Extensions.EventHubs

azure-sdk avatar Jan 25 '23 18:01 azure-sdk

Tagging @alrod to help with review

pragnagopa avatar Jan 25 '23 19:01 pragnagopa

Hi @chiangvincent Somewhat I can't leave the pointer, however, you need to update here. admin/host/config api will use this part. Formatter

Could you double check "spec" part on this PR description? https://github.com/Azure/azure-functions-host/pull/8148

TsuyoshiUshio avatar Jan 26 '23 18:01 TsuyoshiUshio

tagging @paulbatum for review as well!

pragnagopa avatar Jan 27 '23 18:01 pragnagopa

/azp run net - eventhub - ci

jsquire avatar Feb 14 '23 19:02 jsquire

Azure Pipelines successfully started running 1 pipeline(s).

azure-pipelines[bot] avatar Feb 14 '23 19:02 azure-pipelines[bot]

/azp run net - eventhub - ci

jsquire avatar Feb 14 '23 20:02 jsquire

Azure Pipelines successfully started running 1 pipeline(s).

azure-pipelines[bot] avatar Feb 14 '23 20:02 azure-pipelines[bot]