我注意到有人在这里问过这个问题(缓慢插入到有上限的集合中?),但没有任何最佳答案。
吹日志是我的上限收集插入操作。
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.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
谢谢你的建议。