12
votes

We have nightly load jobs that writes several hundred thousand records to an Mysql reporting database running in Amazon RDS.

The load jobs are taking several hours to complete, but I am having a hard time figuring out where the bottleneck is.

The instance is currently running with General Purpose (SSD) storage. By looking at the cloudwatch metrics, it appears I am averaging less than 50 IOPS for the last week. However, Network Receive Throughput is less than 0.2 MB/sec.

Is there anyway to tell from this data if I am being bottlenecked by network latency (we are currently loading the data from a remote server...this will change eventually) or by Write IOPS?

If IOPS is the bottleneck, I can easily upgrade to Provisioned IOPS. But if network latency is the issue, I will need to redesign our load jobs to load raw data from EC2 instances instead of our remote servers, which will take some time to implement.

Any advice is appreciated.

UPDATE: More info about my instance. I am using an m3.xlarge instance. It is provisioned for 500GB in size. The load jobs are done with the ETL tool from pentaho. They pull from multiple (remote) source databases and insert into the RDS instance using multiple threads.

RDS Cloudwatch Metrics

6
how much storage have you allocated for the DB? What instance are you running this on?tedder42
What do the load jobs look like? It seems like you are not hitting IOPS or bandwidth limits...xpa1492
The database is currently 300GB in size. But we have 500GB provisioned.Jeff
We are using a ETL tool from Pentaho to extract data from multiple source databases and insert in to this reporting database. The ETL tool can do parallel writes. So we might pull out 200,000 records from a single source table and have 4 parallel threads inserting those records into the RDS instance.Jeff

6 Answers

2
votes

You aren't using up much CPU. Your memory is very low. An instance with more memory should be a good win.

You're only doing 50-150 iops. That's low, you should get 3000 in a burst on standard SSD-level storage. However, if your database is small, it is probably hurting you (since you get 3 iops per GB- so if you are on a 50gb or smaller database, consider paying for provisioned iops).

You might also try Aurora; it speaks mysql, and supposedly has great performance.

If you can spread out your writes, the spikes will be smaller.

2
votes

A very quick test is to buy provisioned IOPS, but be careful as you may get fewer than you do currently during a burst.

Another quick means to determine your bottleneck is to profile your job execution application with a profiler that understands your database driver. If you're using Java, JProfiler will show the characteristics of your job and it's use of the database.

A third is to configure your database driver to print statistics about the database workload. This might inform you that you are issuing far more queries than you would expect.

1
votes

Your most likely culprit accessing the database remotely is actually round-trip latency. The impact is easy to overlook or underestimate.

If the remote database has, for example, a 75 millisecond round-trip time, you can't possibly execute more than 1000 (milliseconds/sec) / 75 (milliseconds/round trip) = 13.3 queries per second if you're using a single connection. There's no getting around the laws of physics.

The spikes suggest inefficiency in the loading process, where it gathers for a while, then loads for a while, then gathers for a while, then loads for a while.

Separate but related, if you don't have the MySQL client/server compression protocol enabled on the client side... find out how to enable it. (The server always supports compression but the client has to request it during the initial connection handshake), This won't fix the core problem but should improve the situation somewhat, since less data to physically transfer could mean less time wasted in transit.

0
votes

I'm not an RDS expert and I don't know if my own particular case can shed you some light. Anyway, hope this give you any kind of insight.

I have a db.t1.micro with 200GB provisioned (that gives be 600 IOPS baseline performance), on a General Purpose SSD storage.

The heaviest workload is when I aggregate thousands of records from a pool of around 2.5 million rows from a 10 million rows table and another one of 8 million rows. I do this every day. This is what I average (it is steady performance, unlike yours where I see a pattern of spikes):

  • Write/ReadIOPS: +600 IOPS
  • NetworkTrafficReceived/Transmit throughput: < 3,000 Bytes/sec (my queries are relatively short)
  • Database connections: 15 (workers aggregating on parallel)
  • Queue depth: 7.5 counts
  • Read/Write Throughput: 10MB per second

The whole aggregation task takes around 3 hours.

Also check 10 tips to improve The Performance of your app in AWS slideshare from AWS Summit 2014.

I don't know what else to say since I'm not an expert! Good luck!

0
votes

In my case it was the amount of records. I was writing only 30 records per minute and had an Write IOPS of round about the same 20 to 30. But this was eating at the CPU, which reduced the CPU credit quite steeply. So I took all the data in that table and moved it to another "historic" table. And cleared all data in that table.

CPU dropped back down to normal measures, but Write IOPS stayed about the same, this was fine though. The problem: Indexes, I think because so many records needed to indexed when inserting it took way more CPU to do this indexing with that amount of rows. Even though the only index I had was a Primary Key.

Moral of my story, the problem is not always where you think it lies, although I had increased Write IOPS it was not the root cause of the problem, but rather the CPU that was being used to do index stuff when inserting which caused the CPU credit to fall.

Not even X-RAY on the Lambda could catch an increased query time. That is when I started to look at the DB directly.

0
votes

Your Queue depth graph shows > 2 , which clearly indicate that the IOPS is under provisioned. (if Queue depth < 2 then IOPS is over provisioned)

I think you have used the default AUTOCOMMIT = 1 (autocommit mode). It performs a log flush to disk for every insert and exhausted the IOPS.

So,It is better to use (for performance tuning) AUTOCOMMIT = 0 before bulk inserts of data in MySQL, if the insert query looks like

 set AUTOCOMMIT = 0;
 START TRANSACTION;
 -- first 10000 recs 
    INSERT INTO SomeTable (column1, column2) VALUES (vala1,valb1),(vala2,valb2) ... (val10000,val10000);
 COMMIT;
 --- next 10000 recs
 START TRANSACTION;
    INSERT INTO SomeTable (column1, column2) VALUES (vala10001,valb10001),(vala10001,valb10001) ... (val20000,val20000);
 COMMIT;
  --- next 10000 recs
 .
 .
 .
set AUTOCOMMIT = 1 

Using the above approach in t2.micro and inserted 300000 in 15 minutes using PHP.