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.
I seems that, my all queries, specially select statement, is performing very slow. If I check this issue on my local PC, there it is working very well. But when I am trying to get data from RDS instance, it is very slow. Some of the select statements takes 2-3 seconds to fetch data.
I have properly tuned up all table indexes, and normalized/de-normalized as required. I have made all necessary settings on RDS custom parameter group (eg. max_connection, buffer etc). I don't know if I am missing something, but it didn't worked for me - performance didn't increase.
So, can someone please help me with this issue?
RDS MySQL performance can be increased in following ways assuming the system has more read ratio:
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:
query_cache_size
andquery_cache_type
(Disclaimer: I am not a DBA so there may be additional things I'm missing here)
You can check where the query is taking time by making use of profiling. Use the below query:
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.
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 then where 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.
First i highly recommend to look over these queries using
You can read more about it on SHOW FULL PROCESSLIST
This will show you the time each query take.
Then you can use
You can read more about it on EXPLAIN
This will show you if you need some enhancement on your queries
It is important to have your RDS and EC2 instances not in the same region but 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.