use reservoir algorithm to save memory