Reputation: 13
Currently I'm getting all blobs in a list from container and then sorting it based on LastModified property. In case of large number of blobs in container, it's giving performance issue.
IEnumerable<IListBlobItem> blobsList = _sourceBlobStorageClient.BlobContainer.ListBlobs(null, false);
var blobItem = blobsList.Cast<CloudBlockBlob>().OrderBy(s => s.Properties.LastModified);
Upvotes: 1
Views: 1160
Reputation: 13
Hi Thanks for the responses. As Zhaoxing mentioned there is no better way. I am using a workaround by introducing a container as staged container. So whatever the number of blobs fetched in first call, I am moving to this staged container and processing it from their. Using this approach I was able to save on listBlobs() call and hence I was seeing improvement in performance as well.
Upvotes: 0
Reputation: 3293
According to your description, you worry about the performance issue of retrieving the oldest blob from a container when there are a large number of blobs in container. As Zhaoxinglu mention, there is no better way to achieve this. From my experience, we can try below workaround to improve the performance.
Since the blob’s name could contain ‘/’ or ‘\’ characters that are interpreted as folders by many apps that read the blob, we could try to use this feature to improve the performance.
The basic idea is as follows:
a) According to the Modified-Time of the blob to store the blob in the directories formatted as “{docs}/{year}/{month}”;
b) Using the prefix associated with the Modified-time of the blob to avoid listing all blobs in the container.
Please refer to the following steps to see whether it could help you.
You could design your blob as follows:
When you want to retrieve the oldest blob, you could refer to the following code:
var results = (from blob in container.ListBlobs(prefix: "docs/2016/1/", useFlatBlobListing: true)
orderby ((CloudBlockBlob)blob).Properties.LastModified
select blob).FirstOrDefault();
Hope it could help you and please let me know if you have any questions about the above steps.
Upvotes: 0