A Rails application has the following feature:
Some of its models access data from an external MySQL database. The following code is being used to set the external database to the model:
class Foo < ActiveRecord::Base
establish_connection ENV['EXTERNAL_DATABASE_URL']
self.table_name = 'foos'
...
end
Running the app locally on my notebook, I have the following request execution times:
Completed 200 OK in 374ms (Views: 118.1ms | ActiveRecord: 198.6ms)
When I upload it to Heroku and use the app there, the same request has the following execution times
Completed 200 OK in 8000ms (Views: 901.6ms | ActiveRecord: 6609.2ms)
Both ActiveRecord and Views times are insanelly large when I run it on Heroku.
- The external db may be the problem?
- How can I check this?
- If it's not, what could be the problem?
EDIT

NewRelic shows that the bottleneck is database. However, it's clearly not the time DB spends on the queries, because when I run locally, it doesn't take that much. So I must assume that it's the latency that's causing it?
amazon-web-services::us-east-1that is where heroku is hosted.