Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ActiveRecord::QueryCache#call taking over 70% of execution time

NewRelic is showing me that over 80% of execution time in the app server is taking place in "Middleware ActiveRecord::QueryCache#call"

enter image description here

Here is a gist of the relevant code tested (although I see similar results on other API endpoints).

Gist

I'm running the app server on AWS Elastic Beanstalk on a t2.medium instance and a t2.small Postgres RDS DB with max_connections set to 100. I'm testing this via loader.io, doing a test of 100 users with the maintain client load setting (this means about 6000 requests a minute).

Does anyone have an idea why the QueryCache is taking so much time?

like image 208
dmastylo Avatar asked Jul 07 '15 00:07

dmastylo


1 Answers

Unfortunately, this issue with QueryCache is quite common and seems to have multiple causes, but the most common is that the connection between your EC2 app server and DB was temporarily severed, and QueryCache doesn't handle this particularly well.

Remedies include increasing your default connection pool size substantially (e.g. an order of magnitude higher), disabling QueryCache entirely, or increasing read_timeout in database.yml to 15 seconds or more depending on your environment.

If the read_timeout setting resolves the problem, you may want to investigate why there are so many disconnects between your app server and db.

Another path which might not be an option for you would be to run the app server on the same machine as the db, but that doesn't work for everyone due to their architecture. It certainly can be an effective test to see if eliminating the network variable helps. Good luck.

like image 54
telemark Avatar answered Oct 23 '22 04:10

telemark