我想檢查一下與MySQL相比,CouchDB可以處理多少個插入。我的測試很簡單:持續10秒,插入{firstName: "Testing 001", lastName: "Testing 002"}
並比較文檔/行數。我得到的結果從我的期望遠:使用CouchDB的插入非常緩慢?
- 的MySQL的MyISAM 110000行
- 的MySQL的InnoDB:52000行
- CouchDB的:文件!
如果我錯了,請糾正我,但是在簡單操作中,NoSQL總是要勝過關係數據庫嗎?我不希望有如此巨大的差異。也許我的測試是天真的,我不應該以這種方式比較這些數據庫?我知道MySQL驅動程序有權訪問連接池,並且不必在每個請求上重新創建TCP連接,但它是否會產生如此大的差異?
應該CouchDB插入如此緩慢,如果不是如何做到這一點的權利?
我經營一個乾淨的CouchDB數據庫測試(無任何設計文件)/ MacBook Pro的2.6GHz的i7處理器,16GB內存,SSD/CouchDB的1.4.0
測試腳本:
var nano = require('nano')('http://localhost:5984');
var async = require('async');
var db = nano.db.use('test');
var mysql = require('mysql');
var connection = mysql.createConnection({
host : 'localhost',
user : 'root',
password : '',
database: 'test'
});
/*
connection.connect(function(err){
var t = new Date().getTime() + 10000;
var i = 0;
var page = 2,
lastPage = 100;
async.whilst(function() {
return new Date().getTime() < t;
},
function (next) {
connection.query('INSERT INTO test (firstName, lastName) VALUES ("Testing 001","Testing 002")', function(err, rows, fields) {
i += 1;
next();
});
},
function (err) {
console.log(i);
connection.end();
});
});
*/
var t = new Date().getTime() + 10000;
var i = 0;
var page = 2,
lastPage = 100;
async.whilst(function() {
return new Date().getTime() < t;
},
function (next) {
db.insert({firstName: "Testing 001", lastName: "Testing 002"}, 'id-' + i, function(){
i += 1;
next();
});
},
function (err) {
console.log(i);
connection.end();
});
//編輯:
事實證明,問題不在於CouchDB方面。有一些關於客戶端的庫/驅動程序,使他們很慢。使用apache基準測試的簡單POST測試在CouchDB端顯示出非常好的結果:
$ ab -n 10000 -c 100 -p post-data -T "application/json" "http://192.168.50.102:5984/test/"
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking 192.168.50.102 (be patient)
Completed 1000 requests
Completed 2000 requests
Completed 3000 requests
Completed 4000 requests
Completed 5000 requests
Completed 6000 requests
Completed 7000 requests
Completed 8000 requests
Completed 9000 requests
Completed 10000 requests
Finished 10000 requests
Server Software: CouchDB/1.5.0
Server Hostname: 192.168.50.102
Server Port: 5984
Document Path: /test/
Document Length: 95 bytes
Concurrency Level: 100
Time taken for tests: 1.149 seconds
Complete requests: 10000
Failed requests: 0
Write errors: 0
Total transferred: 4120412 bytes
Total POSTed: 1920960
HTML transferred: 950095 bytes
Requests per second: 8704.85 [#/sec] (mean)
Time per request: 11.488 [ms] (mean)
Time per request: 0.115 [ms] (mean, across all concurrent requests)
Transfer rate: 3502.69 [Kbytes/sec] received
1632.98 kb/s sent
5135.67 kb/s total
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.1 0 2
Processing: 6 11 2.6 11 23
Waiting: 6 11 2.6 11 22
Total: 6 11 2.6 11 25
「 NoSql比RDBMS更快「並不普遍。數據庫有長處和短處,這可能是其中一種情況。這種類型的測試的問題在於它可能突出顯示弱點,但沒有顯示CouchDb可能擅長的地方。如果您試圖強制或脅迫NoSql DB表現得像RDBMS一樣,結果往往會混雜到差。 – WiredPrairie
我同意我喜歡理解優點和缺點。我認爲對任何系統來說,簡單的INSERT/SELECT都不是什麼大的挑戰。這就是爲什麼我對結果感到困惑。 –
寫入通常是數據庫系統中最昂貴的操作。我想我會將測試切換到實際上是異步的,以便一次允許多個連接/插入。 – WiredPrairie