When I recently rewrote our app at work into a multi tenant app I ran in to the problem of the action_mailer views. Since the app
started out it’s life as a single tenant app most of the mails had to be changed but also had to remain the same for the app still there
My first idea was to just configure the template_root of ActionMailer in my new Environment but just after this was done the requirement
came that each tenant might want to customize these views. so instead of changing the template_root depending on the tenant I googled around
and found a solution for adding the nice view_path method we already have for the ActionController.
The original post can be found here but I thought I would show my implementation below. Basically a compilation of the original poster and the comments given
to that post
This week I was adding a galleries to a rails site that I am working on and for some reason on my production server, each time I tried to upload an image it failed and I got returned a 502 response from my server. The thing was that even though I was looking at my logs I saw no request even being made to the server.
I finally got an image to upload and could see in my logs that the action took in excess of one minute to complete which led my Rails worker (unicorn) to time out and return the aforementioned 502 error response. As I went through the call stack I could determine that the bottleneck was ImageMagick and especially the calls to the convert method.
I did some testing and could confirm what I had determined in the logs:
1234
$ time utilities/convert 'image.jpg' -resize "x60" -crop "60x60" +repage 'thumb'
real 0m11.602s
user 0m11.414s
sys 0m0.069s
11 seconds to scale and crop an image, that’s just insanly slow!!!
I did some googleing and found rumors that openmp, that is activated by default in ImageMagick and helps to make use of modern CPUs multi core architecture sometimes could cause issues in a virtualized environment wich is exactly what I am running on.
So I went out and got the latest version of the ImageMagick source, compiled it with the —disable-openmp flag and redid the test with this binary:
1234
$ time utilities/convert 'image.jpg' -resize "x60" -crop "60x60" +repage 'thumb'
real 0m0.077s
user 0m0.058s
sys 0m0.019s
That’s more like it, don’t you agree. All I know had to do was to install this version on to my server. However as I am running Ubuntu 10.04 so I’d like to keep with the package system. For some reason I was not able to get the 10.04 package of ImageMagick to accept the —disable-openmp flag so, in the end I backported the package from Ubuntu 10.10 instead. please find the steps below: