gpt4 book ai didi

Azure Powershell : How Do I search for files in a BLOB storage quickly?

转载 作者:行者123 更新时间:2023-12-03 05:21:11 28 4
gpt4 key购买 nike

我们将日志文件存储在 Azure 存储帐户中,按目录、日期和客户排序,如下所示:

YYYY/MM/DD/customerNo/.../.../somestring.customerNo.applicatoinID.log

我需要每天自动解析其中一些文件,效果很好。不过,我只知道上面提到的前缀和后缀,它们可能位于不同的子目录中。

所以我就是这样做的:

$files = (Get-AzStorageBlob -Container logfiles -Context $context) | Where-Object { $_.Name -like "$customerId.$appID.txt" }

虽然没有任何日志文件,但速度很快,但一年后,这个搜索需要很长时间。我读过somewhere按前缀搜索比按后缀搜索更快。不幸的是,我必须使用后缀,但我现在也使用日期作为前缀。我尝试通过这样做来改进它:

$date = Get-Date -UFormat "%Y/%m/%d"
$prefix = "$date/$customerId/"
$files = (Get-AzStorageBlob -Container logfiles -Context $context) | Where-Object { $_.Name -like "$prefix*$customerId.$appID.txt" }

但是,并没有任何改善,只是时间和以前一样长。而且感觉搜索所花费的时间随着日志文件的数量呈指数级增长(几十GB中就有几十万)

我收到一条状态消息,该消息实际上在那里停留了半个小时:

enter image description here

据我了解,Azure 的 BLOB 存储没有支持文件夹的分层文件系统,因此“/”是 BLOB 名称的一部分,并被客户端软件解释为文件夹。

但是,这并不能帮助我加快搜索速度。对于如何改善这种情况有什么建议吗?

最佳答案

Azure Blob 存储支持服务器端按前缀过滤 blob,但您的代码并未利用这一点。

$files = (Get-AzStorageBlob -Container logfiles -Context $context) | Where-Object { $_.Name -like "$prefix*$customerId.$appID.txt" }

上面的代码本质上是列出所有 blob,然后在客户端进行过滤。

为了加快搜索速度,请将您的代码修改为:

$files = (Get-AzStorageBlob -Container logfiles -Prefix $prefix -Context $context) | Where-Object { $_.Name -like "$prefix*$customerId.$appID.txt" }

我只是在 Prefix 参数中传递了前缀。现在,您将仅收到以前缀 开头的 blob 名称。

关于Azure Powershell : How Do I search for files in a BLOB storage quickly?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72216803/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com