I am not ready to say that Riak would be the right solution here,
although I think it could work. You have some good things going for
you. A specific, well defined spec and immutable data. Using the
criteria you provided it would not be that much work to spec out a
solution. If I were to use Riak, as it exists today, for this project
I would do the following:
-Make extensive usage of key filters.
Key filters is a mechanism by which you can construct a filter to
select, from memory, a subset of keys to pass to map/reduce. This
means that if you use meaningful key names you get a big win
performance wise, and in reality would be one of the only ways to do
this. In your case the naming convention I would use would be
something like "sensorname_timestamp". You could construct a filter
that would look for only keys starting with "sensorname" and having a
"timestamp" between A and B where timestamp is a unix int. See
http://wiki.basho.com/Key-Filters.html .
-Map/Reduce considerations:
Maps are distributed in Riak. Meaning that after your key list has
been constructed via the key filter phase, the coordinating node (Riak
is homogeneous - any node can service any request) will hash the keys
in the set to their corresponding nodes in the cluster and distributed
the requests to all those nodes. The cluster will fetch the keys from
all those nodes and return them - out of order - to the coordinating
node. The reduce, in this case a sort, is applied on the coordinating
node.
Things to think about is the total key set returned via the key
filter. Given your exacting parameters we can calculate that each
sensor will have a maximum of 60*60*24 keys per day which if you are
doing daily rollups would push 86,400 keys to your coordinating node.
Once hashed (relatively inexpensive) the fetch would be fanned out
across the cluster and the cluster would return 86,400*250 bytes of
data back to the coordinating node for sorting (I padded your payload
a touch). Recall that the reduce (sort in this case) is not
distributed. This means that your coordinating node is sorting 21MB
data. If you are writing your m/r in javascript you will incur a
penalty for the marshaling between the erlang vm and the javascript
vm. If you do use javascript I would pay attention to the javascript
specific vm config items in the config file, namely the number of js
vm's and their memory allocations. But in reality I would get the m/r
written in erlang - not hard considering the simplicity of your needs.
-File system backend
The other thing to consider is the number of keys per node in your
cluster. Bitcask, the default file backend for Riak, stores a hint
file of all its keys in memory. This means the more keys you have the
more memory you eat. Fortunately, there is a metric to ascertain
maximum capacity like so:
cluster ram = ( key size + overhead ) * number of keys
In your case the sheer number of 1trillion keys will exhaust the
capacity for total ram in a cluster. In short, you can absolutely not
do this with the bitcask backend and the current convention of 1 key
per sensor per second. Your only other alternative would be the innodb
backend and I would have a serious conversation with the Basho guys
about that. The other alternative would be to rollup your 86,400 keys
per day per sensor into 1 key , thereby reducing your total key count
to simply 10 k per day. Each key would have 20 some odd MB of data but
that is totally manageable. Of course, your rollup frequency can be
shortened from a day to an hour. But you get my point, if you want to
use Bitcask (which you probably do) you will need to reduce your
overall key count. See
https://spreadsheets.google.com/ccc?key=0Ak4OBkABJPsxdEowYXc2akxnYU9xNkJmbmZscnhaTFE&hl=en#gid=0
.
I've written a blog post a bit back re. pagination in riak but it goes
over some of the m/r consideration and Riak limitations,
http://siculars.posterous.com/paginating-with-riak .
I would post this exact question to the Riak mailing list and see what
the Basho folks say. That said, I would also take a look here:
http://discoproject.org/ . I saw the main developer give a demo at
erlang factory just today. It is pretty impressive and may be a good
fit. Think hadoop but switch java with erlang.
Do write back with your findings.
Cheers,
-Alexander
@siculars