4

This is my environments.

Java - 1.7 by Oracle

mongod v2.4.5 (in Mongolab)

I found difference in performance of the two MongoDB driver(2.9.3 vs 2.11.2)

When I run same code using each driver, 2.11.2 slower than 2.9.3.

   for(int i=0; i<1000; i++){
        BasicDBObject doc = new BasicDBObject(
                "currentTime",
                new SimpleDateFormat("HH:mm:ss:SSS").format(Calendar.getInstance().getTime())
        );
        coll.insert(doc);
    }

    DBCursor cursor = coll.find();
    try{
        while(cursor.hasNext()){
            System.out.println(cursor.next());
        }
    } finally {
        cursor.close();
    }

The above code is to put 1000 document to MongoDB.

In driver 2.9.3, it takes 1~2 sec. but in 2.11.2, it takes more than 1 minute.

Does anyone know anything about this problem?

Community
  • 1
  • 1
DaegiKim
  • 45
  • 7
  • inserting 1000 documents shouldn't take 1minute even with the new default write concern. Small documents like this takes microseconds on my laptop. One small tip in case you're not aware, a bulk insert will probably be faster. You can insert a list of documents. This means that there is only one round trip for your 1000 docs. – Dylan Tong Aug 18 '13 at 05:58

1 Answers1

4

Default Write concern has changed from NORMAL to SAFE for Java driver since V 2.10.0 See here

This means that in the older driver version insert operations by default return as soon as a message is written to socket.

In the newer driver version on the other hand, operations by default must be acknowledged by the server before returning, which is much slower.

Ori Dar
  • 18,687
  • 5
  • 58
  • 72