rvagg/node-leveldown — pull request #68 by JerrySievert (2013-10-18 23:53:22+00:00)
Title: [discussion] first pass at a multiget

this is a discussion pull request.

i've added `multiget`, which accepts an array of id's to retrieve, and operates similar to `get`. for each key, a `ReadWorker` is queued. on each `get`, the callback is fired with either an error if a key is not found, or the record.

there may be bugs (likely are, my c++ is rusty, and the last time i wrote against v8 was node v0.4.x), and there may be a better way to do this - hence the discussion.

against 620,350 records requested, the speed difference is about 20% faster. the speedup comes from needing to cross the `v8 <-> c++ <-> v8` boundary less times. with `get`, there are 620,350 requests, and 620,350 callbacks, resulting in 1,240,700 crossings of the boundary. `multiget` reduces this to 620,351.

here's the script test with `multiget`:

```
var leveldown = require('./index');

var db = leveldown('../data/buildings');
var indexes = require('../data/indexes.json');
var count = 0;
db.open(function () {
console.log(arguments);
var start = +new Date();
db.multiget(indexes, function () {
count++;

if (count === indexes.length) {
var end = +new Date();
console.log('done!', end - start, count);
}
});

});
```

and the same with `get`:

```

var leveldown = require('./index');

var db = leveldown('../data/buildings'),
indexes = require('../data/indexes.json'),
count = 0, i;
db.open(function () {
console.log(arguments);
var start = +new Date();
for (i = 0; i < indexes.length; i++) {
db.get(indexes[i], function () {
count++;

if (count === indexes.length) {
var end = +new Date();
console.log('done!', end - start);
}
});
}

});
```

thoughts?