3

I have a Django app on App Engine that connects to a Cloud Sql server.

Recently, some of the requests started to raise the following error from MySQLdb:

OperationalError: (2062, 'Cloud SQL socket open failed with error: No such file or directory')

The error is raised sporadically so it's hard to debug.

Tzach
  • 12,889
  • 11
  • 68
  • 115

1 Answers1

4

Found the answer here.

Stating from GAE 1.9.5, the number of concurrent db request per instance is limited to 12. The solution was to limit the number of concurrent requests per instance to 12, by changing app.yaml:

automatic_scaling:
  max_concurrent_requests: 12

For those who don't use GAE Modules or Automatic Scaling, the solution may be to disable concurrent requests completely by setting threadsafe: false. Note that this might dramatically increase the number of instances.

Another solution is to use some kind of a DB connection pool with a limited number of simultaneous connections. I haven't tried it myself.

Tzach
  • 12,889
  • 11
  • 68
  • 115
  • 1
    I don't see how this can be a solution- documentation [here](https://cloud.google.com/appengine/docs/python/modules/#Python_Instance_scaling_and_class) states that the default max_concurrent_requests is 8. – georgerw Mar 10 '15 at 10:26
  • @georgerw on my configuration that setting was set to a higher value. – Tzach Mar 10 '15 at 10:53
  • 1
    I currently have this configuration in my app.yaml, and I'm still seeing this error. However I think this could also be caused by not closing connections, or opening multiple connections in a request. – Mark Apr 04 '16 at 22:53
  • 1
    @Mark you are correct, and I actually realized that and created a middleware that automatically closes DB connections when requests are finished. I also configured MySQL to auto close stale connections after a few minutes. – Tzach Apr 05 '16 at 07:50
  • If you limit the number of concurrent request for a task queue, what happens when that limit is reached? Does it fail, or does it wait until a connection can be made? – coler-j Jul 23 '17 at 22:21