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?

1
  • 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. Commented Aug 18, 2013 at 5:58

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.