I have a PHP application running on Google App Engine that uses Google Cloud SQL.
Recently we have seen an an increase in our user count and since then we have been getting the following error.
This happens frequently but in random views. We are sure there is nothing wrong with the code. This error however disappears once the user refreshes the browser.
Can someone help us to understand why this is happening?
Krish, I am not sure what your setup is with replication etc, however if this issue started after an increase in users it is likely that you are reaching concurrent connection, queue limit issues.
The documentation for Cloud SQL https://cloud.google.com/sql/docs/mysql/diagnose-issues
Has a section on CloudSQL Instance limits. It is possible you are reaching the queue limit. This could be caused by way too many users making requests at the same time, or maybe you have a query that is too slow and clogs up the queue, causing users to overflow the queue.
That same page in the documentation talks about enabling query logs (way down the page) and shows you how once activated you can query your SQL logs for slow queries that could be causing issues.
SELECT * FROM mysql.slow_log;
If you are able to solve it by fixing your queries then great! If not, maybe it is time to introduce read replicas to spread the load between a couple of instances of your DB.