Quote
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.
Rest is Couchdb way to complete the operation of the distributed document database, it is necessary to complete the operation Couchdb many words, it is necessary to the implementation of Http requests. Traditional databases are completed through DBAdapter messaging, then can consider: Http request DBAdapter traditional efficiency and the efficiency of the request, to a certain extent affect the Couchdb and traditional database performance.
At Couchdb, the holding insert data for each time a data interpolation, the client must put the request to launch a, Couchdb no longer accept this request and make a deal. Now I do this on a test to compare two Couchdb and Mysql database Insert data speed. Play mysql and couchdb operation initiated from the client, mysql and couchdb loaded simultaneously on a single server. Record through the benchmark time-consuming operation.
Test environment: a server, a client,
server: DELL1950 division of one virtual machine, cpu: 2, mem: 2GB
mysql: Server version: 5.0.67-0ubuntu6 (Ubuntu)
couchdb: Apache CouchDB 0.8.0-incubating (LogLevel = info)
File System:
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: ordinary desktop
Test scenario:
1, mysql and insert couchdb the 1000 data, time-consuming.
2, mysql and insert 10000 the couchdb contrast time-consuming data.
Test code is as follows:
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 Scene 1 (1000 data insert test results):
-----------------------------------------------------------------
Insert Records
-----------------------------------------------------------------
user system total real
InsertIntoMysql 0.171000 0.062000 0.233000 ( 7.297000)
InsertIntoCouchdb 1.922000 1.219000 3.141000 ( 27.969000)
Here we can see, Couchdb indeed Mysql insertion than slower, but much slower, four times the gap.
Scene II (10000 data insert test results):
-----------------------------------------------------------------
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
Run a lot of times, will be reported to "usually each socket address (protocol / network address / port) to allow only used once." Anomaly. This is why estimates are requesting a flower for a very long time without the release of the client socket lead, there may be momentary couchdb to deal with, however, I guess.
To explain the benchmark:
lgn21st wrote
benchmark shown in the report information are:
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.
And the user cpu time, system time, the user system time together, the actual time-consuming unit is second.
Can be run through the browser's look at the status of couchdb:
Couchdb list of all databases:
http://10.2.226.133:5984/_all_dbs
The browser displays:
[ "couchdbvsmysql"]
Listed in the database couchdbvsmysql state:
http://10.2.226.133:5984/couchdbvsmysql
The browser displays:
( "db_name": "couchdbvsmysql", "doc_count": 1000, "doc_del_count": 0, "update_seq": 1000, "compact_running": false, "disk_size": 2376834)
This is run 1000 data interpolation results.
Through the top of the results of my casual, Couchdb insertion Mysql is indeed slower than slow. As a distributed database, Couchdb first question to be addressed are: adjust the speed of Erlang Http server, do not appear to insert 10,000 data appears to deal with the situation, however (I guess there may be a server in response to long lead), then Couchdb identify a suitable file system (I think a document database to read and write speed of disk and file system should be the type of relationship between the great). The test results are a single Couchdb, and should not have been deployed into a distributed database for comparison, such as high-version Couchdb Supporting distributed again after the test.







