I am trying to check MongoDB performance before using it. I am trying to see how many documents I can update per second. I am using C # (Mono + Ubuntu) MongoDB Driver v1.9 and MongoDB v2.4.6.
I believe that one of the most efficient MongoDB options for write performance is Write Concern. As stated in the documentation , the most laid-back value for anxiety for writing would be -1, then, 0and finally, 1the slowest.
After searching, I found that I could fix write problems in C # built into the connection string, like this:
var client = new MongoClient("mongodb://localhost/?w=-1");
Here are the results that I play with different values for w:
- The fastest results are achieved when I install
win 1! - Setup is
w=0slower than w=128 times! w=-1will result in an exception being sent with an error message W value must be greater than or equal to zero!
Does anyone have an explanation for these results? Am I doing something wrong?
[UPDATE]
I think it is necessary to establish a testing procedure, maybe there is something hidden there. So here it is:
I have a database with 100M documents in one collection. Each document is created this way using the mongo shell:
{ "counter" : 0, "last_update" : new Date() }
Here's the conclusion db.collection.stats();:
{
"ns" : "test.collection",
"count" : 100000100,
"size" : 6400006560,
"avgObjSize" : 64.0000015999984,
"storageSize" : 8683839472,
"numExtents" : 27,
"nindexes" : 2,
"lastExtentSize" : 2146426864,
"paddingFactor" : 1,
"systemFlags" : 1,
"userFlags" : 0,
"totalIndexSize" : 5769582448,
"indexSizes" : {
"_id_" : 3251652432,
"last_update_1" : 2517930016
},
"ok" : 1
}
3.2.1 Ubuntu 12.04 #, MongoDB :
FindAndModifyArgs args = new FindAndModifyArgs();
args.SortBy = SortBy.Ascending("last_update");
args.Update = Update<Entity>.Set(e => e.last_update, DateTime.Now);
args.Fields = Fields.Include(new string[] { "counter", "_id" });
var m = collection.FindAndModify(args);
Entity ent = m.GetModifiedDocumentAs<Entity>();
var query = Query<Entity>.EQ(e => e.Id, ent.Id);
var update = Update<Entity>.Set(e => e.counter, ent.counter+1);
collection.Update(query, update);
, ; last_update, last_update, ( ).
10k Write Concerns, w=-1, w=0, w=1 w=1&j=true. w=-1 , :

, :
w=-1 w=0 w=1 w=1&j=true
Average N/A 244.0948611492 7064.5143923477 238.1846428156
STDEV N/A 1.7787457992 511.892765742 21.0230097306
: - , w=0 , w=1 w=-1 ?
[]
RequestStart :
using (server.RequestStart(database)) {
FindAndModifyArgs args = new FindAndModifyArgs();
args.SortBy = SortBy.Ascending("last_update");
args.Update = Update<Entity>.Set(e => e.last_update, DateTime.Now);
args.Fields = Fields.Include(new string[] { "counter", "_id" });
var m = collection.FindAndModify(args);
Entity ent = m.GetModifiedDocumentAs<Entity>();
var query = Query<Entity>.EQ(e => e.Id, ent.Id);
var update = Update<Entity>.Set(e => e.counter, ent.counter+1);
collection.Update(query, update);
}
- , .