I have an AWS RDS instance up and running. When the DB is queried from my website (also on AWS, same region) it runs beautifully. But, if I try to connect to the database from my local developments machine it takes AGES for any query to execute. Does anyone know why? I have opened up the security group to allow connections (while i try to connect from the local machine).
问题:
回答1:
There could be multiple reasons for a problem like this. Some reasons might be so obvious, but mentioning them for the completeness of the answer. You have said that queries execute slow, so I assume that connection establishes successfully and there is no problem with Network ACLs, Security Groups etc.
Reason 1: Your Internet Connection is too Slow
This could be due to many reasons. See the following...
- Another device using your internet bandwidth
- You have some parallel downloads happening in your same device
- Your internet quota has exceeded
- ISP speed issues
For whatever reason, a problem like this will be solved after some time. Check your internet speed using this.
Reason 2: Exceeding the maximum number of connections on RDS instance
You could be 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.
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
.
Reason 3: Geographical Network Latency
Your website, being on the same region has a lower number of network hops to reach the RDS instance. But You local machine might take multiple hops to reach the RDS and return back. Generally AWS is pretty fast and has a stable network but you might notice latency issues for some protocols.
This is highly unlikely, but still could be a reason.
Reason 4: Your network bandwidth is low
To query for multiple records, your bandwidth might not be enough to return them in blazing speeds. Hence, you see the slowness in database queries.
回答2:
Sounds like there is a problem with your internet connection? All the queries from your local workstation have to go from your home or office network, out to the internet and then to your AWS VPC. If you have a slow internet connection that will be a problem. There could also be issue with any local firewall in your home/office.