函数式编程范式-MapReduce
2008-08-07 16:48 分类:Hadoop, MapReduce
一个月前有人问我什么是函数式编程?虽然熟悉一些函数式编程的概念,那本半年前从托人从加拿大买的The Little Schemer也就看了前面几章,那天就是回答不了究竟什么是函数式编程。函数式编程对于熟悉过程式程序设计的程序员来说是一个陌生的领域,闭包(closure),延续(continuation),和柯里化(currying)等概念对于过程式程序设计的程序员是个噩梦。
Without understanding functional programming, you can't invent MapReduce,the algorithm that makes Google so massively scalable. The terms Map and Reduce come from Lisp and functional programming. MapReduce is, in retrospect, obvious to anyone who remembers from their 6.001-equivalent programming class that purely functional programs have no side effects and are thus trivially parallelizable. The very fact that Google invented MapReduce, and Microsoft didn't, says something about why Microsoft is still playing catch up trying to get basic search features to work, while Google has moved on to the next problem: building Skynet^H^H^H^H^H^H the world's largest massively parallel supercomputer. I don't think Microsoft completely understands just how far behind they are on that wave.
上段内容摘自 Joel Spolsky的Blog,明白的解释了函数式编程模型是MapReduce的灵感。
MapReduce的名字源于函数式编程模型中的两项核心操作:Map和Reduce。也许熟悉Functional Programming(FP)的人见到这两个词会倍感亲切。因为Map和Reduce这两个术语源自Lisp语言和函数式编程。Map是把一组数据一对一的映射为另外的一组数据,其映射的规则由一个函数来指定。Reduce是对一组数据进行归约,这个归约的规则由一个函数指定。Map是一个把数据分开的过程,Reduce则是把分开的数据合并的过程。如Hadoop的wordcount例子:用Map把[one,word,one,dream]进行映射就变成了[{one,1}, {word,1}, {one,1}, {dream,1}],再用Reduce把[{one,1}, {word,1}, {one,1}, {dream,1}]归约变成[{one,2}, {word,1}, {dream,1}]的结果集。
Web客户端Js访问不同域中数据的解决方法
2008-02-21 09:34 分类:Web
Web客户端Js访问不同域中数据一直存在一些问题,比如A站点:a.com 要访问B站点:b.com的数据采用Ajax访问时会出现跨域的安全性问题,无法取得b.com的xml文档。好多项目都是采用在a.com写一个Proxy来代理访问b.com。流程图如下:
web client -> a.com -> b.com -> a.com ->web client
这种请求即费时间又浪费带宽,我们是不是可以修改上面的流程让客户端直接访问b.com呢?
web client -> b.com -> web client
所幸的是我们可以这么做。我们有一种数据表达方式叫JSON.来处理远程登陆。这种格式可以 让Javascript不使用XMLHTTPRequest对象来获得数据,更有用的是我们可以取得不同域的数据抛开我们的Proxy。所要求的是b.com增加一些数据传 输格式。我们更可以在服务端扩展JSON输出格式让Python和Ruby,C++,Php,Java,C#,Perl来读取数据.以便各种语言的客户端能够获取数据。