couchdb剖析

很对不起这个题目,因为这个是转贴文章,我只是看了一部分,没有精力翻译。
感兴趣的朋友认真看一下吧:

from Ayende Rahien.
Reading Erlang: CouchDB - From REST to Disk in a few function calls
Erlang Reading: CouchDB - Digging Down to Disk
Reading Eralng: CouchDB Streams
Previous CouchDB articles by Ayende
Reading Erlang: Inspecting CouchDB
More CouchDB reading: btree:lookup
More CouchDB reading: btree:query_modify
等手头工作搞完了,一定认真的研究一下couchdb。
今天就说点“浅显”的东西,couchdb中使用mochiweb。
couchdb提供了HTTP API进行各种访问控制,灵活,方便,便于开发web应用。
其HTTP server基于mochiweb。
在couch_httpd.erl的start_link/3函数中:

Loop = fun (Req) -> apply(couch_httpd, handle_request, [Req, DocumentRoot]) end,
mochiweb_http:start([
[...]

mochiweb 分析-安装

(本文所阐述的环境为linux)
mochiweb是一个高效,轻量的web服务器,提供静态文件的http服务,其采用erlang开发。
mochiweb提供了一个web服务器的基本框架,开发人员可以进行相关扩展。
首先登录http://code.google.com/p/mochiweb/ 获取mochiweb的源头代码:
svn checkout http://mochiweb.googlecode.com/svn/trunk/
代码下载完成后,我们需要安装
$ cd trunk
$make
make完成后,我们需要建立一个demo,其运行在mochiweb的框架之上。
通过运行escript new_mochiweb.erl我们可以建立一个demo。
$./scripts/new_mochiweb.erl mochidemo ~/src
然后进入刚刚建立的mochidemo目录:
$cd ~/src/mochidemo
$make
建立demo。成功后运行:
$./start-dev.sh

=PROGRESS REPORT==== 29-Apr-2008::09:34:06 ===
application: mochidemo
started_at: nonode@nohost
表示您的web服务器已经开始运行,其默认端口为8000。
随后您可以在浏览器中或者erl中输入:http://127.0.0.1:8000查看web server是否工作正常。
在erl中可以使用http client进行请求:
$ erl
>: inets::start().
ok
>: http:request(”http://127.0.0.1:8000″).
>: {ok,{{”HTTP/1.1″,200,”OK”},
[{"date","Tue, 29 Apr 2008 02:01:30 GMT"},
{"server","MochiWeb/1.0 (Any of you quaids got a smint?)"},
{"content-length","88"},
{"content-type","text/html"}],
“<:html>:\n<:head>:\n<:title>:It Worked<:/title>:\n<:/head>:\n<:body>:\nMochiWeb running.\n<:/body>:\n<:/html>:\n”}}
好了mochiweb如何安装使用说清楚了,下面就是一步步的分析了。