AWS RDS MySQL remote connection extremely slow

I have a site hosted on AWS EC2 (Elastic Beanstalk), with a MySQL database hosted on AWS RDS. Everything works fine on the production server, fast and all.

However when I try to connect remotely from my local machine, it sometimes gets extremely slow (like 4 minutes to load the list of tables), or simply times out.

I added my IP in the security group (which I did correctly, since it sometimes works). When it doesn't work, I at the same time check the prod server and it still looks good.


As much I could understand, there is nothing wrong at the ACL or network level, as you are saying that it works sometimes.

What I can see is that you are hitting a limit on the maximum number of processes for Mysql. So, when you connect and issue any command, then if the number of processes allowed to run are saturated, then you have to wait and your request goes into queue. But if you don't get a slot then after that it timeouts.

You can check the same by looking at the graphs which are available with RDS. If the graph is going flat at some value, then my guess is very right.

The total number of connections depends on the instance type you are using. That you can check and set in the DB parameters group option. Search for max_connections.

I am not sure what are the default values for different types of instances, but I am sure this information should be somewhere over the internet.