与Amazon S3和jqueryfileupload插件图片上传性能问题 [英] Image upload performance issue with Amazon S3 and jqueryfileupload plugin

查看:203
本文介绍了与Amazon S3和jqueryfileupload插件图片上传性能问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我还有一个问题,亚马逊和它的uploads.I正在使用提交相关 jqueryFileUpload 和亚马逊的API来uplaod文件到Amazon S3.I已经成功上传它,但它涉及的把戏。
     我必须保存我的服务器上的图像,然后将其移动到S3从那里使用S3.Now的 putObjectFile 方法插件自带大功能裁剪/调整图像和我一直在使用他们,因为long.Now当我整合插件使用AWS,我面对的性能问题与服用上传upload.The时间比平时长,这提高了使用AWS的S3在我们的问题传统方式。
     我不得不做出改变我的 UploadHandler.php 文件,以使其work.These是改变made.i从行加入AWS上传code的一部分,以文件的 735至750


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.
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.
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

     $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; 

这里是一个链接到S3类的混帐。 正常上传到我目前的服务器(不是亚马逊),在 15秒相同的图片上传,但在亚马逊S3大约需要 23秒,我不能够找出更好的solution.I必须上传到S3之前,我的服务器对图像存储,因为我不知道我是否能够处理它们的在飞行并直接上传到S3。
任何人都可以提出以正确的方式来处理这个问题?是否有可能调整图像以不同大小的内存,并直接上传到S3避免将其保存到我们的服务器吗?如果有任何人能指导我的方向是正确的开销?
感谢您的关注。

Here is a link to s3 class on git. 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.
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?
Thank you for the attention.

推荐答案

我相信大概8secs是这里的开销用于创建图像的不同大小的版本。 你可以采取不同的方法来摆脱调整的开销在上传的时候。其基本思想是允许上传脚本执行完成并返回响应,并做调整进程作为一个单独的脚本。

I believe the approximate 8secs is the overhead here for creating versions of image in different sizes. 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.

我想建议以下方法:  方法1在上载过程中不调整!创建于即时,只有当它被要求在第一次和缓存生成的图像,直接服务于更高的要求调整大小的版本。我看到几个亚马逊CloudFront的中提到在一些其他线程的中计算器。

I like to suggest following approaches: Approach 1. Don't resize during the upload! 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.

2,方法调用$ C $下创建大小版本为原始图像的上传后的一个单独的异步请求。有将在缩放的版本是可用的延迟。所以写需要code,显示在网站上一些占位符图像,直到缩放版本可用。你将不得不想出一些方法来确定缩放版本是否可用但还是没有(例如检查文件的存在,或者设置一些标志数据库)。一些途径<一个href="http://stackoverflow.com/questions/5453192/is-making-asynchronous-http-requests-possible-with-php">making异步卷曲请求建议此处如果您想尝试一下。

Approach 2. Invoke the code for creating resized versions as a separate asynchronous request after the upload of original image. 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.

我觉得这两种方法都会有复杂的同等水平。

I think both approaches will have equal level of complexity.

其他的一些方法被认为是回答这个问题,其他

Some other approaches are suggested as answers for this other question.

这篇关于与Amazon S3和jqueryfileupload插件图片上传性能问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆