我的应用程序需要从GCS桶下载文件,我可以使用StorageClient DownloadObjects方法从GCS下载文件。但是表演真的很慢。对于50 by的文件大小,它需要3-4分钟,这一时间因hugh时间差而变化。请查找示例代码,并让我知道如何提高下载性能?
类程序{公共静态空主(string[] args) {
GoogleCredentials gcpCreds = new GoogleCredentials()
{
private_key = "-----BEGIN PRIVATE KEY-----PrivateKey-----END PRIVATE KEY-----\n",
client_email = "client_email",
type = "service_account"
};
var credentials = GoogleCredential.FromJson(JsonConvert.SerializeObject(gcpCreds));
// var credentials= GoogleCredential.GetApplicationDefault();
var storage = StorageClient.CreateAsync(credentials).Result;
string localPath, directoryPath, localFileName, objectName, bucketName;
directoryPath = "localpathstring";
objectName = "SourceFileName";
localFileName = objectName;
localPath = directoryPath + "\\" + localFileName;
bucketName="bucketName";
FileStream fs = new FileStream(localPath, FileMode.OpenOrCreate);
//Code to download with progress bar
DownloadObjectOptions option = new DownloadObjectOptions();
using (fs)
{
var progress = new Progress<IDownloadProgress>(
p => Console.WriteLine($"bytes: {p.BytesDownloaded}, status: {p.Status},"));
storage.DownloadObject(bucketName, objectName, fs, option, progress);
}
}发布于 2019-11-12 16:44:13
您正在经历的延迟问题可能来自应用程序、网络(您自己的或Google的)或云存储服务。要确定根本原因,以下是一些步骤:
mtr -4 -n -r -c 10 www.googleapis.comgsutil perfdiag -o output.json gs://your-bucket如果结果显示了健康的指标,那么尝试异步下载文件是值得的。最后,这里是一些优化云存储性能的技巧。
https://serverfault.com/questions/991364
复制相似问题