我正在运行一个测试来比较使用RavenDB为我们的数据库后端与实体框架与MSSQL. 我有我的测试应用程序设置来检查并查看RavenDB在启动时是否有任何文档,如果没有,它通过Entity Framework查询
我有我的测试应用程序设置来检查并查看RavenDB在启动时是否有任何文档,如果没有,它通过Entity Framework查询SQL数据库以获取所有对象(大约31,000个项目),然后将它们插入RavenDB.这部分按预期工作.
然后我运行测试.我查询EF以获取一组记录并将它们转换为JSON,并使用Raven重复相同(获取完全相同的记录集).我预计Raven会更快,因为它针对读取进行了优化,而EF必须连接两个表来获取数据.但事实并非如此.
以下是测试的输出:
Entity Framework with MS SQL RavenDB Percent Difference Raven to EF 796.8954 ms (862 records) 1703.1686 ms (862 records) 213.725490196078 296.8826 ms (862 records) 796.8954 ms (862 records) 268.421052631579 281.2572 ms (862 records) 781.27 ms (862 records) 277.777777777778 281.2572 ms (862 records) 796.8954 ms (862 records) 283.333333333333 296.8826 ms (862 records) 765.6446 ms (862 records) 257.894736842105 312.508 ms (862 records) 765.6446 ms (862 records) 245 296.8826 ms (862 records) 750.0192 ms (862 records) 252.631578947368 296.8826 ms (862 records) 750.0192 ms (862 records) 252.631578947368 359.3842 ms (862 records) 765.6446 ms (862 records) 213.04347826087 281.2572 ms (862 records) 765.6446 ms (862 records) 272.222222222222 281.2572 ms (862 records) 796.8954 ms (862 records) 283.333333333333 281.2572 ms (862 records) 765.6446 ms (862 records) 272.222222222222 281.2572 ms (862 records) 812.5208 ms (862 records) 288.888888888889 265.6318 ms (862 records) 781.27 ms (862 records) 294.117647058824 296.8826 ms (862 records) 796.8954 ms (862 records) 268.421052631579 281.2572 ms (862 records) 765.6446 ms (862 records) 272.222222222222 281.2572 ms (862 records) 828.1462 ms (862 records) 294.444444444444 281.2572 ms (862 records) 781.27 ms (862 records) 277.777777777778 328.1334 ms (862 records) 750.0192 ms (862 records) 228.571428571429 296.8826 ms (862 records) 750.0192 ms (862 records) 252.631578947368 312.508 ms (862 records) 781.27 ms (862 records) 250 296.8826 ms (862 records) 796.8954 ms (862 records) 268.421052631579 281.2572 ms (862 records) 765.6446 ms (862 records) 272.222222222222 312.508 ms (862 records) 781.27 ms (862 records) 250 281.2572 ms (862 records) 734.3938 ms (862 records) 261.111111111111
以下是用于运行测试的代码:
protected void Page_Load(object sender, EventArgs e) { int totalTests = 25; DataTable dt = new DataTable(); dt.Columns.Add("Entity Framework with MS SQL"); dt.Columns.Add("RavenDB"); dt.Columns.Add("Percent Difference Raven to EF"); for (int i = 1; i <= totalTests; i++) { string efMilliseconds = string.Empty; string ravenMilliseconds = string.Empty; double efMS = 0; double ravenMS = 0; // EF using (tamcEntitiesForRavenTest myObjectContext = new tamcEntitiesForRavenTest()) { DateTime startTime = DateTime.Now; List<Treatment> efTreatments = myObjectContext.Treatments.Include("Segments").Where(x => x.Jurisdiction == "00145").OrderBy(x => x.Treatment_Date).ToList(); string json = JsonConvert.SerializeObject(efTreatments); TimeSpan TotalTime = DateTime.Now - startTime; efMS = TotalTime.TotalMilliseconds; efMilliseconds = string.Format("{0} ms ({1} records)", efMS.ToString(), efTreatments.Count); } // Raven using (var session = DataDocumentStore.Instance.OpenSession()) { DateTime startTime = DateTime.Now; List<RavenTreatment> ravenTreatments = session.Query<RavenTreatment>().Where(x => x.Jurisdiction == "00145").OrderBy(x => x.Treatment_Date).Take(1000).ToList(); string json = JsonConvert.SerializeObject(ravenTreatments); TimeSpan TotalTime = DateTime.Now - startTime; ravenMS = TotalTime.TotalMilliseconds; ravenMilliseconds = string.Format("{0} ms ({1} records)", ravenMS.ToString(), ravenTreatments.Count); } DataRow dr = dt.NewRow(); dr[0] = efMilliseconds; dr[1] = ravenMilliseconds; double percentDifference = (ravenMS * 100) / efMS; dr[2] = percentDifference; dt.Rows.Add(dr); } GridView1.DataSource = dt; GridView1.DataBind(); }
我让RavenDB实例在与SQL服务器相同的机器上运行.
这是预期的业绩结果吗?或者有什么我做错了.
Amanda,你需要明白它不是比sql server更快的RavenDB本身. MSSQL已经存在多年了,你可以肯定它是非常微优化的,并且可以在批量选择场景中获得最佳结果,例如上面显示的场景.这不是RavenDB有机会击败像MSSQL这样的产品的地方.然而,虽然数据库本身不是产生差异,但大多数情况下,应用程序及其数据访问策略将为您带来乌鸦所熟知的闪电性能.
整个过程是关于文档数据库如何允许您构建数据(聚合根,非规范化引用,预计算索引等).这不是特定于RavenDB的东西,因为你可以使用MongoDB和CouchDB来做这些事情,所以这些数据库中最本质的差异可能是,raven为你提供了一个非常好的和简单的.NET体验,并且已经超出了-box多文档事务.还有许多其他的甜点,但那些通常会让你在不同的数据库之间做出决定.