views:

195

answers:

2

I've been trying to improve performance our app. The worst performing area seems to be the creation of our Image model, which uses attachment_fu:

class Image < Attachment

  ...

  has_attachment :content_type => :image,
    :max_size => 100.megabytes,
    :storage => :file_system,
    :path_prefix => 'public/uploaded/images',
    :thumbnails => { :small => '75x75>', :medium => '160x120>', :large => '600x600>' },
    :s3_access => :authenticated_read

  validates_as_attachment

  after_create :move_to_s3

  ...

We've already moved the move_to_s3 method to a delayed_job.

Our apdex score on this transaction is horrible (often < 0.5) and it's taking 1 to 2 seconds.

How else can I improve the creation of Image records (speed-wise)?

I may be able to do without the :small thumbnail? Would it help to drop that?

If it helps, most of these files are high-res images. Does the upload time factor into the metrics I have? Is it skewing the reports?

+1  A: 

I would save the image directly to S3, then created a delayed job to download it, resize it, and put the thumbnails back in S3.

To show the image on the next page load, just link to the large version and resize it via css.

Also, yes, the fewer sizes you need, the less processing it will take.

BJ Clark
Uploading the images directly to S3 is probably out of the question–partially because we also allow users to FTP images to our server (we then import them from their FTP folder).
Callmeed
A: 

You could use mod_porter to let the webserver handle the upload, instead of your app.

This isn't going to "speed up" anything, but it will keep one of your app servers from blocking until the file is actually uploaded.

BJ Clark