从 AWS S3 下载一个 700 KB 的图像文件大约需要 7.5 秒。
我编写了这个方法来从 AWS S3 下载图像:
+ (UIImage *)downloadImageFromPath:(NSString *)path
{
NSDate *methodStart = [NSDate date];
S3GetObjectRequest *getObjectRequest = [[S3GetObjectRequest alloc] initWithKey:path withBucket:AWS_BUCKET];
AmazonS3Client *s3 = [[AmazonS3Client alloc] initWithAccessKey:ACCESS_KEY_ID withSecretKey:SECRET_KEY];
S3GetObjectResponse *response;
@try
{
response = [s3 getObject:getObjectRequest];
}
@catch(NSException* ex)
{
return [UIImage imageNamed:@"blank.jpg"];
}
NSData *data = response.body;
UIImage *image = [UIImage imageWithData:data];
NSDate *methodFinish = [NSDate date];
NSTimeInterval executionTime = [methodFinish timeIntervalSinceDate:methodStart];
NSLog(@"executionTime = %f", executionTime);
return image;
}
我只是在方法的开头和结尾添加了代码。
正如我上面提到的,它需要大约 7.5 秒才能完成。
我使用 GCD 在后台运行它,DISPATCH_QUEUE_PRIORITY_HIGH
它运行时队列中没有其他内容。
有谁知道为什么要花这么长时间?很乐意提供更多信息。