Couchdb:
引用
Apache CouchDB is a distributed, fault-tolerant and schema-free document-oriented database accessible via a RESTful HTTP/JSON API. Among other features, it provides robust, incremental replication with bi-directional conflict detection and resolution, and is queryable and indexable using a table-oriented view engine with JavaScript acting as the default view definition language.
Couchdb是以Rest方式来完成操作的分布式文档数据库,要多Couchdb完成操作的话,必须通过执行Http请求。传统数据库是通过DBAdapter完成消息传递的,那么可以认为:Http请求的效率和传统的DBAdapter请求的效率,在一定程度上影响着Couchdb和传统数据库的性能。
在Couchdb中,拿插入数据来说,每次插一条数据,客户端必须发起一次put请求,Couchdb再接受这个请求并作处理。下面我就要做这样的一次测试,来比较Couchdb和Mysql两种数据库的插入数据的速度。插mysql和couchdb的操作都从客户端发起,mysql和couchdb同时装在一台server上。通过benchmark记录操作耗时。
测试环境:一台server,一台client,
server:DELL1950划分的一台虚拟机,cpu:2,mem:2GB
mysql:Server version: 5.0.67-0ubuntu6 (Ubuntu)
couchdb:Apache CouchDB 0.8.0-incubating (LogLevel=info)
文件系统:
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda1 ext3 85G 1.5G 80G 2% /
tmpfs tmpfs 1013M 0 1013M 0% /lib/init/rw
varrun tmpfs 1013M 356K 1012M 1% /var/run
varlock tmpfs 1013M 0 1013M 0% /var/lock
udev tmpfs 1013M 2.6M 1010M 1% /dev
tmpfs tmpfs 1013M 0 1013M 0% /dev/shm
client:普通台式机
测试场景:
1、mysql和couchdb各插入1000条数据对比耗时。
2、mysql和couchdb各插入10000条数据对比耗时。
测试代码如下:
require 'rubygems'
require 'couchdb'
require 'active_record'
require 'active_record/vendor/mysql'
require 'pp'
ActiveRecord::Base.establish_connection(
:adapter=>"mysql",
:encoding=>"utf8",
:database=>"couchdbvsmysql",
:username=>"root",
:password=>"******",
:host=>"1.2.3.4")
#A database must be named with all lowercase characters (a-z), digits (0-9), or any of the _$()+-/ characters
#and must end with a slash in the URL. The name has to start with characters.
server = Couch::Server.new("10.2.226.133", "5984")
server.put("/couchdbvsmysql/", "")
seq1=1
seq2=1
print "-----------------------------------------------------------------\n"
print " Insert Records \n"
print "-----------------------------------------------------------------\n"
sql=proc {<<SQL
insert into udb_user(user_id,user_name,creator)
values("#{(seq1+=1).round}","user#{(rand*10**10).round}","CuiZheng#{seq1}")
SQL
}
json=proc{<<JSON
{"user_id":"#{seq2+=1}","user_name":"user#{(rand*10**10).round}","creator":"CuiZheng#{seq2}"}
JSON
}
InsertIntoMysql=proc do |x|
proc do
x.times{ActiveRecord::Base.connection.execute(sql.call.gsub("\n"," "))}
end
end
InsertIntoCouchdb=proc do |x|
proc do
x.times{server.put("/couchdbvsmysql/#{seq2}",json.call.gsub("\n"," "))}
end
end
Benchmark.bm(25) do |x|
x.report("InsertIntoMysql",&(InsertIntoMysql.call(10**4)))
x.report("InsertIntoCouchdb",&(InsertIntoCouchdb.call(10**4)))
end
场景一(插入1000条数据测试结果):
-----------------------------------------------------------------
Insert Records
-----------------------------------------------------------------
user system total real
InsertIntoMysql 0.171000 0.062000 0.233000 ( 7.297000)
InsertIntoCouchdb 1.922000 1.219000 3.141000 ( 27.969000)
这里可以看到,Couchdb的确比Mysql的插入速度慢,而且慢很多,四倍的差距。
场景二(插入10000条数据测试结果):
-----------------------------------------------------------------
Insert Records
-----------------------------------------------------------------
user system total real
InsertIntoMysql 2.187000 0.547000 2.734000 ( 12.953000)
InsertIntoCouchdb D:/ruby/lib/ruby/1.8/net/http.rb:560:in `initialize': 通常每个套接字地址(协议/网络地址/端口)只允许使用一次。 - connect(2) (Errno::EADDRINUSE)
from D:/ruby/lib/ruby/1.8/net/http.rb:560:in `open'
from D:/ruby/lib/ruby/1.8/net/http.rb:560:in `connect'
from D:/ruby/lib/ruby/1.8/timeout.rb:53:in `timeout'
from D:/ruby/lib/ruby/1.8/timeout.rb:93:in `timeout'
from D:/ruby/lib/ruby/1.8/net/http.rb:560:in `connect'
from D:/ruby/lib/ruby/1.8/net/http.rb:553:in `do_start'
from D:/ruby/lib/ruby/1.8/net/http.rb:542:in `start'
from D:/ruby/lib/ruby/1.8/net/http.rb:440:in `start'
... 7 levels...
from F:/MySummary/MyRails/RubyApplication1/lib/CouchdbVsMysqlPerf.rb:54
from D:/ruby/lib/ruby/1.8/benchmark.rb:177:in `benchmark'
from D:/ruby/lib/ruby/1.8/benchmark.rb:207:in `bm'
from F:/MySummary/MyRails/RubyApplication1/lib/CouchdbVsMysqlPerf.rb:52
跑了很多次,都会报“通常每个套接字地址(协议/网络地址/端口)只允许使用一次。”这个异常。这个原因估计是某个请求花了很长的时间没有释放客户端的套接字导致,可能是couchdb那边一时处理不过来了,我猜的。
解释一下benchmark:
lgn21st 写道
benchmark的report显示的信息是:
This report shows the user CPU time, system CPU time, the sum of the user and system CPU times, and the elapsed real time. The unit of time is seconds.
即用户cpu时间,系统时间,用户系统时间合,实际耗时,单位是秒。
跑完之后可以通过浏览器来看一下couchdb的状态:
列出couchdb所有数据库:
http://10.2.226.133:5984/_all_dbs
浏览器显示:
["couchdbvsmysql"]
列出数据库couchdbvsmysql的状态:
http://10.2.226.133:5984/couchdbvsmysql
浏览器显示:
{"db_name":"couchdbvsmysql","doc_count":1000,"doc_del_count":0,"update_seq":1000,"compact_running":false,"disk_size":2376834}
这个是跑插1000条数据后的结果。
通过上面的结果,我随便说说,Couchdb的插入速度的确比Mysql慢。作为一个分布式数据库,Couchdb首先应该解决的问题是:调整Erlang Http服务器的速度,不要出现插入10000条数据时出现的处理不过来的情况(我猜可能是服务器那边响应过长导致),然后找出适合Couchdb的一个文件系统(我想一个文档式数据库的磁盘读写速度应该和文件系统的类型关系很大)。本次测试结果是单台Couchdb,不能和已经部署成分布式的数据库作对比,等Couchdb的高版本支持分布式之后再来测试。
- 大小: 35.2 KB
分享到:
相关推荐
转换器在 CouchDB 和 MySQL 之间同步数据的小工具为什么? 好吧,我向一个人展示了 CouchDB,第一个问题是……“你能与 MySQL 同步吗?” “PouchDB 可以与 MongoDB/MySQL/我当前的非 CouchDB 数据库同步吗?不能。...
p2000-沙发到-mysql P2000 消息从 CouchDB 到 MySQL 数据库的同步脚本。 脚本: 应用程序.js CouchDB 和 MySQL 之间的实时同步; 当前未使用; 不如 SYNC-BACK.JS 干净-couchdb.js 只是另一个文件的副本,尚未使用;...
我目前正在这些基准测试上,以获取有关CouchDB扩展属性的第一手数据。 我特别关心磁盘使用情况(弄清楚何时需要分片)和复制速度。 但是,在此过程中,我还将收集其他可能有用的信息,但请记住,我的测试方法将明确...
插入自定义函数以在写入数据之前添加您自己的更改。 批量写入数据以提高速度。 还可以使用流式JSON解析器读取巨大的JSON文件。 允许使用--parallelism选项一次执行多个HTTP写操作。 安装 要求 node.js = npm ...
CouchDB
出版时间:2012年9月1日。 内容简介: 三位CouchDB的开发者向你展示了如何以独立应用框架的形式来使用这一面向文档的数据库,以及如何使用它来构建高容量、分布式的...* 优化CouchDB来适应不断提高的性能和可靠性要求。
一个非常简单的基于 PHP 的基准测试程序,用于比较批量文档插入的速度 沙发数据库 MongoDB 数据库 它将批量文档发送到数据库的批量文档 API: CouchDB 的 bulk_docs HTTP API MongoDB 的 collection->batchInsert...
Beginning CouchDB.pdf
学习couchDB 的入门教程
Python CouchDB模块,使用:直接将其中的couchdb文件夹复制到Python27\Lib文件夹下,即可使用import couchdb按照文档进行后续开发。
couchdb源码
Fabric 1.4基于couchdb环境搭建步骤,以及基于couchdb的区块链多字段数据查询
之前整理的关于CouchDB技术的内容 类型:开源数据库,Apache项目 存储格式:JSON 查询语言:JavaScript API :MapReduce、HTTP
CouchDb的三位创建者向您展示了如何将此面向文档的数据库用作独立的应用程序框架或用于大量分布式应用程序。
sofa-CouchDB 是 CouchDB 的独立博客,使用 CouchDB 的书来做主要内容,这方便了所有用来在这博客上交流他们的想法,并且里面提供了很多帮助指导,这都是 HTML,Javascript 和 CouchDB 的结晶。目前支持任何人在上面...
CouchDB 是一个开源的面向文档的数据库管理系统,可以通过 RESTful JavaScript Object Notation (JSON) API 访问。...CouchDB 最初是用 C++ 编写的,但在 2008 年 4 月,这个项目转移到 Erlang OTP 平台进行容错测试
CouchDB 是一个开源的面向文档的数据库管理系统,可以通过 RESTful JavaScript Object Notation (JSON) API 访问。...CouchDB 最初是用 C++ 编写的,但在 2008 年 4 月,这个项目转移到 Erlang OTP 平台进行容错测试
This book introduces you to Apache CouchDB, a document-oriented database that offers a different way to model your data. CouchDB is a schema-free database, designed to work with applications that ...
Apache CouchDB 是一个开源的 NoSQL 文档数据库,以基于 JSON 的文档格式收集和存储数据,提供了高可用性和高可靠性。近日,深信服安全团队监测到 Apache CouchDB 组件存在信息泄露漏洞,漏洞编号:CVE-2023-26268...
辛星 MySQL、Linux、Node、Nginx、Redis、CouchDB、Git 教程 2015