FeedPollDelay in ChangeFeedProcessorOptions is not respected
See original GitHub issueHello everybody,
Describe the bug
When FeedPollDelay in CosmosDBTrigger is used (which uses ChangeFeedProcessorOptions) delay is not respected by the change feed mechanism. Calls to the leases
collections are made every few seconds.
To Reproduce ChangeFeedProcessorOptions looks as follows:
public class Func
{
public const int FiveMinutesInMiliseconds = 300000;
[FunctionName("Func")]
public async Task Run([CosmosDBTrigger(
databaseName: "databaseName",
collectionName: "collectionname",
ConnectionStringSetting = "COSMOSDB_CONNECTION_STRING",
LeaseCollectionName = "leases",
CreateLeaseCollectionIfNotExists = true,
FeedPollDelay = FiveMinutesInMiliseconds)]
In the Azure Func option I see that option is set correctly:
There were no runs of the function between 9:15 and 9:40:
but then in CosmosDB Logs I see that the feed mechanism runs every single second
I tried to clean lease collection, stop and start a function - nothing helped.
Expected behavior
A single function call to the leases
collection every 5 minutes.
Actual behavior
A lot of calls to the leases
collection.
Environment summary
ActivityId to track function run - 6f6d4528-86fa-404a-9a34-7f0a9afc6fdf
Time when happened - 2021-01-19T09:22:32.782Z
Issue Analytics
- State:
- Created 3 years ago
- Comments:15 (7 by maintainers)
Top GitHub Comments
@rmaziarka
I do not have access to the Consumption Plan details and internal workings, what I am saying is that, if you are on Consumption Plan, then I know the Functions runtime checks the estimation and know if they need to scale up/down. If there are no more events in your Change Feed for more than 5-10 minutes, Consumption Plan scales down and shuts down all instances. But periodically (I have no clue how often, it could be every 10 seconds) they would use the Estimator APIs, to know if there are any new changes and “wake up” instances to process them, this is not a hunch, this actually happens, so it could be very well the source of these queries. All this logic is completely external to Cosmos DB or the Cosmos DB Trigger, so there is nothing you can configure as far as I know (you could ask the Functions team through a support ticket maybe if the period they use to check is configurable). My only hunch based on the screenshot you pasted is the User Agent. At the end, it says
changefeed-2.2.1
, meaning the source is using the Change Feed Processor nuget 2.2.1, in your Function App project, you probably have the Cosmos DB extension nuget, which has a dependency on the CFP nuget, if your version does not match (for example, yours is higher), then it would confirm the suspicion that it’s coming from there.Regarding your second question, all those docs are for the Change Feed Processor, not related to Azure Functions Cosmos DB Trigger. Consumption Plan uses the CFP nuget and this API as far as I know:
If your intent is to check if it’s the same query, you could do the same from a console app.
@rmaziarka This is the wrong repo, don’t you mean to send this to the Functions repo? https://github.com/Azure/azure-webjobs-sdk-extensions
In any case, this is not a bug and that setting does not measure the calls to the Leases collection.
The leases collection is used to store state. State is updated frequently, whenever your code finishes processing some changes, and periodically to refresh ownership of the leases by the current instance.
The FeedPollDelay affects Change Feed requests to the Monitored Collection (doesn’t affect any interaction with the leases collection). And only applies when the Change Feed is checked and there are no changes. See the official docs: https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-cosmosdb-v2-trigger?tabs=csharp#configuration
For more details on the Change Feed Processor see: https://docs.microsoft.com/en-us/azure/cosmos-db/change-feed-processor