I have three tables of around 10 million rows each in MySQL on Amazon RDS and I am finding the insert/update performance to be VERY slow. Each table contains unrelated data.
Each table is regularly updated with about 2000 rows each time. The rows either update existing values or insert new ones. I am finding that updating or inserting 2000 rows takes over 12 hours to perform.
The database has 100GB of General SSD storage which means that it can sustain 300 IOPS. CPU utilisation is below 20% and RAM is 50% free.
I am using an index and a primary key which was constructed from two columns within the table using:
CONSTRAINT PK_1 PRIMARY KEY (DATE, NAME)
I am using the following query:
INSERT INTO Table (DATE, NAME, COLUMN_1, ..., COLUMN_10) VALUES ('2015-05-26','David', VALUE_1, ... , VALUE_10), ... ('2015-05-26','Tom', VALUE_1, ... , VALUE_10) ON DUPLICATE KEY UPDATE COLUMN_1=VALUES(COLUMN_1), ... , COLUMN_10=VALUES(COLUMN_10);
The above query inserts/updates 7 rows and 10 columns of data. This happens for all 2000 entries(users).
The reason why I have chosen to use the above statement instead of a
REPLACE INTO statement is because whilst the table is 40 columns wide, I only receive 10 of those columns at once. The values of the rows can also change for up to a week.
By default, the data was being inserted into the three tables sequentially. I have tried inserting the data in parallel. However, there was no significant improvement in the performance.
I don't understand why it takes over 12 hours to insert 2000 rows. What are my options to improving performance?