Clip loading is very slow (unicorn)

Sitting here with a simple rail 3 application, in which I have a simple gallery model, and each gallery has many images. The image model is expanded with a paper clip and with the following parameters

has_attached_file :local, :styles => { :large => "800x800>", :medium => "300x300>", :thumb => "100x100#", :small => "60x60#" } 

In my galleries_controller I have the following action that is implemented to work with the jQuery-File-Upload plugin. so the answer is json.

 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 

For me it's pretty straight forward. But there is a problem. In development for mongrel, any type of upload works with just 500-1000ms / upload.

However, when I push it to production, I constantly get timeouts for my unicorns, and when it sends an image through it, it takes 30 to 55 seconds for a single file.

download files about 100 thousand in size

I did some bandwidth testing between my VPS and my witH ipref dev computer and got an average speed of about 77 Kbps, so downloading should not be a problem.

Note. I also checked the test with downloading a file without ajax using the same application with a user model that has an avatar. Development => Completed 302 Found in 693ms Production => Completed 302 Found in 21618 m.

Has anyone encountered a similar problem while downloading files (rails3, unicorn)?

+4
source share
2 answers

So, after digging, I was able to determine that on my VPS it was the OpenMP option in ImageMagick, which caused very slow operation. So, my first attempt was to restore the native Ubuntu 10.04 package with the -disable-openmp flag added. For some reason this failed, and so far I'm not sure why the package continued to work with openMP, still active. Now my current solution is instead of backing up ImageMagick from Ubuntu 10.10. Following are 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 change the rules

 $ cd imagemagick-6.6.2.6 $ vim debian/rules 

Add a description line to the file. / configure on line 25-39. I added mine on line 34.

 34: --disable-openmp \ 

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

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

Step 5 Exit with the old, 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 Perform Quick Image Conversions Again

 _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 
+4
source

If processing takes a lot of time, consider processing thumbnails in individual workers.

Request: accept file; save it to disk; send the task to the queue Worker: pop task from the queue; create sketches; replay

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

0
source

Source: https://habr.com/ru/post/1344835/


All Articles