Search code examples
ruby-on-railsruby-on-rails-3performancescale

Rails 3 application speeding up


I am newbie in Rails 3.
I'm trying to find out why my page is loaded so much slow.
I am in development mode (but in production mode there is the sane picture)

There is a log:

Started GET "/inv/claims?locale=uk" for 127.0.0.1 at 2012-05-07 14:36:24 +0300
  Processing by ClaimsController#index as HTML
  Parameters: {"locale"=>"uk", "property"=>"inv"}
Rendered shared/_apps_list.html.erb (0.0ms)
Rendered shared/_apps_list.html.erb (0.0ms)
Rendered shared/_apps_list.html.erb (15.6ms)
Rendered shared/_apps_list.html.erb (0.0ms)
Rendered shared/_apps_list.html.erb (0.0ms)
Rendered shared/_apps_list.html.erb (0.0ms)
Rendered shared/_apps_list.html.erb (15.6ms)
Rendered shared/_apps_list.html.erb (0.0ms)
Rendered shared/_apps_list.html.erb (0.0ms)
Rendered shared/_apps_list.html.erb (0.0ms)
Rendered shared/_apps_lists.html.erb (31.3ms)
Rendered claims/index.html.erb within layouts/application (46.9ms)
Completed 200 OK in 1594ms (Views: 46.9ms | ActiveRecord: 0.0ms)

Total amount of time is 1594ms

First question: Is it really slow?

1594 - 46.9 = *1547*ms - it's a time that my page spends for some logic (not for rendering and querying).

Second question: Is the logic of application bad in that case (1547ms)?

I try to make pagination
My page logic:
I have a folder structure:

/myfolder/1/application.xml (size of any application.xml about 5Kb)
/myfolder/2/application.xml  
/myfolder/3/application.xml  
/myfolder/4/application.xml  
/myfolder/5/application.xml  
...  
/folder/50/application.xml 

I'm doing...
1) I am getting such information about each folder in myfolder (myfolder/1/, myfolder/2/...): folder creation or change date. I store that information in Hash.
2) Sort getting on step 1) Hash by date of creation or change
3) Getting slice of Hash using start id and step. Saving it in new Hash. 4) Iterating through Hash from step 3. For every entry reading application.xml and parsing it to hash using doc_hash = Hash.from_xml(Nokogiri::XML(f, &:noblanks).to_xml


Solution

    1. Yes. That's a second and a half to process a page. It's too slow.

    2. It looks like there must be some strange logic error somewhere. Spending over a second in non-activerecord, non-view processing is way too long.

    I'd look pretty deeply at any loops you have and try to understand what's happening at that level.