We have 1200+ shards spread across 20 mysql servers. I am working on some denormalization project to remove joins and improve performance of a big snapshot query. I had to alter a table with 8 denormalized columns so initially my script was
alter table file_p1_mdb1_t1 add column ctime BIGINT;
alter table file_p1_mdb1_t1 add column size BIGINT;
alter table file_p1_mdb1_t1 add column user_id BIGINT;
in performance environment when I generated the alter script and started applying alter I started seeing below data where each alter is taking 30sec. I was like this could take 80 hours to alter 1200 shards each with 8 alter per table. Even if we do 20 servers in parallel this could take 4 hours.
Query OK, 1446841 rows affected (33.58 sec)
Records: 1446841 Duplicates: 0 Warnings: 0
Query OK, 1446841 rows affected (31.66 sec)
Records: 1446841 Duplicates: 0 Warnings: 0
Query OK, 1446841 rows affected (31.86 sec)
Records: 1446841 Duplicates: 0 Warnings: 0
Query OK, 1446841 rows affected (32.15 sec)
Records: 1446841 Duplicates: 0 Warnings: 0
so I wrote a new alter that looks like
alter table file_p1_mdb1_t1 add column ctime BIGINT,
add column size BIGINT,
add column user_id BIGINT;
and this shows same constant time. So this would take 10 hours. But we can do the 20 servers in parallel and should finish in 30 min.
Query OK, 1446841 rows affected (33.58 sec)
Records: 1446841 Duplicates: 0 Warnings: 0
Lesson learnt, when you are operating at scale even small optimizations count.
alter table file_p1_mdb1_t1 add column ctime BIGINT;
alter table file_p1_mdb1_t1 add column size BIGINT;
alter table file_p1_mdb1_t1 add column user_id BIGINT;
in performance environment when I generated the alter script and started applying alter I started seeing below data where each alter is taking 30sec. I was like this could take 80 hours to alter 1200 shards each with 8 alter per table. Even if we do 20 servers in parallel this could take 4 hours.
Query OK, 1446841 rows affected (33.58 sec)
Records: 1446841 Duplicates: 0 Warnings: 0
Query OK, 1446841 rows affected (31.66 sec)
Records: 1446841 Duplicates: 0 Warnings: 0
Query OK, 1446841 rows affected (31.86 sec)
Records: 1446841 Duplicates: 0 Warnings: 0
Query OK, 1446841 rows affected (32.15 sec)
Records: 1446841 Duplicates: 0 Warnings: 0
so I wrote a new alter that looks like
alter table file_p1_mdb1_t1 add column ctime BIGINT,
add column size BIGINT,
add column user_id BIGINT;
and this shows same constant time. So this would take 10 hours. But we can do the 20 servers in parallel and should finish in 30 min.
Query OK, 1446841 rows affected (33.58 sec)
Records: 1446841 Duplicates: 0 Warnings: 0
Lesson learnt, when you are operating at scale even small optimizations count.
Comments
Post a Comment