我正在尝试使用新的ArangoDb-Net重新实现驱动程序https://github.com/yojimbo87/ArangoDB-NET/tree/reimplement。今天是我第一次尝试性能测试。当我使用araongosh执行插入时,它可以每秒插入约5000个记录。然而,当我使用.Net驱动程序执行相同的更新时,执行同样的插入需要大约2分钟时间。请问我做错了什么?谢谢。
[编辑]完成问题与GitHub讨论。我已经使用我的arangosh测试了下面的代码
count=1;
startTime=+new Date();
console.log(startTime);
while(count <= 10000)
{
db.someCollection.save({"Id":"1234567890123456789012345678901234",
"Key":1234567,
"Revision":1234567,
"Name":"Mohamad Abu Bakar",
"IC Number":"1234567-12-3444",
"Department":"IT Department",
"Height":1234,
"DateOfBirth":"2015-01-27 03:33",
"Salary":3333});
count++;
}
endTime=+new Date();
console.log(endTime);
console.log("Total time taken:" + (endTime - startTime)/1000);
完成该操作共耗时3.375秒。
我用.Net驱动程序做了类似的事情,几乎需要9.5797819秒。几乎是arangosh的三倍。以下是.Net代码:
public static void TestArangoDb()
{
//ASettings.AddConnection("_system", "127.0.0.1", 8529, false, "_system");
//var db = new ADatabase("_system");
//db.Create("trial_sample");
ASettings.AddConnection("trial_sample",
"127.0.0.1", 8529, false, "trial_sample");
var db2 = new ADatabase("trial_sample");
db2.Collection.Create("someCollection");
DateTime startTime = DateTime.Now;
Console.WriteLine("Start Time: " + startTime.ToLongTimeString());
for(int count=1; count <= 10000; count++)
{
var employee = new Employee();
employee.Id = "1234567890123456789012345678901234";
employee.Key = "1234567";
employee.Revision = "1234567";
employee.Name = "Mohamad Abu Bakar";
employee.IcNumber = "1234567-12-3444";
employee.Department = "IT Department";
employee.Height = 1234;
employee.DateOfBirth = new DateTime(2015, 1, 27, 3, 33, 3);
employee.Salary = 3333;
var result = db2.Document.Create<Employee>("someCollection", employee);
//var updateDocument = new Dictionary<string, object>()
// .String("DocumentId", "SomeId");
//db2.Document.Update(result.Value.String("_id"), updateDocument);
}
DateTime endTime = DateTime.Now;
TimeSpan duration = endTime - startTime;
Console.WriteLine("End Time: " + endTime.ToLongTimeString());
Console.WriteLine("Total time taken: " + duration.TotalSeconds);
}
public class Employee
{
public string Id { get; set; }
public string Key { get; set; }
public string Revision { get; set; }
public string Name { get; set; }
public string IcNumber { get; set; }
public string Email { get; set; }
public string Department { get; set; }
public double Height { get; set; }
public DateTime DateOfBirth { get; set; }
public decimal Salary { get; set; }
}
如果我移除这行代码的注释:
var updateDocument = new Dictionary<string, object>()
.String("DocumentId", "SomeId");
db2.Document.Update(result.Value.String("_id"), updateDocument);
性能提高了近30倍。完成所需的时间为99.8789133秒。实际上,我只是执行了额外的更新来添加其他列。
你能就上面代码的问题提出建议吗?谢谢。