我創建的MongoDB數據庫在Linux服務器(標準D2 V2(2芯,7 GB內存))非常緩慢。 MongoDB是在Windows Azure平臺上Azure平臺
我測試數據插入到數據庫與下面的代碼。但結果不好..! 47秒插入100.000記錄非常糟糕。問題是什麼?
代碼爲插入到MongoDB的在Azure上(Linux的虛擬機 - 標準D2 V2(2芯,7 GB內存))
string connectionString = "mongodb://root:[email protected]:27017";
var client = new MongoClient(connectionString);
var database = client.GetDatabase("testdb");
var collection = database.GetCollection<Item>("foo");
var documents = Enumerable.Range(1, 100000).Select(i => new Item
{
Address = "Address " + i,
City = "City " + i,
Index = i + 1,
Name = "Name " + i,
Status = i % 2 == 0,
Surname = "Surname " + i,
Title = "Title " + i,
Town = "Town " + i
});
var models = documents.Select(s => new InsertOneModel<Item>(s)).ToList();
Stopwatch sw = new Stopwatch();
sw.Start();
var result = collection.BulkWrite(models);
sw.Stop();
Console.WriteLine("Seconds:" + sw.Elapsed.Seconds);
result.InsertedCount.Dump();
collection.Count(p => 1 == 1).Dump();
什麼比很慢? –
Sql Server的批量插入速度比MongoDB相同的數據快。 –
你如何在Mongo中插入數據? :D –