WriteConcern w>1 is very slow for writing

Hi, I would like to know why the writeConcern w>1 is very slow for writes when de PRIMARY e SECONDARY are on the same network. I just want use SECONDARY for consistent READS for use in application. Below my tests.

for (i=0; i<number; i++) {db.inventory.insert({ sku: “abcdxyz”, qty : 100, category: “Clothing” },{ writeConcern: { w: x, j: true, wtimeout: 1000 } })}

w1: 10.000 documents

$ time mongo localhost --port 27017 --username "admin" --password "admin" --authenticationDatabase "admin" < w1.txt
MongoDB shell version v4.2.8
real    0m23.195s

w2: 10.000 documents

$ time mongo localhost --port 27017 --username "admin" --password "admin" --authenticationDatabase "admin" < w2.txt
MongoDB shell version v4.2.8
real    1m41.394s

w1: 100.000 documents

time mongo localhost --port 27017 --username "admin" --password "admin" --authenticationDatabase "admin" < w1.txt
MongoDB shell version v4.2.8
real    3m36.208s

w2: 100.000 documents

$ time mongo localhost --port 27017 --username "admin" --password "admin" --authenticationDatabase "admin" < w2.txt
MongoDB shell version v4.2.8
real    16m33.480s

Hi @Eduardo_Legatti,

As you increase your write concern your client is required to wait for asynchronous replication to replicate the written to n number of secondaries as specified in write concern.

The more consistent your write is configured to be the more time it might take to write the data…

Moreover, the more documents you write simultaneously the bigger the replication lag might be causing subsequent writes to get slower and slower as they are waiting longer.

Even though the members are in the same network does not mean that asynchronous replication can’t be impacted by disk,cpu or ram factors for slow operations.

Specific mongo versions might introduce additional behaviour on the way reads are impacting replication, be aware.

Please read more here

Pavel

1 Like

Hi Pavel,

So, I think using secondary members to scale reads is not a good approach, rigth?

Thanks.

Hi @Eduardo_Legatti,

I suggest you to read the following answer:

Thanks
Pavle

1 Like

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.