繁体   English   中英

通过PHP优化批量上传到Rackspace云文件

[英]Optimizing Bulk Uploads to Rackspace Cloud Files via PHP

我们有一个应用程序可以解析来自外部源的数据并将其本地化,从而保存和调整图像的大小,这是该过程的最后一步。 考虑到我们处理的大小[到目前为止,已有200万张图片],我们一直在使用Rackspace Files托管数据...

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

其他一些要点:

  1. 我们的处理服务器也位于Rackspace的云中。
  2. 总共有5种图片版本,范围从30kb到2kb
  3. 所有图像在传输前已保存到磁盘,并在传输后删除
  4. 我们的容器[我们使用多个容器,但每个容器一个]已启用CDN

有人对批量转移到Rackspace有建议吗? 经过一定时间/数量的请求后,我们应该重新连接吗? 通过其他方式优化我们的连接? 还是仅仅是分叉流程并运行大量呼叫。

您是否尝试过使用CloudFuse? 它允许您将Rackspace CloudFiles存储桶安装为安装。

我已经用过了,它非常好-使它适用于Rackspace的人。

http://sandeepsidhu.wordpress.com/2011/03/07/mounting-cloud-files-using-cloudfuse-into-ubuntu-10-10-v2/

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM