简体   繁体   English

Amazon S3和jqueryfileupload插件的图像上传性能问题

[英]Image upload performance issue with Amazon S3 and jqueryfileupload plugin


I have another issue with amazon and its related to file uploads.I am using jqueryFileUpload and amazon API's to uplaod files to amazon S3.I have succeeded in uploading it,but it involves a trick. 我还有另一个关于亚马逊及其与文件上传有关的问题。我正在使用jqueryFileUpload和亚马逊API将文件升级到亚马逊S3。我已经成功上传了文件,但这涉及到一个技巧。
I had to store the image on my server and then move it to S3 from there using putObjectFile method of S3.Now the plugin comes with great functions to crop/resize images and I have been using them since long.Now when I integrate the plugin with AWS,i am facing performance issues with upload.The time taken for uploads is longer than normal and this raises questions of us using AWS S3 over traditional way. 我不得不将图像存储在服务器上,然后使用S3的putObjectFile方法将其从那里移到S3。现在,该插件具有强大的功能来裁剪/调整图像大小,并且我已经使用了很长时间了。现在,当我集成插件时使用AWS时,我在上传时遇到性能问题 。上传所花的时间比平时长,这引起了我们在传统方式下使用AWS S3的疑问。
I had to make changes to my UploadHandler.php file to make it work.These are the changes made.i added a part of AWS upload code to the file from line 735 to 750 我必须对我的UploadHandler.php文件进行更改以使其正常工作。这些是所做的更改。我从第735到750行向该文件添加了一部分AWS上传代码

     $bucket = "elasticbeanstalk-2-66938761981";
     $s3 = new S3(awsAccessKey, awsSecretKey);
     $response = $s3->putObjectFile($file_path,$bucket,$file->name,S3::ACL_PUBLIC_READ);
     $thumbResponse = $s3->putObjectFile('files/thumbnail/'.$file->name,$bucket,'images/'.$file->name,S3::ACL_PUBLIC_READ);
     //echo $response;
     //echo $thumbResponse;
     if ($response==1) {
        //echo 'HERER enter!!';
     } else {
          $file->error = "<strong>Something went wrong while uploading your file... sorry.</strong>";
     }
     return $file; 

Here is a link to s3 class on git. 是git上s3类的链接。 The normal upload to my current server(not amazon),same image uploads in 15 secs ,but on amazon S3 it takes around 23 secs and I am not able to figure out a better solution.I have to store the image on my sever before uploading to S3 as I am not sure if I can process them on the fly and upload directly to S3. 正常上传到我当前的服务器(非亚马逊),相同的图像在15秒内上传,但是在亚马逊S3上大约需要23秒 ,我无法找到更好的解决方案。我必须将图像存储在服务器上上传到S3,因为我不确定是否可以即时处理它们并直接上传到S3。
Can anyone suggest the right way to approach the problem?Is it possible to resize the images to different sizes in memory and upload directly to S3 avoiding the overhead of saving it to our server?If yes can anyone guide me in the right direction? 有人可以提出解决问题的正确方法吗?是否可以将图像大小调整为内存中的不同大小并直接上传到S3,从而避免将其保存到我们的服务器的开销?如果是,有人可以指导我正确的方向吗?
Thank you for the attention. 谢谢您的关注。

I believe the approximate 8secs is the overhead here for creating versions of image in different sizes. 我相信大约8秒是创建不同大小的图像版本的开销。 You may take different approaches to get rid of the resizing overhead at time of upload. 您可以采取不同的方法来消除上载时的调整大小开销。 The basic idea will be to allow the uploading script to finish execution and return the response, and do the resizing process as a separate script. 基本思想是允许上载脚本完成执行并返回响应,并作为单独的脚本进行调整大小的过程。

I like to suggest following approaches: Approach 1. Don't resize during the upload! 我想建议以下方法:方法1.不要在上传过程中调整大小! Create resized versions on-the-fly only when it is being requested for the first time and cache the generated images to serve directly for later requests. 仅在首次请求时即时创建调整大小的版本,并缓存生成的图像以直接用于以后的请求。 I saw a few mentions of Amazon CloudFront as a solution in some other threads in Stackoverflow. 我在Stackoverflow的其他一些线程中提到了Amazon CloudFront作为解决方案。

Approach 2. Invoke the code for creating resized versions as a separate asynchronous request after the upload of original image. 方法2.在上传原始图像后,将用于创建调整大小版本的代码作为一个单独的异步请求调用。 There will be a delay in scaled versions being available. 缩放版本可用会有延迟。 So write necessary code to show some place holder images in the website until the scaled versions become available. 因此,编写必要的代码以在网站上显示一些占位符图像,直到获得缩放版本为止。 You will have to figure out some way to identify whether scaled version is available yet or not(For example check file is existing, or set some flag in database). 您将必须找出某种方法来确定缩放版本是否可用(例如,检查文件是否存在,或在数据库中设置一些标志)。 Some ways for making asynchronous cURL requests are suggested here if you would like to try it out. 如果您想尝试一下, 这里提出了一些异步cURL请求的方法。

I think both approaches will have equal level of complexity. 我认为这两种方法都将具有相同的复杂度。

Some other approaches are suggested as answers for this other question . 建议使用其他一些方法作为对此问题的答案

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

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