Mongo更新速度超慢

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Mongo更新速度超慢相关的知识,希望对你有一定的参考价值。

我们的mongo更新面临超时问题。我们的藏品目前包含约30万份文件。当我们尝试通过UI更新记录时,服务器超时并且UI陷入困境。

Lead.updateOne({
      _id: body.CandidateID
    }, {
      $set: {
        ingestionStatus: 'SUBMITTED',
        program: body.program,
        participant: body.participant,
        promotion: body.promotion,
        addressMeta: body.addressMeta,
        CreatedByID: body.CreatedByID,
        entryPerson: body.entryPerson,
        lastEnteredOn: body.lastEnteredOn,
        zipcode: body.zipcode,
        state: body.state,
        readableAddress: body.readableAddress,
        promotionId: body.promotionId,
        programId: body.programId,
        phone1: body.phone1,
        personId: body.personId,
        lastName: body.lastName,
        hasSignature: body.hasSignature,
        firstName: body.firstName,
        city: body.city,
        email: body.email,
        addressVerified: body.addressVerified,
        address: body.address,
        accountId: body.accountId
      }

这是我们更新单个记录的方式。我们在堆栈中使用mlab和Heroku。寻求有关如何加快这一速度的建议。

谢谢。

答案

如果您的索引没问题,那么您可以在此集合上尝试rebuilding indexes。 mango命令行中的集合索引:例如,从mongo命令行重建前导集合索引:

db.lead.reIndex();

参考:

https://docs.mongodb.com/v3.2/tutorial/manage-indexes/ https://docs.mongodb.com/manual/reference/command/repairDatabase/

另一答案

如果您没有使用它,那么尝试这一个索引构建可以阻止对您的数据库的写操作,因此您不希望在高峰使用期间在大型表的前台构建索引。您可以通过在创建时指定background:true来使用索引的后台创建。

db.collection.createIndex({a:1},{background:true})

这最终需要更长时间才能完成,但它不会阻止操作,对性能的影响也会更小。

另一答案

1)通过id作为分片键的Shard Lead集合。 2)检查mongodb因索引占用的内存是否小于mongoDb服务器的内存。

另一答案

你有没有尝试过this answer的建议?即,更新没有写入问题?

以上是关于Mongo更新速度超慢的主要内容,如果未能解决你的问题,请参考以下文章

为啥我得source insight 运行速度超慢

Hive Tez 减速器运行速度超慢

我的电脑速度超慢!!求救!!!

deepin终端下载速度超慢解决方案

Zencart v1.5.0安装后,网站打开速度超慢!!!

Linux(Centos)下jdbc连接oracle速度超慢的问题