【发布时间】:2017-09-29 04:10:05
【问题描述】:
环境:
- Windows 10 x64
- Ruby 2.1.0 32 位
- 厨师 12.12.15
- 蔚蓝宝石 0.7.9
- Azure-Storage Gem 0.12.1.preview
我正在尝试从容器中下载一个 ~880MB 的 blob。当我这样做时,它会在 Ruby 进程达到约 500MB 大小后引发以下错误:
C:/opscode/chefdk/embedded/lib/ruby/2.1.0/net/protocol.rb:102:in `read': 分配内存失败 (NoMemoryError)
我已经在 Ruby 内外以及 Azure gem 和 Azure-Storage gem 中尝试过。结果对于所有四种组合(Chef 中的 Azure、Ruby 中的 Azure、Chef 中的 Azure-Storage、Ruby 中的 Azure-Storage)都是相同的。
我发现的针对此类问题的大多数故障排除建议使用流式传输或分块下载,但似乎没有相应的方法或 get_blob 选项来执行此操作。
代码:
require 'azure/storage'
# vars
account_name = "myacct"
container_name = "myfiles"
access_key = "mykey"
installs_dir = "myinstalls"
# directory for files
create_dir = 'c:/' + installs_dir
Dir.mkdir(create_dir) unless File.exists?(create_dir)
# create azure client
Azure::Storage.setup(:storage_account_name => account_name, :storage_access_key => access_key)
azBlobs = Azure::Storage::Blob::BlobService.new
# get list of blobs in container
dlBlobs = azBlobs.list_blobs(container_name)
# download each blob to directory
dlBlobs.each do |dlBlob|
puts "Downloading " + container_name + "/" + dlBlob.name
portalBlob, blobContent = azBlobs.get_blob(container_name, dlBlob.name)
File.open("c:/" + installs_dir + "/" + portalBlob.name, "wb") {|f|
f.write(blobContent)
}
end
我也尝试使用 IO.binwrite() 而不是 File.open() 并得到相同的结果。
建议?
【问题讨论】:
标签: ruby azure chef-infra azure-storage azure-blob-storage