[英]Get container sizes in Azure Blob Storage using Python
I am trying to use block_blob_service
library in Python in order to get the sizes of all containers in an Azure blob storage. 我试图在Python中使用block_blob_service
库,以获取Azure blob存储中所有容器的大小。 The following works, but takes too long (around 10 minutes for 50TB blob). 可以执行以下操作,但是花费的时间太长(50TB blob大约需要10分钟)。
Is there a quicker way? 有没有更快的方法?
block_blob_service = BlockBlobService(account_name=azureAccount, account_key=azurekey)
containers = block_blob_service.list_containers()
for c in containers:
contName = c.name
generator = block_blob_service.list_blobs(contName)
contSize = 0
contNum = 0
for blob in generator:
contSize += blob.properties.content_length
contNum += 1
print(contName + " : " + str(contSize/1000000) + " MB" + " in " + str(contNum) + " blobs")
In addition to the SDK, you can use PowerShell script or a CLI script to get container size. 除了SDK,您还可以使用PowerShell脚本或CLI脚本来获取容器大小。
Also , you can view the container size on the portal directly. 另外,您可以直接在门户上查看容器的大小。
I think the main issue of executing so long is that the storage blobs are too fragmented to increase the number of loops, compared to the capacity of the storage blobs. 我认为执行如此长时间的主要问题是,与存储blob的容量相比,存储blob过于分散,无法增加循环数。
So , I suggest you put the calculation in Azure Function to ease the pressure of your application. 因此,我建议您将计算结果放入Azure Function中,以减轻应用程序的压力。
Hope it helps you. 希望对您有帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.