In the spawn chunks, use a command block with the command:
/testfor @a/testfor @a
withWith a comparator coming out of it connected to a block., place redstone dust on top of the block leading to a command block with the command:
/gamerule randomTickSpeed (speed, default is 3)/gamerule randomTickSpeed (speed, default is 3)
and a torch going out of the block with redstone dust connecting it to a command block with the command:
/gamerule randomTickSpeed 0/gamerule randomTickSpeed 0