Closed tarikguney closed 5 years ago
Based on https://docs.microsoft.com/en-us/azure/cosmos-db/change-feed-processor#implementing-the-change-feed-processor-library, the work can be parallelized based on the multiplicity of partition key values (https://docs.microsoft.com/en-us/azure/cosmos-db/partition-data#logical-partitions). The more diversity and cardinality of your partition key values, the further the scaling capabilities of the library.
In your case, your container seems to be either fixed (no partition key) or contains a single partition key value, thus, you only have 1 lease. The lease is the distributable unit of work for the library. If you have X leases, and 1 host, that host will own and process in parallel all leases. If you scale to more hosts, the leases will get equally distributed and compute will get also distributed. But it all depends on your data distribution.
I don't agree with the assumption that my container has fixed size and one partition key. It has more.
Also this the settings of the container:
If your leases container only contains 1 document with a PartitionId
(which is not really the partition, just the name used to reference the partitioned unit of work) and that value is 0
, it means the container only contains 1 Partition Key value range so far.
It could be that it was a fixed container, which you correctly dismissed, but it also could mean that the diversity and granularity of your Partition Key values is not big enough.
The logic inside the library uses this as unit of parallelism and that is referenced in the graphic in the official docs, each range of values can be assigned to 1 host.
seeing the same behavior on my part (using cosmos db change feed trigger with consumption plan functions in c#).
Im guessing this is because of the physical vs logical (partitionId) partitions.
My collection has 5mil rows, with 73k different partitionIds. The partitionkey is a guid.
A changefeed processor will only manage to create 1 partition lease, for partition 0.
Can someone confirm that this is the case? Or point me to some documentation that speaks of when you actually can paralellize workers on the same colletion (not as in creating workers with different lease-prefixes).
Thx!
The monitored collection has a partition key that creates multiple virtual partitions. Also, I have created multiple hosts, but I keep getting only one partition debug message, also the work is not distributed at all.
Here is what I am seeing all the time:
The code I am using is very simple:
I am running the code above from within different processes. What I have observed is that there is not parallelization in different work distribution among various hosts. It is only one host that takes on the work no matter how many hosts and partitions are there. The only slight work distribution I observed happens when a host fails, and one of the other hosts take over and start acting similar: Working only by itself while the other hosts are doing nothing but waiting. So I debugged your library, and the library creates a lease (which turns out to be a lease document on the given lease collection). However, I always see only one lease document is being created.
As opposed to what's actually happening, here is what the documentation says: https://docs.microsoft.com/en-us/azure/cosmos-db/read-change-feed#using-the-change-feed-processor-library
From the documentation above and the source code that I analyzed, I am supposed to see multiple lease documents being created. Nevertheless, this the response when the library makes call to Cosmos DB instance to get the
pkranges
of the monitored collection. This seems to be the root of the problem here as the lease documents, when missing, are created based on the response.The below is where the request is made in the library's source code that returns the response above: