如何提高MongoDB的性能 [英] How to increase MongoDB performance

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

问题描述

我正在开发MongoDB中的应用程序,CakePHP。我的数据库中有 145,000 个记录。当我使用以下命令查询记录时,需要 12秒。这对我的应用程序非常不好。

I am developing an application in MongoDB, CakePHP. I have 145,000 record in my database. When I query for records using following command then it takes 12seconds. Which is very bad for my application.

$params= array('aggregate'=>array(
     array('$project'=>array('as'=>1,'pid'=>1,'st'=>1)),
     array('$unwind'=>'$as'),                   
     array('$match' => array('pd'=>array('$gt'=>$f,'$lt'=>$t),'pid'=>$project_id)),
     array('$group'=>array('_id'=>'$as')), 
     array('$sort'=>array('_id'=>1)),
     array('$limit'=>10)
     )
);
$results = $this->Detail->find('all',array('conditions'=>$params)); 

任何人都可以帮助我减少查询时间。

Can anyone help me in reducing time for query.

我有的索引和& pid 。我的系统内存为1.5GB。

I have indexes on as & pid. My system RAM is 1.5GB.

我得到以下数据

[1] => Array
    (
        [Detail] => Array
            (
                [_id] => Array
                    (
                        [0] => "superfone" Llc,moscow,ru
                    )

            )

    )

[2] => Array
    (
        [Detail] => Array
            (
                [_id] => Array
                    (
                        [0] => "superphone" Llc,moscow,ru
                    )

            )

    )

$ b b

推荐答案

在执行查找之前,请确保将递归级别设置为所需级别,然后报告您的效果。

Before performing the find, make sure to set the recursive level to the level you need, then report back on your performance.

$this->Detail->recursive = -1; // no joins
results = $this->Detail->find('all',array('conditions'=>$params)); 

$this->Detail->recursive = 0; // data + domain
results = $this->Detail->find('all',array('conditions'=>$params)); 

不知道你需要什么级别的递归,所以给他们一个测试,但默认是1,可能是一个昂贵的练习。

Not sure what level of recursive you need, so give them a test, but default is 1 and it can be a costly exercise.

ref
http://book.cakephp.org/2.0/en/models/model-attributes.html#recursive

引用还说,使你的默认值为-1,并根据需要提高递归级别,这可以通过在AppModel中添加以下内容来实现。

The reference also says to make -1 your default, and raise the recursive levels as you need them, this can be done by adding the following to AppModel

public $recursive = -1;

这篇关于如何提高MongoDB的性能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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