You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

为何MongoDB分片集群写入性能低于单实例?求优化建议

MongoDB分片集群插入性能低于单实例的问题排查请求

我在3台Red Hat Enterprise Linux release 8.6服务器上搭建了MongoDB分片集群,使用YCSB工具插入100万条记录进行性能测试。每条记录包含11个字段(1个字符串、10个二进制),以_id作为分片键,执行命令sh.shardCollection("ycsb.usertable", {_id: 1})启用分片。

测试结果

单MongoDB实例

bin\ycsb.bat run mongodb -P workloads\workloada -p operationcount=1000000 -threads 200 -p mongodb.batchsize=1 -p mongodb.url="mongodb://ycsb:ycsb_1234@127.0.0.1:20017/ycsb"

[OVERALL], RunTime(ms), 99762
[OVERALL], Throughput(ops/sec), 10023
[INSERT], Operations, 1000000
[INSERT], AverageLatency(us), 19613

分片集群

bin\ycsb.bat run mongodb -P workloads\workloada -p operationcount=1000000 -threads 200 -p mongodb.batchsize=1 -p mongodb.url="mongodb://ycsb:ycsb_1234@[127.0.0.1:20020],[127.0.0.2:20020],[127.0.0.3:20020]/ycsb"

[OVERALL], RunTime(ms), 146067
[OVERALL], Throughput(ops/sec), 6846
[INSERT], Operations, 1000000
[INSERT], AverageLatency(us), 28239

我疑惑为何分片集群的性能反而低于单实例架构?以下是我的集群配置,恳请各位提供建议,谢谢。

集群配置信息

基础架构信息

Mongo DB版本:4.2.24
Server address:127.0.0.1、127.0.0.2、127.0.0.3
Mongos port:20020
Config port:20010
Shard1 port:20001
Shard2 port:20002
Shard3 port:20003

集群架构图

配置服务器配置

systemLog:
    destination: file
    path: "/mongodb/config/config.log"
    logAppend: true
storage:
    dbPath: "/mongodb/config"
    engine: "wiredTiger"
    directoryPerDB: true
    wiredTiger:
        engineConfig:
            cacheSizeGB: 1
            directoryForIndexes: true
            statisticsLogDelaySecs: 0
        collectionConfig:
            blockCompressor: "snappy"
        indexConfig:
            prefixCompression: true
    journal:
        enabled: true
processManagement:
    fork: true
net:
    bindIp: 127.0.0.1 #other server would be 127.0.0.2, 127.0.0.3
    port: 20010
replication:
    oplogSizeMB: 1024
    replSetName: configrs
sharding:
   clusterRole: configsvr

分片节点配置

systemLog:
    destination: file
    path: "/mongodb/shard1/shard.log"
    logAppend: true
storage:
    dbPath: "/mongodb/shard1"
    engine: "wiredTiger"
    directoryPerDB: true
    wiredTiger:
        engineConfig:
            cacheSizeGB: 1
            directoryForIndexes: true
            statisticsLogDelaySecs: 0
        collectionConfig:
            blockCompressor: "snappy"
        indexConfig:
            prefixCompression: true
    journal:
        enabled: true
processManagement:
    fork: true
net:
    bindIp: 127.0.0.1 #other server would be 127.0.0.2, 127.0.0.3
    port: 20001
replication:
    oplogSizeMB: 1024
    replSetName: shardrs1
sharding:
   clusterRole: shardsvr

Mongos配置

systemLog:
    destination: file
    path: "/mongodb/mongos/mongos.log"
    logAppend: true
processManagement:
    fork: true
net:
    bindIp: 127.0.0.1 #other server would be 127.0.0.2, 127.0.0.3
    port: 20020
sharding:
    configDB: configrs/127.0.0.1:20010,127.0.0.2:20010,127.0.0.3:20010

内容的提问来源于stack exchange,提问作者EvaHHHH

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.24 18:04:59