【问题标题】:Why is MongoDB slower on Debian than on Windows..?为什么 Debian 在 Debian 上的 MongoDB 比在 Windows 上慢..?
【发布时间】:2012-11-13 07:01:28
【问题描述】:

我创建了一个小型 Java 应用程序(使用 Spring Data)来测试 MongoDB 的地理空间查询性能。

public class MongoThread {

public static void main(String[] args) throws Exception {

    if(args.length != 1) {
        System.out.println("Usage: MongoThread <nb_thread>");
        System.exit(0);
    }

    int nbThread = Integer.parseInt(args[0]);

    ApplicationContext ctx = new AnnotationConfigApplicationContext(SpringMongoConfigStandalone.class);
    MongoOperations db = (MongoOperations) ctx.getBean("mongoTemplate");

    for (int x=0; x<nbThread; x++) {
        double lat = Math.random() * 60;
        double lng = Math.random() * 60;
        double radius = 3000 + 50 * Math.random();
        MyThread t = new MyThread("Thread #" + x, db, lat, lng, radius);
        t.start();
    }

    //create1MEntries(db);
}

private static void create1MEntries(MongoOperations db) {
    if (!db.getCollectionNames().contains("Item")) {
        db.createCollection("Item");
    }
    db.indexOps(Item.class).ensureIndex(new GeospatialIndex("loc"));
    for(int i=0; i<1000000; i++) {
        Item item = new Item();
        item.setName("item" + i);
        item.setLoc(new double[]{Math.random() * 180, Math.random() * 180});
        db.save(item, "Item");
    }
}
}

class MyThread extends Thread {

String name;
MongoOperations db;
double lat, lng, radius;

public MonThread (String name, MongoOperations db, double lat, double lng, double radius) {
    this.name = name;
    this.db = db;
    this.lat = lat;
    this.lng = lng;
    this.radius = radius;
}

public void run() {
    long t1 = Calendar.getInstance().getTimeInMillis();
    List<Item> items = db.find(new Query(Criteria.where("loc")
            .near(new Point(lat,lng)).maxDistance(radius/111.12)).limit(100), Item.class, "Item");
    System.out.println(name + " - " + items.size() + " results found around " + radius + " of (" + lat + "," + lng + ")");
    long t2 = Calendar.getInstance().getTimeInMillis();
    System.out.println(name + " - " + (t2-t1) + "ms");
}
}

public class Item {
    @Id
    private String id;
    private String name;
    private double[] loc;
}

在多次运行测试以将数据加载到内存中后,我得到的结果如下:

  • 在我的开发计算机上(Win7 64 位,i7 860 @2.8 Ghz,RAM 8GB 1066Mhz):对于 100 个线程,我在大约 500 毫秒(450 毫秒到 550 毫秒之间)内得到所有响应

  • 在我的服务器上(由 OVH 托管:Debian 6.0 64 位,i3 2130 2x2(HT) 3.4GHz,RAM 16GB 1333Mhz):对于 100 个线程,我在大约 1700 毫秒(介于 1600 毫秒和1900 毫秒)

我既不是硬件也不是 Linux 专家,但我希望这台服务器比我的 Windows 计算机做得更好(或者至少和我一样好)。 我在几个论坛上读到,MongoDB 在 Linux 上的速度确实更快,重要的硬件特性(按此顺序)是:RAM、CPU(但 Mongo 不使用多核)和硬盘。

我增加了最大打开文件数(使用 ulimit -n 99999),因为我读到它可以减慢 MongoDB,但对结果没有影响。

你知道瓶颈来自哪里吗?

【问题讨论】:

  • 您是否使用相同的 java 版本和相同的 JAVA_ARGS 运行它?
  • 是的,我在两者上都使用 Java 1.6(32 位)

标签: linux performance mongodb io mongodb-java


【解决方案1】:

我认为这不是 linux 与 windows 的问题。我的意思是,与 Windows 机器上的 i7 相比,i3 处理器相当低端。

如果您真的想比较两个操作系统之间的性能,我建议让您的设置在相同的硬件上运行..

【讨论】:

  • 在查看这个基准时不确定:cpu-world.com/Compare/369/… 我的开发计算机正在变旧(3 年),CPU 来自第一代 i7,i3 CPU 更高,并且从我的读数MongoDB 不使用多核。我将在我的开发计算机上安装 Debian 进行比较。但我担心服务器上的硬盘(由 OVH 托管)正在减慢 Mongo。
  • MongoDB 正在使用 Mozilla 的 SpiderMonkey javascript 引擎,该引擎只能在单个线程中执行 javascript。但是 MongoDB 不是用 javascript 编写的,它是用 C++ 编写的,并且确实使用了多个线程。当涉及到 javascript 执行时,它会进入单线程模式,但自 2.2 以来,操作锁定方面已经有了许多改进,因此您会看到更多内核的性能改进。
  • 无论哪种方式,写入数据库都会涉及磁盘操作,所以如果你的硬盘RPM或品牌不同,那么基准是没有用的。如果您的内存不同,如果已安装程序的可用内存不同,即使内存总线速度不同,那么基准测试与操作系统无关,而是与硬件有关,而硬件本来应该是相同的。
  • 我也不会使用便宜的托管服务提供商,因为他们通常使用虚拟化,这本身就是一种开销,并且如果您在共享服务器上,还会锁定您的帐户正在使用的资源托管计划。
  • 这几乎可以肯定是由于硬件不匹配,特别是 CPU 和 I/O 性能。没有理由一个操作系统应该比另一个操作系统快得多。
猜你喜欢
  • 1970-01-01
  • 2013-07-05
  • 1970-01-01
  • 1970-01-01
  • 2015-06-17
  • 2014-08-02
  • 2013-06-01
  • 2011-09-11
  • 1970-01-01
相关资源
最近更新 更多