Amazon RDS MySQL instance performs very slow

前端 未结 7 1562
轻奢々
轻奢々 2021-01-31 17:58

I have published my website on Amazon EC2 (Singapore region) and I have used MySQL RDS instance for the data storage. Everything is working very fine except performance.

相关标签:
7条回答
  • 2021-01-31 18:06

    Always should deploy source and rds in the same AWS availability zone for lower network latency and Should create a private endpoint link in VPC for RDS to connect RDS endpoint through the internal network instead of routing through the internet.

    Reference: https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/vpc-interface-endpoints.html

    0 讨论(0)
  • 2021-01-31 18:08

    It is important to have your RDS and EC2 instances not just in the same region but also in the same availability zone to minimize the latency.

    I had an API hosted in Ireland on EC2 and moved the Database to a MySQL cluster in Virginia USA that we had set up for another project and the round trip on every SQL query made the API unusable.

    0 讨论(0)
  • 2021-01-31 18:08

    First i highly recommend to look over these queries using

    SHOW FULL PROCESSLIST

    You can read more about it on SHOW FULL PROCESSLIST

    This will show you the time each query take.

    Then you can use

    EXPLAIN

    You can read more about it on EXPLAIN

    This will show you if you need some enhancement on your queries

    0 讨论(0)
  • 2021-01-31 18:15

    For me, it was nothing to do with MySQL but rather the instance type I was on t2.medium. The problem is I ran out of CPU credits because the load on the DB was too high and the balance kept going down until finally, I was getting far fewer credits hourly than were needed.

    Here is what I saw in RDS CloudWatch under CPU Credit Usage:

    If you have the same problem it may be time to switch to a different instance. Here is the list of instance types:

    https://aws.amazon.com/rds/instance-types/

    Hope this helps.

    0 讨论(0)
  • 2021-01-31 18:15

    You can check where the query is taking time by making use of profiling. Use the below query:

    1. set profiling=1
    2. execute your select query
    3. show profile

    This will tell you about the status of the query and where the query is spending its time. If the sum of all the time returned by the profiling is less than the actual execution time of the query, then maybe other factors like Network bandwidth may be the cause of it.

    0 讨论(0)
  • 2021-01-31 18:21

    It is worth noting that, for whatever reason, MySQL query cache is OFF by default in RDS. We learned that the hard way ourselves this week.

    This won't help performance of your initial query, but it may speed things up in general.

    To re-enable query cache:

    1. Log in to the RDS Console
    2. Click on your RDS instance to view it's details
    3. Edit the Database Parameter Group
    4. Be sure to set both query_cache_size and query_cache_type

    (Disclaimer: I am not a DBA so there may be additional things I'm missing here)

    0 讨论(0)
提交回复
热议问题