Reputation: 555
With nothing happening in the controller besides render 'mypage'
, and nothing happening in the view besides HTML (I've commented out all the Ruby code in both places), it still takes over 5 seconds to load the page:
Completed 200 OK in 6258ms (Views: 5283.2ms | ActiveRecord: 14.6ms)
Any suggestions on how I can either improve this or profile it? Every 'solution' I've come across has no effect for me. Rails-dev-tweaks doesn't make an impact, changing the assets debug flag has no effect; I actually believe this all happens before assets are requested.
Update 07 May 1450
Hi all - thanks for the replies. Let me start off by saying I have narrowed this down to assets; removing about a half dozen gems and all assets has brought the page load time down to 1.3s for the first load, and reloading is ~150ms. Fantastic. So my problem now becomes how to properly configure a gem like rails-dev-tweaks to get it going; I can't seem to find the right config that will. We have probably a hundred or so assets - maybe a little more.
To answer your questions: I unfortunately can't copy and paste the view; however, suffice to say it is about 100 lines of HTML, 10 lines of javascript, and maybe 30 of the HTML lines have some Ruby code in it, but I commented out all the Ruby.
I tried ruby-prof - didn't give me anything really useful
No external HTTP requests are being made
There is a before_filter in the ApplicationController, but even commenting that out didn't make a huge difference.
I'm developing on Mac OS X 10.8
I'm using Rails 3.2.13
With no assets at all: The first page load:
Completed 200 OK in 3418ms (Views: 1414.9ms | ActiveRecord: 74.6ms)
Refreshing the page:
Completed 200 OK in 140ms (Views: 120.8ms | ActiveRecord: 2.8ms)
Interestingly, rails -v
takes 4 seconds to load:
ruby-1.9.3-p327@aidin ± time rails -v
Rails 3.2.13
rails -v 4.10s user 0.24s system 92% cpu 4.679 total
Update 2 07 May 1450
New Relic tells me there's an inordinate amount of time taken in what I believe is a Rails dependency (actually an ActionPack dependency), Journey itself:
Metric Timestamp (s) Duration (ms) Exclusive (ms)
DashboardController#show 0.001 2,652 1917
The detail page shows me this file:
journey-1.0.4/lib/journey/router.rb
And this line:
status, headers, body = route.app.call(env)
Update 3 07 May @ 1509
Further investigation reveals that in addition to removing all assets, removing all gems decreases the response time to an acceptable ~150ms. Putting the gems back in moves it to 800ms to 1500ms; clearly there's something going on in those alone that's causing problems.
If anyone thinks they can pick out which gems are causing problems I'm happy to post the Gemfile
Upvotes: 6
Views: 3121
Reputation: 5471
This question is probably long abandon but this is most likely a /etc/hosts problem. 127.0.0.1 in the url bar usually works but I've noticed this isn't always the case.
Before messing with your settings, disconnect your network and see if that helps. If it does, you most likely need to edit your /etc/hosts. Make sure it has the following line.
127.0.0.1 localhost
Upvotes: 0
Reputation: 41
Try accessing your application with local ip address
127.0.0.1:3000
in my case I gained 2 ~ 3 seconds in charging time
Upvotes: 3
Reputation: 1377
So load times are often the result of assets loading or SQL requests occurring.
First, let's start with assets:
One mistake that often occurs with rails apps are the developers are loading way more assets than then really need. Some troubleshooting you can do is in application.js and application.css, remove the //= require_tree .
. This loads all assets you have under assets/stylesheets and assets/javascripts.
Second, reduce your SQL queries
You may have many SQL queries running in your controller(!), model, or sometimes views. These greatly slow down the load times of your pages because they constantly bounce to your database to complete the query.
Another tip:
You can add use Rack::Deflater
to /config.ru to perform a gzip like compression when the page loads. This helped me speed up my pages.
Last tip:
Try to reduce the amount of gems you use in your application. Many of them may save some time, but each one requires more HTTP requests to load their assets. For most, you can replicate their functions with your own code.
Okay... one more
Try to minimize your assets for production. This reduces the time for the browser to scan your code because it reduces the amount of lines by removing whitespace!
Hope these help!
Upvotes: 0