I have the following two profiles for a basic SELECT
STATEMENT:
select count(*) from mturk_completion;
Here are the two profiles:
# My Local machine, using a local db
Status Duration
starting 0.000045
checking permissions 0.000006
Opening tables 0.000015
init 0.000011
System lock 0.000006
optimizing 0.000004
statistics 0.000011
preparing 0.000009
executing 0.000002
Sending data 0.034015 ########
end 0.000012
query end 0.000006
closing tables 0.000011
freeing items 0.000036
cleaning up 0.000010
And then here it is on my AWS ec2 large instance using an RDS mysql db:
starting 0.000068
checking permissions 0.000016
Opening tables 0.000028
init 0.000024
System lock 0.000018
optimizing 0.000015
statistics 0.000022
preparing 0.000022
executing 0.000012
Sending data 0.446171 #########
end 0.000036
query end 0.000018
closing tables 0.000023
freeing items 0.00009
cleaning up 0.000013
Most of the numbers are comparable except the Sending data part is more than ten times slower on the RDS instance!! What could account for that, and how would I fix this?
Here is the RDS instance information:
http://dev.mysql.com/doc/refman/5.0/en/general-thread-states.html
I suspect disk access speed is the difference.
In your first test it seems you have a local machine connecting to a local DB server with a local hard disk. In your second test you're connecting to a remote DB server with a remote hard disk (ie. EBS).
EBS (which is what RDS uses for storage) is significantly slower than instance storage, which I imagine might still be slower than an unloaded local disk on your workstation (especially if you have an SSD).
However in exchange for the performance loss you gain a number of benefits enabled by the abstracted nature of ELB:
Which is why most people accept the performance penalty.
If the performance loss is significant then you can try a few things: