Realtime Metrics for 128 Million Users with Redis: 50ms + 16MB RAM
blog.getspool.com
blog.getspool.com
In my case, and it appears to be true for Spool too, I don't know what bit will be set first. It could be 12 or it could be 2938251, so to prevent a slowdown if the initial bit is a high place I use buckets of bitmaps, each holding around 8 million bits.
[1] Read Warning: http://redis.io/commands/setbit
For instance you want to set bit i, but you want k bits per every key, the you do:
keyname = "bitmap:"+(i/k)
keybit = i%k
k can be fairly large, like 128k bytes per key. It's still small but big enough for keys overhead to be negligible. var bucketSize = 8190;
...
var bucketNumber = Math.floor(userId / bucketSize),
bitInBucket = userId % bucketSize;
...correction on my last comment, looks like I use ~8 thousand bits per bucket, not 8 million.2 million users' actions could be tracked in 250k per metric. 10 metrics per day is 2.5m per day x 7 days is back to just over 16m (17.5m).
Redis has a mode which does this automatically I believe (and it's the default if I remember correctly).
I'm using MongoDB and IDs are 12-byte values of which the first four are a timestamp. Does anyone know of a way to make this method work, ideally without adding another field to the collection?
I hope it's clearer now.
was:
Realtime Metrics with Redis: 128 Million Users + 16MB RAM = 50ms
is: Realtime Metrics for 128 Million Users with Redis: 50ms + 16MB RAM