Ask HN: Need help...Rails app seems to take 300ms+ for everything.

4 points by shail ↗ HN
Ok, I will admit. Its not the simplest app but yet its not the most complicated one either.

The rather frustrating part is that most of the time is being spent in rendering views. Here are few examples.

- Completed 200 OK in 272ms (Views: 236.9ms | ActiveRecord: 15.7ms)

- Completed 200 OK in 275ms (Views: 148.2ms | ActiveRecord: 42.6ms)

- Completed 200 OK in 384ms (Views: 335.1ms | ActiveRecord: 3.5ms)

I am not doing partials in a loop etc. I am NOT querying while rendering either. Its just ruby hash operations etc which are taking up lot of ms. Now I am starting to wonder is how many SQL queries is considered normal, like in my app its around 4 - 10 queries. Is 300ms+ an acceptable response time for a Rails app which is not even launched yet (so no server load as of now). Hosted on $20 VPS Linode.

Thanks in advance for sharing your insights.

7 comments

[ 104 ms ] story [ 395 ms ] thread
Have you done any view caching? You should take a look at fragment caching and how Russian doll caching works with the cache_digest gem.
I have not done any view caching as of now. I plan to do that. But the main issue in my mind currently is that ruby is performing slow and while searching on net I found solutions such as: 1) using REE (some GC fix) 2) Erubis is faster than erb 3) Other ruby implementations.

I am wondering if anyone can share their experiences with an y of these approaches.

Caching is something I plan to do but I wish to keep it as the last resort.

What version of ruby, rails, db & which web server are you using? It's hard to say the problem is ruby being slow until you isolate the problem. A guy I work with wrote a gem called dev_panel we use to find the bottlenecks. I haven't looked at ree in a long time but I think the most recent version is built against ruby 1.8. Erubis hasn't had an update in over 2 years.
Post code.

Ruby hash operations - your code or the framework?

Have you installed newrelic.com and compared the performance difference between your dev and prod?
No one can tell you what the problem is with that little information. However, here are some suggestions on how you can yourself debug your problem:

Isolate: Eliminate as much as possible until nothing except the problem remains. You can't fix the problem until you know what the problem is, and guessing about it will just lead you astray.

Is performance still crap when you remove the db calls? When you replace the db connection with sqlite? When you remove the view logic and just render a static template? When you remove the templates altogether and just render a simple "Hello, world" string? When you put the application on a free Heroku instance instead of Linode?

Then ask yourself, does it make sense? Is Ruby so slow that a simple page takes 300 ms to load? Is a $20 (per month? per year?) Linode VPS that crappy?

Have you tried running this anywhere else? How much processing time does a linode vps actually give you? It says activerecord is taking 15ms, that's the time spent querying the database. The view is taking the majority of the time which is normally going to be cpu time because it has to compile the template. Are you running it in cached mode? Because if not its going to read each template off disk before generating the view right?