title: Performances on rails
body: <p>I have a problem of performances with rails. When i do an ajax call to a controller like this : </p>
  
  <pre><code>def test
      @hotels = Hotel.all
      render :json =&gt; ['hotels' =&gt; @hotels ], :include=&gt; [:country, :city]
  end
  </code></pre>
  
  <p>It takes maybe 2-5 seconds to finish. I only have 40 hotels in my database. I think it very long... for example, the same request on Django will take 400ms</p>
  
  <p>Did i forgot to configure well my environement?</p>
  
  <p>I use Rails entreprise version and passenger.</p>
  
  <p>EDIT : My log file :</p>
  
  <pre><code>     Started GET "/hotels/test.json" for 172.16.81.1 at Wed Oct 12 22:11:06 +0200 2011
      [paperclip] Duplicate URL for image with /system/:attachment/:id/:style/:filename. This will clash with attachment defined in HotelImage class
      [paperclip] Duplicate URL for thumbnail with /system/:attachment/:id/:style/:filename. This will clash with attachment defined in Hotel class
      [paperclip] Duplicate URL for map with /system/:attachment/:id/:style/:filename. This will clash with attachment defined in Hotel class
      [paperclip] Duplicate URL for thumbnail with /system/:attachment/:id/:style/:filename. This will clash with attachment defined in DestinationAlbumPhoto class
      [paperclip] Duplicate URL for map with /system/:attachment/:id/:style/:filename. This will clash with attachment defined in Destination class
      [paperclip] Duplicate URL for image with /system/:attachment/:id/:style/:filename. This will clash with attachment defined in Continent class
      [paperclip] Duplicate URL for thumbnail with /system/:attachment/:id/:style/:filename. This will clash with attachment defined in Destination class
      [paperclip] Duplicate URL for image with /system/:attachment/:id/:style/:filename. This will clash with attachment defined in Event class
      [paperclip] Duplicate URL for thumbnail with /system/:attachment/:id/:style/:filename. This will clash with attachment defined in HotelAlbumPhoto class
      [paperclip] Duplicate URL for map with /system/:attachment/:id/:style/:filename. This will clash with attachment defined in Event class
        Processing by HotelController#test as JSON
        [1m[36mHotel Load (0.2ms)[0m  [1mSELECT `hotels`.* FROM `hotels`[0m
        [1m[35mCountry Load (0.1ms)[0m  SELECT `countries`.* FROM `countries` WHERE (`countries`.`id` = 3)
        [1m[36mCity Load (0.1ms)[0m  [1mSELECT `cities`.* FROM `cities` WHERE (`cities`.`id` = 2)[0m
      Completed 200 OK in 405ms (Views: 366.1ms | ActiveRecord: 0.3ms)
  </code></pre>
  
  <p>It's writen 405ms but firefox tell me 3,7sec.</p>
  
  <p>My hotel model : </p>
  
  <pre><code>class Hotel &lt; ActiveRecord::Base
    cattr_reader :per_page
    @@per_page = 16
  
    belongs_to :hotel_type
    belongs_to :hotel_theme
    belongs_to :country
    belongs_to :city
    belongs_to :destination
    belongs_to :continent
  
    has_many :hotel_comments, :dependent =&gt; :destroy
  
    has_many :hotel_album_photos, :dependent =&gt; :destroy
  
    has_many :hotel_activity_values
  
    has_many :hotel_service_values
  
    accepts_nested_attributes_for :hotel_album_photos
  
    has_attached_file :thumbnail, :styles =&gt; { :medium =&gt; "300x300&gt;", :thumb =&gt; "191x134&gt;"} , :default_url =&gt; '/images/default/missing.png' 
    has_attached_file :map, :styles =&gt; { :medium =&gt; "300x300&gt;", :thumb =&gt; "191x134&gt;"} , :default_url =&gt; '/images/default/missing.png' 
  
    scope :country, lambda { |country_id|
       self.scoped.where('country_id IN ( ? )', country_id) unless country_id.blank?
    }
  
    scope :selection, lambda { |selection|
       self.scoped.where('selection = ? ', 1) unless selection.blank?
    }
  
    scope :city, lambda { |city_id|
        self.scoped.where('city_id IN ( ? )', city_id) unless city_id.blank?
    }
  
    scope :hoteltype, lambda { |type|
        self.scoped.where('hotel_type_id IN ( ? )', type) unless type.blank?
     }
  
    scope :theme, lambda { |theme|
        self.scoped.where('hotel_theme_id IN ( ? )', theme) unless theme.blank?
     }
  
    scope :prices, lambda { |prices|
        condition = []
        prices.each do |price|
          pricesArray = price.split('-')
          condition.push '(price BETWEEN ' + pricesArray[0] + ' AND ' + pricesArray[1] + ')'
        end
        self.scoped.where(condition.join(' OR ')) 
     }
  
     scope :order_by_price, lambda { |direction|
       self.scoped.order('price ' + direction)
     }
  
     scope :order_by_rate, lambda { |rate|
       self.scoped.order('global_rate ' + rate)
     }
  
     scope :services, lambda { |services|
        {:joins =&gt; [:hotel_service_values ]  , :conditions =&gt; { :hotel_service_values =&gt; {:hotel_service_id  =&gt; services}}}
     }
  
    scope :limiter, lambda { |limiter|
        self.scoped.limit(limiter)
     }
  
  end
  </code></pre>
  
  <p>Thank you for help.</p>