Home > Net >  how to improve mongoDB write in a big collection
how to improve mongoDB write in a big collection

Time:03-14

I have a collection it have 2 billion documents,and it have 3 shardings I allot 20G memory to every sharding .It write very slow now and I use mongostate to monitor it, It only write 200 documents every second avg,and others is noraml,and I do not have any index,and I don't know what to do.

insert query update delete getmore command dirty  used flushes vsize   res  qrw  arw net_in net_out conn    set repl                time
   127    *0     *0     *0       9     9|0  2.8% 76.5%       0 12.0G 9.59G  0|0  1|6   224k    263k   80 shard1  PRI Mar 11 16:08:38.710
   115    *0     *0     *0       6    13|0  2.7% 76.6%       0 12.0G 9.60G  0|1  1|3   185k    166k   80 shard1  PRI Mar 11 16:08:39.625
   137    *0     *0     *0      11     8|0  2.7% 76.7%       0 12.0G 9.60G  0|0  1|3   231k    369k   80 shard1  PRI Mar 11 16:08:40.625
   135    *0     *0     *0      21    27|0  2.8% 76.7%       0 12.0G 9.60G  0|0  1|2   263k    340k   80 shard1  PRI Mar 11 16:08:41.625
   119    *0     *0     *0       9    15|0  2.8% 76.7%       0 12.0G 9.60G  0|0  1|6   220k    212k   80 shard1  PRI Mar 11 16:08:42.702
   111    *0     *0     *0       4     9|0  2.8% 76.7%       0 12.0G 9.60G  0|0  1|8   195k    206k   80 shard1  PRI Mar 11 16:08:44.115
   154    *0     *0     *0      15    19|0  2.9% 76.8%       0 12.0G 9.60G  0|0  1|3   282k    441k   80 shard1  PRI Mar 11 16:08:44.625
   150    *0     *0     *0      13    20|0  2.9% 76.8%       0 12.0G 9.60G  0|0  1|1   258k    355k   80 shard1  PRI Mar 11 16:08:45.625
   127    *0     *0     *0      15    17|0  2.9% 76.8%       0 12.0G 9.60G  0|0  1|4   231k    311k   79 shard1  PRI Mar 11 16:08:46.625
   113    *0     *0     *0      11    11|0  3.0% 76.9%       0 12.0G 9.60G  0|0  1|5   215k    278k   79 shard1  PRI Mar 11 16:08:47.738

and IOPS

Device:         rrqm/s   wrqm/s     r/s     w/s    rMB/s    wMB/s avgrq-sz avgqu-sz   await r_await w_await  svctm  %util
sda               0.00     0.00  161.00  299.50     3.99     4.86    39.34     8.55   18.47   49.90    1.

CodePudding user response:

Options:

1) Improve storage performance:

A. Add better disks HDD(bad choise)->SSD(better)->NVME SSD(excellent)

B. Tweak operating system/file system ( mount with noatime , split across phisical volumes for better IOPS )

C. Mount journal files to different volume.

2) Improvements from mongoDB:

A. Pre-split collection.

B. Add more shards.

C. Switch off FTDC.

D. Optimize writeConcern.

E. You say you dont have any indexes and you have sharded in 3x shards ? ( I think you need to have at least one index to be able to shard the collection , you maybe need to evaluate and check if this is correct shard index )

F. Reduce number of replicaSet members if possible in the initial loading. ( majority write concern in 7 members will requiere insert to be confirmed by 4x members )

3) Improvements from application:

A. Reduce writeConcern if possible.

B. Insert in paralel batches instead of single sequential inserts.

Please, share some more details like schema , shard distribution etc?

  • Related