MongoDb journal in write concern

2.5k views Asked by At

I wrote a test program to check mongodb write performance with or without journaling: Items to be inserted: 10000

case1: insert with (w = 1, j = 1) result: 10000 documents inserted in 340,620 ms (about 29 documents per second)

case2: insert with (w = 0, j = 1) result: 10000 documents inserted in 360ms (about 27700 documents per second)

What does (w = 0, j = 1) mean?

do we have durability in case2?

1

There are 1 answers

7
Sammaye On BEST ANSWER

Providing that the working of journaled has not changed in the last version I believe what you are seeing is the speed of w=0. Since you have w=0 ( http://docs.mongodb.org/manual/core/write-concern/#unacknowledged ) you are only acknowledging that the command was sent to the MongoDB instance(s).

The behaviour of w=0 was changed from socket acknowledged in earlier versions of MongoDB which could not mitigate network errors because of that.

So the value of w=0 is overriding the value of j=1 and causing unacknowledged writes, however, the durability should theorticially be the same since j=1 still causes:

http://docs.mongodb.org/manual/core/write-concern/#journaled

MongoDB also increases the frequency that it commits operations to the journal.

But:

Unacknowledged is similar to errors ignored; however, drivers will attempt to receive and handle network errors when possible.

Good to note that "errors ignored". If you get an error while updating/inserting them you would not be told about it, but ignoring documents with errors, your durability should be relatively the same.

Of course, it is not as good as actually doing a w=1 but it is not as bad as socket acknowledged (old w=0) which could lose massive amounts of writes.

So you are getting the speed of w=0 with short intervals to journal as if they are all journal acknowledged.