2012-07-10 90 views
0

我們有一個應用程序,用於解析外部數據源中的數據並將其本地化,保存和調整圖像大小作爲過程的最後一步。由於我們處理的大小[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

一些附加要點:

  1. 我們的處理服務器也位於Rackspace的雲中。
  2. 有5點總映像的版本從各地30KB到2KB
  3. 所有圖像都轉移之前保存到磁盤後
  4. 我們的容器中刪除[我們用幾個整體,但每個項目的一個]的CDN啓用

有沒有人有批量轉移到Rackspace的建議?我們是否應該在一定的時間/數量的請求後重新連接?以其他方式優化我們的連接?或者它只是分解流程並運行大量呼叫。

+0

上傳的圖片大小是多少?可能是那個......我懷疑它。 您是否與Rackspace支持通話?可能值得記錄一張票或使用實時聊天。 – ajtrichards 2012-07-11 21:19:26

+0

圖像相當小...在50kb以下的全尺寸,大拇指幾kb。 Rackspace的支持有一些想法,但這些想法已經到位,我們仍然比我們想要的要慢...... – 2012-07-12 01:01:11

回答

相關問題