How do I understand why my rails 3 application using mod_rails is so slow?

I developed a small Rails application using Rails 3.0.0 and Ruby 1.9.2. During the test, on my personal computer, this is excellent performance. I put it on VPS for production using Apache and mod_rails, and sometimes the performance is terrible.

Here is an example from production.log:

GET "/ tracker" launched for XX.XX.XX.XX on 2010-11-21 21:49:56 -0500
FleetsController # Index Processing as HTML
Displayed Layouts /_stylesheets.html.haml(0.8ms)
Displayed Layouts /_header.html.haml(1.0ms)
Displayed Layouts /_footer.html.haml(0.0ms)
Displayed pages /about.html.haml in layouts / application (4.5 ms)
Completed 200 OK in 15ms (Views: 14.3ms | ActiveRecord: 0.0ms)

GET "/ tracker /" launched for XX.XX.XX.XX on 2010-11-21 21:50:02 -0500
FleetsController # Index Processing as HTML
Displayed Layouts /_stylesheets.html.haml(0.7 ms)
Displayed Layouts /_header.html.haml(1.1ms)
Displayed Layouts /_footer.html.haml(0.0ms)
Issued fleets /index.html.haml in layouts / application (7.8ms)
Completed 200 OK in 1901ms (Views: 7.8ms | ActiveRecord: 1.5ms)

GET "/ tracker / fleets / XXXXXXXXX" was launched for XX.XX.XX.XX on 2010-11-21 21:50:06 -0500
FleetsController processing # show as HTML
Parameters: {"id" => "XXXXXXXXX"}
Presented fleets /_details_inner.html.haml(1.2ms)
Presented fleets /_details.html.haml(2.1ms)
Presented fleets /_summary.html.haml(3.5ms)
Presented fleets /_scouts_inner.html.haml(1.3ms)
Presented fleets /_scouts.html.haml(3.5ms)
Provided reports /_report.html.haml(0.5 ms)
Presented fleets /_reports.html.haml(3.0ms)
Presented fleets /_recon_form.html.haml(39.9ms)
Presented fleets /_recon.html.haml(40.8ms)
Issued Users /_user.html.haml(1.2ms)
Presented fleets /_pilots.html.haml(1.9ms)
Displayed Layouts /_stylesheets.html.haml(0.5ms)
Presented layouts /_header.html.haml(0.9ms)
Displayed Layouts /_footer.html.haml(0.0ms)
Presented fleets /show.html.haml in layouts / application (60.2ms)
Completed 200 OK in 495ms (Views: 59.1ms | ActiveRecord: 2.9ms)

In the first hit there was no access to the database. The second one has access to the database, but for views only 7.8 ms, and for the database only 1.5 ms, and the entire page was not full for almost 2 minutes! This is a fairly common example, but I have several log entries with 14 + seconds to respond to the page. And no, this is not during the loading of the initial rails after a reboot.

What could be at this time?

1) I misinterpreted ActiveRecord time reports and this is really just code time, but real-time database time is time at which time?

2) I am using sqlite. I know that in the end I will probably have to switch to MySQL, since I will have problems with concurrency, since (most) every page site invokes a database record. But right now I have almost no movement; at the same time, maybe 15 people on the site. In the above log example, there was only 1 hit at a time, with 4-6 seconds between each hit. I would have thought sqlite could handle this ...

3) I am on a shared VPS. This means that maybe some other user on the VPS was doing something at the same time, which was why the server was slowing down. In most cases, my VPS has very low CPU usage, but it’s possible that I’m out of luck and something is happening at this moment. But I saw that this happens quite often, and I do not buy it as an answer.

4) VPS has only 512 + 512 MB of memory. I show 150MB there for free, but is it possible that I just push the memory limits and that is page switching or something like that?

5) I also saw several BusyException in the log. I increased the database.yml timeout to 15 seconds (from 5) to see if this helps. They didn’t do a real test, because to make sure that this happened.

I know that I probably did not provide enough information for you to tell me what is happening, so the real question is: how do I even start trying to track this?

+4
source share
2 answers

So, two things.

  • Use the new relic to help diagnose slow code
  • Based on registration, I would argue that you are doing array manipulation or returning a large array of elements to the FleetsController # index ... it looks like your application code is doing there.

http://www.newrelic.com/

If this does not look right, send the code to the FleetsController # index. But NewRelic can help you understand exactly where you spend your loops in slow web requests.

+1
source

SQLite does not do concurrency at all. I think that perhaps the connections are blocked in the database. The actual queries are fine, but I suspect that the SQLite db file is locked while another query is executing.

You really need to go to the actual server database like MySQL or PostgreSQL.

0
source

All Articles