Logo Questions Linux Laravel Mysql Ubuntu Git Menu

How to decrease the timeout for my python application connecting to mysql server

We have a python application running with uwsgi, nginx.

We have a fallback mechanism for DBs. ie., if one server refuses to connect, we connect to the other server. But the issue is that the connection takes more than 60s to timeout.

As nginx times out in 60s, it displays the nginx error page. Where can we change the timeout for connecting to mysql servers so that we can make three attempts of connection to mysql in the given 60s nginx timeout period?

We use Web2py and default DAL object with pymysql adapter

like image 736
Srinath G S Avatar asked Mar 24 '23 07:03

Srinath G S

1 Answers

you're talking about the option connect_timeout?

conn = pymysql.connect(host='', port=3306, user='root', passwd='', db='mysql', connect_timeout=20)

in DAL terms this option will be something about this (not tested)

db = DAL('mysql://username:password@localhost/test', driver_args={connect_timeout=20})
like image 60
cadmi Avatar answered Mar 30 '23 18:03