Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS RDS painfully slow when connecting from local machine

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).

like image 738
Robert Benedetto Avatar asked Oct 15 '15 06:10

Robert Benedetto


People also ask

Why is my AWS RDS so slow?

Your Amazon Relational Database Service (Amazon RDS) system resources are over utilized. This can happen because of high CPU, low memory, or a workload that exceeds what your DB instance type can handle. The database is locking and the resulting wait events are causing SELECT queries to perform poorly.

How can I make my RDS faster?

DB instance RAM recommendations An Amazon RDS performance best practice is to allocate enough RAM so that your working set resides almost completely in memory. The working set is the data and indexes that are frequently in use on your instance. The more you use the DB instance, the more the working set will grow.

Can we connect to RDS from local?

To connect to a private RDS DB instance from a local machine using an EC2 instance as a jump server, follow these steps: Launch and configure your EC2 instance and configure the network setting of the instance. Configure the RDS DB instance's security groups. Connect to the RDS DB instance from your local machine.

Why is RDS CPU usage so high?

Increases in CPU utilization can be caused by several factors, such as user-initiated heavy workloads, multiple concurrent queries, or long-running transactions. To identify the source of the CPU usage in your Amazon RDS for MySQL instance, review the following approaches: Enhanced Monitoring. Performance Insights.


1 Answers

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.

enter image description here

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.

like image 180
Keet Sugathadasa Avatar answered Sep 26 '22 00:09

Keet Sugathadasa