将数据写入上限集合太慢了

时间:2013-05-01 16:07:36

标签: mongodb mongodb-.net-driver

我注意到有人在这里问了这个问题(slow inserts into a capped collection?),但没有最好的答案。

打击日志是我的上限集合插入操作。

Tue Apr 30 13:12:19.172 [conn870] insert shopbot_slurp.requestLogs ninserted:1 keyUpdates:0 locks(micros) w:53 872ms
Tue Apr 30 13:12:19.175 [conn1093] insert shopbot_slurp.requestLogs ninserted:1 keyUpdates:0 locks(micros) w:70 1792ms
Tue Apr 30 13:12:19.182 [conn843] insert shopbot_slurp.requestLogs ninserted:1 keyUpdates:0 locks(micros) w:245206 256ms
Tue Apr 30 13:12:19.690 [conn886] insert shopbot_slurp.requestLogs ninserted:1 keyUpdates:0 locks(micros) w:64 1392ms
Tue Apr 30 13:12:19.691 [conn1087] insert shopbot_slurp.requestLogs ninserted:1 keyUpdates:0 locks(micros) w:55 512ms
Tue Apr 30 13:12:19.692 [conn922] insert shopbot_slurp.requestLogs ninserted:1 keyUpdates:0 locks(micros) w:63 1874ms
Tue Apr 30 13:12:19.693 [conn937] insert shopbot_slurp.requestLogs ninserted:1 keyUpdates:0 locks(micros) w:503479 511ms
Tue Apr 30 13:12:19.694 [conn879] insert shopbot_slurp.requestLogs ninserted:1 keyUpdates:0 locks(micros) w:63 1776ms
Tue Apr 30 13:12:20.475 [conn879] insert shopbot_slurp.requestLogs ninserted:1 keyUpdates:0 locks(micros) w:82 779ms
........

我正在运行一个自动记录操作日志的应用程序,这意味着需要从客户端请求向db写入大量日志。

> db.requestLogs.stats();
{
    "ns" : "shopbot_slurp.requestLogs",
    "count" : 1105917,
    "size" : 192024340,
    "avgObjSize" : 173.63359094760276,
    "storageSize" : 209719296,
    "numExtents" : 1,
    "nindexes" : 0,
    "lastExtentSize" : 209719296,
    "paddingFactor" : 1,
    "systemFlags" : 0,
    "userFlags" : 0,
    "totalIndexSize" : 0,
    "indexSizes" : {

    },
    "capped" : true,
    "max" : NumberLong("9223372036854775807"),
    "ok" : 1
}


>db.system.namespaces.find() 
{ "name" : "shopbot_slurp.requestLogs", "options" :
 { "create" : "requestLogs","capped" : true, "size" : 209715200, "autoIndexId" : false } }

以下是我的插入代码:

var doc = new BsonDocument()
        {
            {"url",url},
            {"verb",verbs},
            {"action",action},
            {"time",DateTime.Now}
        };                
var collection = this._database.GetCollection(RequestLogCollectionName);
collection.Insert(doc, WriteConcern.Unacknowledged);

mongodb:2.4.2 mongodb司机:c# 1.7

感谢您的一些建议。

1 个答案:

答案 0 :(得分:0)

您似乎错过了上限集合中的_id索引。有关详细信息,请参阅https://stackoverflow.com/a/10638190/1630757