I have an Azure Function v4 .NET 6 isolated app with an HTTP trigger function that writes events to an event hub. Another event hub triggered function in the same app listens to those events, performs some manipulation, and publishes them again to another hub, which is listened to by a different function app.
I’ve noticed through logs that there’s a delay of approximately 5-10 seconds between when an event is published and when it’s received by the event hub trigger function. Since there are two event hub listeners involved, the total delay is 10-20 seconds, which is unacceptable for my use case.
Event hug trigger:
[Function(_functionName)]
public async Task RunAsync([EventHubTrigger(eventHubName: $"%
{nameof(EnvironmentVariables.HubName)}%",
Connection = $"{nameof(EnvironmentVariables.HubNamespaceReadWriteConnection)}",
ConsumerGroup = "$Default")] string[] messages)
{
//Biz logic
}
Configuration in host.json for the event hub is:
"eventHubs": {
"batchCheckpointFrequency": 1,
"maxEventBatchSize": 200,
"maxWaitTime": "00:00:01",
"minEventBatchSize": 2,
"clientRetryOptions": {
"mode": "exponential",
"tryTimeout": "00:05:00"
}
}
As you can see maxWaitTime is set to 1 second, so it should wait for a maximum of 1 second to create a batch. However, it’s not behaving according to this configuration.
I’ve also tried removing batching from the trigger altogether and listening to single events only, but the delay remains the same. Here’s an example of the code for that:
[Function(_functionName)]
public async Task RunAsync([EventHubTrigger(eventHubName: $"%
{nameof(EnvironmentVariables.HubName)}%",
Connection = $"{nameof(EnvironmentVariables.HubNamespaceReadWriteConnection)}",
ConsumerGroup = "$Default", IsBatched = false)] string message)
{
//Biz logic
}
My app is hosted in the consumption tier. I’ve also tried the premium tier, but the behavior remains the same. Additionally, this should not be a cold start issue because this is happening for several events sent at intervals of 1 minute.
While I suspect the delay originates from within the function app only and not from event hub itself, but I haven’t verified this yet. To validate this assumption, I plan to write a simple .NET application to listen to events from the hub.
In the meantime, are there any further changes I can implement to potentially reduce this delay?