Upload with paperclip very slow (unicorn)

本秂侑毒 提交于 2019-12-05 15:27:19

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:

Step 1 download the following files:

  • 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

from here

Step 2 unpack the package

$ dpkg-source -x imagemagick_6.6.2.6-1ubuntu1.1.dsc

Step 3 edit the rules

$ cd imagemagick-6.6.2.6
$ vim debian/rules

Add the the follwing line to the ./configure statment on line 25-39. I added mine on line 34.

34: --disable-openmp \

Step 4 add dependencies and build ( I needed these dependencies)

$ sudo apt-get install liblqr-1-0-dev librsvg2-dev
$ dpkg-buildpackage -b

Step 5 Out with the old, in with the new

$ 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

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

If processing takes a long time, consider processing the thumbnails in a separate workers.

Request: accept file; save it to disk; post job to queue Worker: pop job from queue; create thumbnails; repeat

Delayed::Job and Resque are great solutions for this.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!