MySql Too many connections: Django sqlAlchemy

139 views
Skip to first unread message

amith chowdri

unread,
Oct 10, 2019, 5:34:21 AM10/10/19
to Django users
Hi all,

I'm developing a tool in which I'm using Angular 6 for frontend and Django rest framework for the backend. To connect Django and MySql I'm using SqlAlchemy.

Now, I'm facing issue "MySql Too many connections" when there is an increase in usage of API or you can say no. of users(currently 10 users). When I see show processlist all the connections are in sleep. when no. of connections reaches maximum I'm getting this error. So I tried using connection pooling to solve this issue (link). But still not able resolve as the connections are continuing to be in sleep mode. I have also tried giving 'CONN_MAX_AGE' as 0 but of no use.

1) Why is Django not closing the connections or reuse the connections which are in sleep instead of creating a new connection every time?
2) Should I close the connections manually? How?
3) The proper way to handle the connection pooling in Django.
4) Any other ways to handle this issue?

Quick fix: I have set wait_timeout and interactive_timeout as 800 for temp purpose and it is working fine as the connections which are in sleep mode for more than 800s are getting dropped. I feel this is not a proper way to fix this issue.

I have posted this issue on stack overflow(link) but haven't got any response.

Thank you
Reply all
Reply to author
Forward
0 new messages