2014-09-17 2 views
0

최근에 ActiveAdmin 응용 프로그램에 약 50,000 개의 레코드를 가져 왔는데 현재 성능이 매우 좋지 않습니다. ActiveAdmin이이 양의 레코드를 처리하도록 설계 되었습니까?ActiveAdmin의 성능이 매우 좋지 않음

사용하지 않는 필터에 대해 remove_filter을 추가하여 성능이 약간 향상되었습니다.

나는 어떤 성능 문제를 일으킬 수있는 연관성이 없음을 알고 있습니다. 내 모델 구조는 단일 테이블 상속을 사용하는 두 개의 하위 클래스로 완전히 평평합니다.

내가 사용하고 있습니다 :

ruby '2.1.1' 

    gem 'rails', '4.1.0' 

    gem 'activeadmin', github: 'activeadmin' 

나는에게 Heroku에 배포 응용 프로그램을 가지고있다. 나는 Heroku에서 몇 가지 로그를 아래쪽에 삽입했습니다. 이 타임 아웃이 경우, 자원을로드 할 때

다음
ActiveAdmin.register Product do 
    menu :label => "All Products", :priority => 1 

    config.clear_action_items! 

     permit_params :name, :link, :category, :image_url, :price, :interest, :interest_changes, :revenue, :start_date, :end_date, :company, :country, :price_eur, :price_gbp, :price_aud, :price_nzd, :price_cad 


       # Input 

     form do |f| 
     f.inputs 'Details' do 

      f.input :country, :as => :string 
      f.input :category 

    end 
    f.actions 
    end 

    # Scopes 
    scope :upward_trending, :default => true 
    scope :downward_trending 
    scope :all 

    # Default Sort 
    config.sort_order = "end_date_desc" 

    index do 
     column "Product Name", :sortable => :name do |a| 
      link_to a.name, a.link, :target => "_blank" 
     end 
     column "Image" do |a| 
      div :class => "image_url" do 
       link_to (image_tag a.image_url, class: 'image_url'), a.image_url, :target => "_blank", class: 'fancybox' 
      end 
     end 

     column "Price", :sortable => :price_eur do |a| 
      div :class => "number" do 
       case current_user.currency 
        when 'EUR' 
         number_to_currency(a.price_eur, unit: "€") 
        when 'GBP' 
         number_to_currency(a.price_gbp, unit: "£") 
        when 'AUD' 
         number_to_currency(a.price_aud, unit: "$") 
        when 'CAD' 
         number_to_currency(a.price_cad, unit: "$") 
        when 'NZD' 
         number_to_currency(a.price_nzd, unit: "$") 
        else 
         number_to_currency(a.price, unit: "$") 
        end 
       end 
      end 

     column "Status", :sortable => :status do |a| 
      div :class => "average" do 
       number_to_percentage(a.status, precision: 0) 
      end 
     end 

     column :category 

     column "Updated", :sortable => "end_date" do |a| 
      if a.end_date > Time.now - 5.days 
       distance_of_time_in_words(a.end_date, Time.now, include_seconds: true) + " ago" 
      else 
       a.end_date.to_formatted_s(:long) 
      end 
     end 

     #column :company 
     #column :country 


    end 

    # Sidebar 

    #sidebar :ProductSearch, :priority => 1 do 
    # render partial: 'admin/search_products', :locals => {:model_name => 'products'} 
    #end 

    # Filters 

    filter :category, :as => :check_boxes, :collection => proc { Product.all.collect {|dd| dd.category}.uniq.sort }   
    #filter :name, :label => "Product Name", :as => :string, filters: ['contains'] 
    #filter :price, :label => "USD Price" 
    #filter :interest, :label => "Units Sold" 
    #filter :company, :as => :select, :collection => proc { Product.all.collect {|dd| dd.company}.uniq.sort } 
    filter :country, :as => :select, :collection => proc { Product.all.collect {|dd| dd.country}.uniq.sort } 
    filter :end_date, :label => "Date" 
    remove_filter :link 
    remove_filter :image_url 
    remove_filter :price 
    remove_filter :interest 
    remove_filter :interest_changes 
    remove_filter :revenue 
    remove_filter :start_date 
    remove_filter :price_eur 
    remove_filter :price_gbp 
    remove_filter :price_aud 
    remove_filter :price_nzd 
    remove_filter :price_cad 

end 

는 Heroku가 일부 로그를 다음과 같습니다

class Product < ActiveRecord::Base 

    # Scopes 

    scope :upward_trending, -> { where("status > ?", 100) } 
    scope :downward_trending, -> { where("status < ?", 100) } 
    scope :uncategorised, -> {where(category: '') } 
    scope :categorised, -> {where.not(category: '') } 

end 

가 여기 내 자원 코드입니다 :

여기 내 모델 코드입니다.

2014-09-17T21:22:09.778167+00:00 app[web.1]: Started GET "/admin/products" for 91.226.23.198 at 2014-09-17 21:22:09 +0000                          
2014-09-17T21:22:09.786533+00:00 app[web.1]: Processing by Admin::ProductsController#index as HTML                                
2014-09-17T21:22:25.828163+00:00 heroku[web.1]: source=web.1 dyno=heroku.29301280.ba6942e6-4473-477d-8fa9-b3de141f9f06 sample#load_avg_1m=0.08 sample#load_avg_5m=0.09 sample#load_avg_15m=0.04         
2014-09-17T21:22:25.828431+00:00 heroku[web.1]: source=web.1 dyno=heroku.29301280.ba6942e6-4473-477d-8fa9-b3de141f9f06 sample#memory_total=670.15MB sample#memory_rss=511.80MB sample#memory_cache=0.00MB sample#memory_swap=15 
8.34MB sample#memory_pgpgin=352746pages sample#memory_pgpgout=221723pages                                      
2014-09-17T21:22:25.829347+00:00 heroku[web.1]: Process running mem=670M(130.9%)                                    
2014-09-17T21:22:25.829678+00:00 heroku[web.1]: Error R14 (Memory quota exceeded)                                    
2014-09-17T21:22:39.775186+00:00 heroku[router]: at=error code=H12 desc="Request timeout" method=GET path="/admin/products" host=*.herokuapp.com request_id=e3abc8d7-f52d-47b2-bbb0-161823e1a596 fwd="91.226.23.198" d 
yno=web.1 connect=1ms service=30001ms status=503 bytes=0                                          
2014-09-17T21:22:40.763399+00:00 app[web.1]: E, [2014-09-17T21:22:40.714804 #2] ERROR -- : worker=0 PID:127 timeout (31s > 30s), killing                      
2014-09-17T21:22:41.133007+00:00 app[web.1]: E, [2014-09-17T21:22:41.132895 #2] ERROR -- : reaped #<Process::Status: pid 127 SIGKILL (signal 9)> worker=0                  
2014-09-17T21:22:43.505823+00:00 app[web.1]: I, [2014-09-17T21:22:43.491614 #158] INFO -- : worker=0 ready                              
2014-09-17T21:22:46.406853+00:00 heroku[router]: at=info method=GET path="/favicon.ico" host=x.herokuapp.com request_id=9769d818-5231-44db-ab19-d6f7597c308b fwd="91.226.23.198" dyno=web.1 connect=1ms service=5666ms 
status=304 bytes=111             

편집 :

나는 이것으로 내림차순 정렬하고 같은 종료일에 인덱스를 추가하는 시도했습니다. 불행하게도 이것은로드 시간에 작은 변화를 만들어 :

범인이 코드 줄처럼
Sep 17 15:22:34 x app/web.1: Completed 200 OK in 8556ms (Views: 7377.9ms | ActiveRecord: 1173.7ms) 
Sep 17 15:23:07 x app/web.1: Completed 200 OK in 8864ms (Views: 7640.8ms | ActiveRecord: 1220.0ms) 
Sep 17 15:28:47 x app/web.1: Completed 200 OK in 9551ms (Views: 8039.2ms | ActiveRecord: 1442.5ms) 
Sep 17 15:29:01 x app/web.1: Completed 200 OK in 8921ms (Views: 7651.1ms | ActiveRecord: 1264.0ms) 
+0

당신은 결과를 paginating하고 있습니다 :

filter :country, :as => :select, :collection => proc { Product.all.collect {|dd| dd.country}.uniq.sort } 

가로 변경 권리? –

+0

안녕하세요. @ PhilHallstrom 답장을 보내 주셔서 감사합니다. ActiveAdmin이 기본적으로 페이지 매김을한다고 생각합니다. 맞습니까? – bnussey

+0

어딘가에 사용 중지하지 않는 한 그렇게합니다. 더블 체크할만한 가치가 있습니다 ... –

답변

2

가 보이는 :

filter :country, :as => :select, :collection => proc { Product.pluck(:country).uniq.sort } 
+1

Product.pluck (: country) .uniq.sort -> Product.uniq.pluck (: country) .sort는 더 빠르게 만들 것입니다 :) –

+0

안녕하세요, @MohitJain이 오류가 발생했습니다 : PG :: InvalidColumnReference : ERROR : SELECT DISTINCT의 경우 ORDER BY 표현식을 선택 목록에 표시해야합니다. LINE 1 : ... T "products". "company"FROM "products"ORDER BY end_date D ... ^ : SELECT DISTINCT "products". "회사"FROM "제품"ORDER BY end_date DESC' – bnussey