1

I have a Ruby 2.7.6 app running on Heroku (stack heroku-20) and a branch of the same app on Ruby 3.1.4 running on Heroku (stack heroku-22). Both have identical DBs. Running these two branches locally, DB query times seem similar. However on Heroku, DB queries on the Ruby 3 build are massively (sometimes over 10x) slower.

# Ruby 2.7.6 on Heroku-20
participant_registration.session_results.count
D, [2023-07-15T15:10:25.598762 #2] DEBUG -- :    (85.0ms)  SELECT COUNT(*) FROM "session_results" WHERE "session_results"."sessionable_id" = $1 AND "session_results"."sessionable_type" = $2  [["sessionable_id", 82497], ["sessionable_type", "UserChampionship"]]

# Ruby 3.1.4 on Heroku-22
participant_registration.session_results.count
D, [2023-07-15T15:10:43.115159 #2] DEBUG -- :    (1167.6ms)  SELECT COUNT(*) FROM "session_results" WHERE "session_results"."sessionable_id" = $1 AND "session_results"."sessionable_type" = $2  [["sessionable_id", 82497], ["sessionable_type", "UserChampionship"]]

All queries are significantly slower, I just chose this one as it seemed even more dramatic than others. Perhaps this is a question I need to raise with Heroku, but I just wanted to check if there was something else I am missing here that I should be aware of.

UPDATE Turns out something must have just gone wrong with the DB on this particular environment. After deleting and rebuilding (with the same production data), it's snappy again.

Tony Beninate
  • 1,926
  • 1
  • 24
  • 44
  • Did you spin up the database in the same region as the dyno? – spickermann Jul 15 '23 at 15:39
  • @spickermann unsure, not sure how to control that on Heroku. I should point out though, if i were to roll back our Heroku-22 environment back to Heroku-20 and Ruby 2, query times would be fast again, so i'm not sure it'd be a region issue. – Tony Beninate Jul 15 '23 at 15:46
  • Is it the same application and DB on Heroku, that you updated to Stack-22 and Ruby 3. Or did you create a new application with a new DB for the new environment? – spickermann Jul 15 '23 at 15:50
  • It's a branch of the same application (only difference being the Ruby version change). DBs are both identical copies from our production environment. – Tony Beninate Jul 15 '23 at 15:52
  • 2
    I would try [connecting directly to the database with a PostgreSQL client](https://devcenter.heroku.com/articles/managing-heroku-postgres-using-cli#pg-psql) and running both queries directly against the DB without Rails. – spickermann Jul 15 '23 at 17:02
  • Well that's super interesting; the speed differential is still present when querying directly on the DB... [big thinking emoji] – Tony Beninate Jul 15 '23 at 20:47
  • 1
    @spickermann well well well. I deleted and rebuilt the DB on the slow environment, and all is zippy again! No idea what happened there. Thanks for helping me think through that. – Tony Beninate Jul 15 '23 at 21:03

0 Answers0