Stat server: stat aggregation

Periodic writes to db instead of instant writes.