我们有一个应用程序,用于解析外部数据源中的数据并将其本地化,保存和调整图像大小作为过程的最后一步。由于我们处理的大小[2万张图片,以日期]我们一直在使用Rackspace公司档案托管数据...通过PHP优化批量上传到Rackspace云文件
require('/var/libs/rackspace/cloudfiles.php');
$auth = new CF_Authentication('xxx', 'yyyy');
$auth->authenticate();
$conn = new CF_Connection($auth,true);
$container = $conn->get_container('some container');
foreach ($lotsofitems as $onitem){
// check the record
// save the image to disk with cURL
// resize it into 4 more versions
// post it to rackspace
if(file_exists('/var/temp/'. $image_id . '_full'. $image_type)){
$object = $container->create_object($image_id . '_full' . $image_type);
$object->load_from_filename('/var/temp/'. $image_id . '_full' . $image_type);
unlink('/var/temp/'. $image_id . '_full' . $image_type); // remove the temp save
}
if(file_exists('/var/temp/'. $image_id . '_big'. $image_type)){
$object = $container->create_object($image_id . '_big' . $image_type);
$object->load_from_filename('/var/temp/'. $image_id . '_big' . $image_type);
unlink('/var/temp/'. $image_id . '_big' . $image_type); // remove the temp save
}
if(file_exists('/var/temp/'. $image_id . '_med'. $image_type)){
$object = $container->create_object($image_id . '_med' . $image_type);
$object->load_from_filename('/var/temp/'. $image_id . '_med' . $image_type);
unlink('/var/temp/'. $image_id . '_med' . $image_type); // remove the temp save
}
// delete the original
// repeat
}
优化我们的解析器,GD等之后,我们的基准测试程序和处理图像需要大约1秒钟,但将5个图像变化传送到Rackspace的每个项目需要2-5秒,并且有时会高达10+。
- 获取图像:1341964436
- 得到的图像:1341964436
- 调整后的图像:1341964437
- 笼罩一幅图像:1341964446
- 云图像:1341964448
- 完成了图像:1341964448
一些附加要点:
- 我们的处理服务器也位于Rackspace的云中。
- 有5点总映像的版本从各地30KB到2KB
- 所有图像都转移之前保存到磁盘后
- 我们的容器中删除[我们用几个整体,但每个项目的一个]的CDN启用
有没有人有批量转移到Rackspace的建议?我们是否应该在一定的时间/数量的请求后重新连接?以其他方式优化我们的连接?或者它只是分解流程并运行大量呼叫。
上传的图片大小是多少?可能是那个......我怀疑它。 您是否与Rackspace支持通话?可能值得记录一张票或使用实时聊天。 – ajtrichards 2012-07-11 21:19:26
图像相当小...在50kb以下的全尺寸,大拇指几kb。 Rackspace的支持有一些想法,但这些想法已经到位,我们仍然比我们想要的要慢...... – 2012-07-12 01:01:11