Permalink
Browse files

learn git

  • Loading branch information...
1 parent c2824f4 commit fd1572a655057496f8c9d37bfe6b9db2355d198e @randomekek committed Feb 19, 2011
Showing with 56 additions and 3 deletions.
  1. +41 −0 README.md
  2. +15 −3 test.js
View
@@ -0,0 +1,41 @@
+# node-cask
+
+This is a clone of bitcask log-based key-value store for node.js
+
+It is a simple implementation ~140 lines of code.
+
+The backing to file system uses node-mmap to persist the data to disk. See https://github.com/bnoordhuis/node-mmap
+
+## Blocking
+
+The main issue of using mmap is that it is blocking, so use this library carefully! However, the way mmap works, reads are directly from memory when the OS caches the files.
+
+In the test.js file provided I can get around 250k random reads/sec and 60k writes/sec. These writes are of size: 50 char keys and 800 char values.
+
+On my computer with about 2gb ram, when the data size is over 1.5gb the read performance falls off a cliff.
+
+Although blocking, performance is acceptable if:
+* More reads than writes and
+* Data set fits in memory
+
+## Complete API overview
+
+ var cask = require('./cask'),
+ db = cask.open('name');
+
+ // returns null
+ var x = db.get('missing key');
+
+ // sets a key
+ db.set('hello בעולם', 'hello 世界');
+
+ // fetches the value
+ var x = db.get('hello בעולם');
+
+## Log based
+
+The main issue with log-based stores is that it will spit out lots of files.
+
+Your changes do not get updated in place on the backing store. This is a downside for filesize, but good for disk write speed.
+
+Bitcask paper did not have a description of how to do continuous compaction.
View
18 test.js
@@ -1,7 +1,8 @@
var cask = require('./cask'),
assert = require('assert');
-var write = true;
+var write = true,
+ randomread = true;
var f = cask.open('temp');
@@ -20,10 +21,21 @@ var value = 'not particularly long value that will get stored.\n';
for(i=0; i<4; i++) {
value += value;
}
-for(i=0; i<100000; i++) {
+
+var start = new Date().getTime();
+for(i=0; i<200000; i++) {
if(write) f.set('key prefix to increase key size a little bit' + i, value);
}
+var end = new Date().getTime();
+if(write) console.log('write test: ' + (end - start)/1000.0 + 's');
+
+assert.ok(f.get('key prefix to increase key size a little bit' + 89293) == value);
-assert.ok(f.get('key prefix to increase key size a little bit' + 39488) == value);
+var start = new Date().getTime();
+for(i=0; i<200000; i++) {
+ if(randomread) assert.ok(f.get('key prefix to increase key size a little bit' + Math.floor(Math.random()*200000)) == value);
+}
+var end = new Date().getTime();
+if(randomread) console.log('random read test: ' + (end - start)/1000.0 + 's');
f.close();

0 comments on commit fd1572a

Please sign in to comment.