CNode

nodejs map-reduce module for fun

分享
Llodengo发布于12 年前最后回复12 年前0 回复4863 浏览0 收藏

nodejs map-reduce for fun

CouchDB-style-like map-reduce:CouchDB

usage: world count example

var fs =  require('fs');
var worldCounter = new MapReduce({
    map: function(chunk){       
        chunk.toString().split(/\W+|\d+/).forEach(function(world){          
            world && this.emit(world.toLowerCase(), 1);
        }, this);
    },
    reduce: function(key, values){
        return this.count(values);
    },
    inputs:fs.readdirSync('./').map(fs.createReadStream)
});

worldCounter.pipe(process.stdout);

more think:

  1. should do reduce during mapping rather than wait until mapping done?
  2. use nodejs ChildProcess/Cluster fork to do map/reduce job?
  3. for processing and generating large data sets with a parallel, distributed algorithm on a cluster? you may look for Hadoop
查看回复

回复 (0)

暂无回复,成为第一个参与讨论的人。
参与回复
登录后即可参与回复。登录