问题描述
坐在这里有一个简单的rails 3 app,其中我有一个简单的Gallery模型,每个画廊都有很多图像。图像模型使用回形针和以下选项进行扩展
Sitting here with a simple rails 3 app in which I have a simple Gallery model and each gallery has many images. The image model is extended with paperclip and with the following options
has_attached_file :local,
:styles => {
:large => "800x800>",
:medium => "300x300>",
:thumb => "100x100#",
:small => "60x60#"
}
在我的galleries_controller中,我执行了以下操作:为了使用插件。从而json响应。
In my galleries_controller I have the following action that is implemented in order to work with the jQuery-File-Upload plugin. thereby the json response.
def add_image
gallery = Gallery.find params[:id]
image = gallery.images.new({:local => params[:local]})
if image.save
render :json => {:thumb => image.url(:thumb), :original => image.url}
else
render :json => { :result => 'error'}
end
end
对我而言,这是相当直接的。但问题来了。在Mongrel下的开发中,任何类型的上传都可以正常工作,大约500-1000ms /上传。
To me this is fairly straight forward. But here comes the issue. In Development under mongrel any kind of upload works just fine with about 500-1000ms/upload.
然而,当我把它推向生产时,我经常会得到我的独角兽工作者的超时时间,当它发送一张图像时,一个文件需要30-55秒。
However when I push it in to production I constantly get timeouts of my unicorn workers and when it does send an image through it takes anywhere from 30-55 seconds for one file.
我上传的文件大小约为100k
我做过一些测试我的VPS和我的开发计算机之间的带宽和ipref,平均速度约为77kbps,所以上传应该不是问题。
I have done some testing of the bandwidth between my VPS and my dev computer witH ipref and got an average speed of about 77kbps so the upload should not be a problem.
注意我还使用具有头像的用户模型的相同应用程序进行非ajax文件上传测试。
开发=>已完成302在693ms找到
生产=>已完成302在21618ms找到
Note I also did a test with a non ajax file upload using the same app with user model that has an avatar.Development => Completed 302 Found in 693msProduction => Completed 302 Found in 21618ms
任何人遇到类似问题(rails3,unicorn)文件上传?
Anyone experienced a similar issue with (rails3, unicorn) file uploads?
推荐答案
所以在挖掘之后我设法确定在我的VPS上是ImageMagick中的OpenMP选项导致操作非常慢。所以我的第一次尝试是重建原生Ubuntu 10.04包,并添加了--disable-openmp标志。由于某种原因,这失败了,虽然我不确定为什么打包出来的openMP仍然有效。我现在的解决方案现在是从Ubuntu 10.10向后移植ImageMagick。以下是我采取的步骤:
So after digging around I managed to determine that on my VPS it was the OpenMP Option in ImageMagick that was causing the very slow operation. So my first attempt was to rebuild the native Ubuntu 10.04 package with the --disable-openmp flag added. This failed for some reason and while I am not sure why the package kept comming out with openMP still active. My current solution is now instead to backport ImageMagick from Ubuntu 10.10. Below follows the steps I took:
第1步下载以下文件:
- imagemagick_6.6.2.6-1ubuntu1.1.dsc
- imagemagick_6.6.2.6.orig.tar.bz2
- imagemagick_6.6.2.6-1ubuntu1.1.debian.tar.bz2
来自
第2步解包
$ dpkg-source -x imagemagick_6.6.2.6-1ubuntu1.1.dsc
第3步编辑规则
$ cd imagemagick-6.6.2.6
$ vim debian/rules
将以下行添加到第25-39行的./configure规则中。我在第34行添加了我的。
Add the the follwing line to the ./configure statment on line 25-39. I added mine on line 34.
34: --disable-openmp \
第4步添加依赖项和构建(我需要这些依赖项)
Step 4 add dependencies and build ( I needed these dependencies)
$ sudo apt-get install liblqr-1-0-dev librsvg2-dev
$ dpkg-buildpackage -b
第5步使用旧的,使用新的
$ sudo apt-get remove --purge imagemagick
$ sudo dpkg -i libmagickcore3_6.6.2.6-1ubuntu1.1_amd64.deb
$ sudo dpkg -i libmagickwand3_6.6.2.6-1ubuntu1.1_amd64.deb
$ sudo dpkg -i imagemagick_6.6.2.6-1ubuntu1.1_amd64.deb
第6步再次进行快速图片转换
Step 6 Once again have fast image conversions
_before_ (with openmp)
$ time utilities/convert 'image.jpg' -resize "x60" -crop "60x60+10+0" +repage 'thumb'
real 0m11.602s
user 0m11.414s
sys 0m0.069s
_after_
$ time utilities/convert 'image.jpg' -resize "x60" -crop "60x60+10+0" +repage 'thumb'
real 0m0.077s
user 0m0.058s
sys 0m0.019s
这篇关于用回形针上传很慢(独角兽)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!