繁体   English   中英

CouchDB插入速度很慢?

[英]Very slow inserts with CouchDB?

我想检查与MySQL相比,CouchDB还可以处理多少个插入。 我的测试很简单:持续10秒钟,继续插入{firstName: "Testing 001", lastName: "Testing 002"}然后比较文档/行数。 我得到的结果远远超出了我的预期:

  • MySQL MyIsam:110,000行
  • MySQL InnoDB:52,000行
  • CouchDB: 3,300个文档!

如果我错了,请纠正我,但是NoSQL在简单的操作中是否应该总是胜过关系数据库? 我不希望有如此巨大的差异。 也许我的测试是幼稚的,我不应该以这种方式比较那些数据库吗? 我知道MySQL驱动程序可以访问连接池,并且不必在每个请求上都重新创建TCP连接,但是它带来了很大的不同吗?

CouchDB插入应该这么慢吗?如果不是,该怎么做正确呢?

我在干净的CouchDB数据库上运行测试(没有任何设计文档)/ Macbook Pro 2.6Ghz i7、16GB RAM,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

您一次要插入一个文档吗? 您绝对应该使用批量文档加载工具进行实际比较:

http://docs.couchdb.org/en/latest/api/database/bulk-api.html#db-bulk-docs

在此处阅读有关CouchDB性能的更多信息:

http://guide.couchdb.org/draft/performance.html (有些过时,但仍很重要)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM