MongoDB - Java Driver performance

牧云@^-^@ 提交于 2021-02-07 18:30:09

问题


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:


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.



来源:https://stackoverflow.com/questions/18235622/mongodb-java-driver-performance

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!