我最近一直在研究.NET可用的nosql选项,MongoDB在可用性和支持方面正在成为明显的赢家,所以今晚我决定试一试.我从mongodb站点下载了1.2.4版(Windows x64二进制文件)并使用以下选项运行它:
C:\mongodb\bin>mkdir data C:\mongodb\bin>mongod -dbpath ./data --cpu --quiet
然后我从http://github.com/samus/mongodb-csharp加载了最新的mongodb-csharp驱动程序,并立即运行基准程序.听说过MongoDB的"速度惊人",我对糟糕的基准性能感到震惊.
Starting Tests encode (small).........................................320000 00:00:00.0156250 encode (medium)........................................80000 00:00:00.0625000 encode (large).........................................1818 00:00:02.7500000 decode (small).........................................320000 00:00:00.0156250 decode (medium)........................................160000 00:00:00.0312500 decode (large).........................................2370 00:00:02.1093750 insert (small, no index)...............................2176 00:00:02.2968750 insert (medium, no index)..............................2269 00:00:02.2031250 insert (large, no index)...............................778 00:00:06.4218750 insert (small, indexed)................................2051 00:00:02.4375000 insert (medium, indexed)...............................2133 00:00:02.3437500 insert (large, indexed)................................835 00:00:05.9843750 batch insert (small, no index).........................53333 00:00:00.0937500 batch insert (medium, no index)........................26666 00:00:00.1875000 batch insert (large, no index).........................1114 00:00:04.4843750 find_one (small, no index).............................350 00:00:14.2812500 find_one (medium, no index)............................204 00:00:24.4687500 find_one (large, no index).............................135 00:00:37.0156250 find_one (small, indexed)..............................352 00:00:14.1718750 find_one (medium, indexed).............................184 00:00:27.0937500 find_one (large, indexed)..............................128 00:00:38.9062500 find (small, no index).................................516 00:00:09.6718750 find (medium, no index)................................316 00:00:15.7812500 find (large, no index).................................216 00:00:23.0468750 find (small, indexed)..................................532 00:00:09.3906250 find (medium, indexed).................................346 00:00:14.4375000 find (large, indexed)..................................212 00:00:23.5468750 find range (small, indexed)............................440 00:00:11.3593750 find range (medium, indexed)...........................294 00:00:16.9531250 find range (large, indexed)............................199 00:00:25.0625000 Press any key to continue...
对于初学者,我可以从SQL Server Express获得更好的非批量插入性能.然而,令我印象深刻的是find_nnnn查询的性能缓慢.为什么从MongoDB中检索数据的速度如此之慢?我错过了什么?
编辑:这都是在本地计算机上,没有网络延迟或任何东西.在测试运行的整个过程中,MongoDB的CPU使用率约为75%.此外,我对基准程序进行了跟踪,并确认花费50%的CPU时间等待MongoDB返回数据,因此这不是C#驱动程序的性能问题.
我也做了那个基准测试.那段代码有很多错误.例如,索引的创建失败但吞下了异常,因此搜索仍然很慢.
但也要注意大对象有很多"细节对象".它是一个层次结构,而不是单个记录.一份文件有280个细节'记录'.将这样的大型文档与sql server等rdbms表中的一行进行比较是不公平的.