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
In a traditional Rails app, HTML view rendering takes a lot of time. Fortunately, there are measures you can take to reduce this. 1. Turbolinks This comes wrapped up in your standard Rails app. Turbolinks is a JavaScript library that works everywhere (even without Rails, like on static pages) and degrades gracefully on unsupported browsers.
In this post, we explored how to improve your Rails app's view performance by making improvements to database utilization, using third-party tools and services and restricting what users see. If you are looking to improve your app's performance, start out simple and keep measuring as you go along!
The first step to building a performant application is to maximize resource utilization. Most Rails apps render something from the database onto the views, so let's try to optimize database calls first! For the purpose of this demonstration, I'm going to use a MySQL database. Let's look at how that initial load of 1066ms breaks down.
Since the server knows when data changes, it can push data only when there is a change! Rails 5 released ActionCable, which lets you manage all things WebSockets. It provides a JS framework for the client to subscribe to the server and a backend framework for the server to publish changes.
Try accessing your application with local ip address
127.0.0.1:3000
in my case I gained 2 ~ 3 seconds in charging time
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With