对此的任何帮助将不胜感激。
我有一个大型的 Mongodb 集合,我在其中存储用户活动。它有几个用于我想要运行的查询的复合索引,通常查询性能非常好,并且用户活动流会立即加载。
但是,最近我添加了一个后台任务,它每 2 小时向集合中添加 20k 条记录(每个用户一条新记录)。由于添加了此任务 - 我注意到在添加这些记录后我第一次访问我的活动流时,在页面加载之前有很大的延迟。然后当我刷新页面时,它会快速加载。
似乎新项目只是在我尝试访问它们后才被添加到索引中。但是从我在 MongoDB FAQ 上读到的内容 - 它们会自动添加到索引中 - http://docs.mongodb.org/manual/faq/indexes/#should-you-run-ensureindex-after-every-insert。也许这是他们还没有被添加的情况?
如果有帮助,这是我的收藏统计信息。
Array
(
[ns] => main.activities
[count] => 26280825
[size] => 3234981772
[avgObjSize] => 123.09285465734
[storageSize] => 4211892224
[numExtents] => 30
[nindexes] => 20
[lastExtentSize] => 844685312
[paddingFactor] => 1.001
[systemFlags] => 1
[userFlags] => 0
[totalIndexSize] => 25240448464
[indexSizes] => Array
(
[_id_] => 946551872
[portfolio_id_1_type_1_timestamp_-1] => 1519746704
[project_id_1_type_1_timestamp_1] => 1839902512
[project_id_1] => 1148997808
[piece_id_1] => 792794016
[user_id_1_type_1_timestamp_-1] => 1903806128
[type_1_timestamp_-1] => 1475522720
[user_id_1_type_1] => 1440243280
[project_id_1_type_1] => 1394008000
[project_id_1_type_1_timestamp_1_project_page_timestamp_1] => 2114419888
[project_id_1_type_1_project_page_timestamp_1] => 1564649296
[conversation_id_1] => 870670416
[project_comment_id_1] => 814640288
[project_comment_id_1_type_1] => 1032408048
[reply_to_comment_id_1] => 512324512
[collection_id_1] => 822996160
[user_id_1] => 1233578528
[portfolio_id_1] => 852691392
[type_1_user_id_1] => 1477182448
[type_1_user_id_-1] => 1483314448
)
[ok] => 1
)