Pergunta

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?

Foi útil?

Solução

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.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top