10

I upgraded a production app from rails 4 to rails 5 a few days ago, and I have seen a big increase in CPU utilization on my RDS postgresql instance. There does not seem to be any associated increase in database requests or decrease in speed.

What could cause that? What can I do to bring CPU utilization back down while still using Rails 5?

The image below shows CPU utilization on the RDS instance. The time of the upgrade is just to the left of the 11/09 line.

RDS Cpu utilization

nbrustein
  • 589
  • 4
  • 14
  • Is the system using prepared statements? The SQL in the log file would have $1, $2 etc and a series of bound parameters. – David Aldridge Nov 14 '16 at 17:10
  • yes, we are using prepared statements – nbrustein Nov 14 '16 at 19:33
  • Could this be related? https://github.com/rails/rails/commit/cbcdecd2c55fca9613722779231de2d8dd67ad02 – nbrustein Nov 14 '16 at 21:54
  • You can see at the tail end of [this graph](http://i.imgur.com/KTJvtFQ.png) an immediate drop in CPU usage variance that happened as soon as we switched the server back to `Rails 4`. – theblang Nov 15 '16 at 17:33
  • We reverted the `postgresql_adapter.rb` changes from [the above commit](https://github.com/rails/rails/commit/cbcdecd2c55fca9613722779231de2d8dd67ad02) and have also tried explicitly disabling `prepared_statements` in our `database.yml`, both without improvement. This leads me to believe that the Rails 5 DB CPU load uptick is not related to prepared statement management. – Brent Nov 15 '16 at 17:39

1 Answers1

2

We eventually tracked this down to an issue in activerecord: https://github.com/rails/rails/issues/27201

Basically, since changed? was sometimes erroneously set to true, we were doing more queries in rails 5 than in rails 4, and we were mis-reading the reports in RDS, so we had not identified the increase in queries.

nbrustein
  • 589
  • 4
  • 14