When working in startup, don’t lose hope, keep slogging as once you reach scale help is on the way.
So far I have been scaling Mysql by throwing more hardware and focusing only on performance issues detected by new relic or my custom report but there were some data driven anomalies where 99% calls to this query would take 1sec but one call to same query would take 10sec. I wasn’t focusing much on it because it was a blip in the graph and there were too many other issues to focus on.
Now we got a full time Mysql engineer who is looking at these queries and hunting down suspects. Today he found this query
select sum(points) from (
select g.all_versions_size as points from folders_trash f
inner join groups g on f.folder_id = g.folder_id
union all
select e1.size as points from groups_trash g1
inner join entries e1 on g1.group_id=e1.group_id
union all
select e2.size as points from entries_trash e2
) s
Now this query works 99% of the time faster because most customers have very few data in trash but some customers have 400K+ rows in trash and for them this was creating a temp table with 400K rows causing the blip.
Changing this query to something like below would create only 3 temp table row, the query became fast and uses less resources.
select sum(points) from (
select sum(g.all_versions_size) as points from folders_trash f
inner join groups g on f.folder_id = g.folder_id
union all
select sum(e1.size) as points from groups_trash g1
inner join entries e1 on g1.group_id=e1.group_id
union all
select sum(e2.size) as points from entries_trash e2
) s
So don't lose hope, find creative ways initially like throwing more hardware to the problem if you can. When you reach scale expert help will come on the way :).
So far I have been scaling Mysql by throwing more hardware and focusing only on performance issues detected by new relic or my custom report but there were some data driven anomalies where 99% calls to this query would take 1sec but one call to same query would take 10sec. I wasn’t focusing much on it because it was a blip in the graph and there were too many other issues to focus on.
Now we got a full time Mysql engineer who is looking at these queries and hunting down suspects. Today he found this query
select sum(points) from (
select g.all_versions_size as points from folders_trash f
inner join groups g on f.folder_id = g.folder_id
union all
select e1.size as points from groups_trash g1
inner join entries e1 on g1.group_id=e1.group_id
union all
select e2.size as points from entries_trash e2
) s
Now this query works 99% of the time faster because most customers have very few data in trash but some customers have 400K+ rows in trash and for them this was creating a temp table with 400K rows causing the blip.
Changing this query to something like below would create only 3 temp table row, the query became fast and uses less resources.
select sum(points) from (
select sum(g.all_versions_size) as points from folders_trash f
inner join groups g on f.folder_id = g.folder_id
union all
select sum(e1.size) as points from groups_trash g1
inner join entries e1 on g1.group_id=e1.group_id
union all
select sum(e2.size) as points from entries_trash e2
) s
So don't lose hope, find creative ways initially like throwing more hardware to the problem if you can. When you reach scale expert help will come on the way :).
Comments
Post a Comment