MongoDB-Java驱动程序性能 [英] MongoDB - Java Driver performance

查看:66
本文介绍了MongoDB-Java驱动程序性能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的环境.

Java-Oracle 1.7版

Java - 1.7 by Oracle

mongod v2.4.5(在Mongolab中)

mongod v2.4.5 (in Mongolab)

我发现两个MongoDB驱动程序的性能有所不同(2.9.3与2.11.2)

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

当我使用每个驱动程序运行相同的代码时,2.11.2比2.9.3慢.

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();
    }

上面的代码是将1000个文档放入MongoDB.

The above code is to put 1000 document to MongoDB.

在驱动程序2.9.3中,需要1到2秒.但在2.11.2中,则需要花费超过1分钟的时间.

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

有人知道这个问题吗?

推荐答案

对于Java驱动程序,自V 2.10.0开始,默认写关注已从NORMAL更改为SAFE请参阅此处

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.

这篇关于MongoDB-Java驱动程序性能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆