I'm a developer of a social game where we have almost 2 millions players(and this number is growing).
The master MySQL DB server has 24 Gb RAM and the database could fit into the memory if it wasn't for one table which has really large size. Currently it has almost a billion of records and its size is 33Gb. It has the following schema:
CREATE TABLE `plant` (
`player_id` int(10) unsigned NOT NULL DEFAULT '0',
`id` mediumint(8) unsigned NOT NULL DEFAULT '0',
`x` tinyint(3) unsigned NOT NULL DEFAULT '0',
`y` tinyint(3) unsigned NOT NULL DEFAULT '0',
`distort_step` tinyint(3) unsigned NOT NULL DEFAULT '0',
`grow_step` tinyint(3) unsigned NOT NULL DEFAULT '0',
`proto_id` int(10) unsigned DEFAULT '0',
`yflip` tinyint(4) NOT NULL DEFAULT '0',
`grow_start` int(10) unsigned NOT NULL DEFAULT '0',
PRIMARY KEY (`player_id`,`id`)
) ENGINE=InnoDB
I'm thinking about the following plan on how to optimize it:
Add a similar table with "archive_" prefix
Partition this new table by hash
Figure out inactive players who haven't played the game, say, for a month.
Copy their records from the big table to the archive table
Mark the player being archived and use the archive table instead the original one whenever he/she logs in
Optionally partition the original table by hash as well(optionally, because it may cause lots of downtime)
If nothing helps think about sharding
What do you think about it? Does it sound like a good plan?