DolphinDB与MongoDB在时序数据上的对比测试
本页提供一篇对比测试文章的引言信息,并引入 DolphinDB 与 MongoDB 的差异与测试目的。
Source: https://dolphindb.cn/blogs/55
What this page covers
- 文章标题、作者、发布时间与测试目的引入。
- 导入、导出、磁盘占用与查询性能的对比结论汇总。
- 测试环境:硬件、操作系统、版本与集群配置。
- 数据集与方法:数据规模、清缓存方式、分区与索引策略。
- 导入导出:脚本、结果解读与原因分析。
- 磁盘占用:测量方法、结果与差异原因。
- 查询性能:查询类型、计时口径、过程与差异分析。
技能认证特训营第二期报名推广
页面顶部包含限时报名活动的宣传信息与链接入口。
- 该区域属于活动报名导流内容。
- 该区域提供访问入口链接。
DolphinDB与MongoDB在时序数据上的对比测试(标题与引言)
给出文章标题、作者与发布时间,并引入两种数据库差异与测试目的。
- 文章发布时间为 2021-08-05。
- 作者署名为 Junxi。
- 测试目的之一是评估 MongoDB 是否适合海量结构化时序数据集。
- 文中对 DolphinDB 与 MongoDB 的定位差异进行引入说明。
主要结论(性能对比要点)
汇总导入导出、磁盘占用与查询性能的关键对比结论。
- 导入速度结论:DolphinDB 比 MongoDB 高出两个数量级。
- 导出速度结论:DolphinDB 约比 MongoDB 快 50 倍。
- 磁盘占用结论:MongoDB 磁盘占用约为 DolphinDB 的 2~3 倍。
- 查询结论:多数测试中 DolphinDB 查询速度更快,少数点查询慢于 MongoDB。
测试环境
描述硬件、操作系统,以及 DolphinDB 与 MongoDB 的版本与集群配置。
- 测试为单机测试。
- 测试主机型号为 DELL OptiPlex 7060。
- 操作系统为 Ubuntu 18.04 LTS。
- 给出 DolphinDB 与 MongoDB 的测试版本与集群节点组成。
数据集
说明两种规模数据集、清缓存与查询执行方法,并给出两类数据集的结构与分区/索引策略。
- 测试数据集规模包含 4.2GB 与 62.4GB 两个量级。
- 测试前通过 sync 与 drop_caches 清空缓存。
- 小数据集来自 TimescaleDB 提供的示例 CSV 数据集链接。
- 大数据集为股票交易相关 CSV 数据(约 16 亿条记录)。
- 描述 DolphinDB 分区与 MongoDB 分片/索引的策略与要求。
数据库导入导出性能对比
给出导入/导出脚本与结果解读,并分析 MongoDB 导入较慢的原因。
- 导入方法包含 DolphinDB 的 submitJob 与 loadTextEx 方式(示例)。
- MongoDB 导入包含数据拆分与 mongoimport 参数设置(示例)。
- 文中描述导入结果:DolphinDB 可达到更高的导入速率与更短耗时(表格叙述)。
- 原因之一:MongoDB 以文档逐条导入,记录数大时导入时长增加。
- 原因之一:分片集群开启 journaling 会降低导入速度。
- 原因之一:为唯一性生成唯一索引并与导入同时进行会降低导入速度。
- 文中给出 DolphinDB 与 MongoDB 的导出命令示例。
- 小数据集导出结果叙述:DolphinDB 导出耗时显著更短(表格叙述)。
数据库磁盘空间占用对比
说明磁盘占用测量方法、对比结果与造成差异的原因(压缩、索引等)。
- 磁盘占用测量:DolphinDB 读取列式文件大小,MongoDB 通过 db.stats() 获取。
- 测量口径包含两库各自的备份情况说明。
- 结果叙述:MongoDB 磁盘占用约为 DolphinDB 的 2~3 倍。
- 差异原因包括压缩方式与索引大小带来的存储开销。
数据库查询性能
定义查询类型、计时口径与小/大数据集的查询测试过程、结果与差异原因分析。
- 查询对比覆盖 8 类常用 SQL 查询类型。
- 计时单位为毫秒,指标为服务器执行时间。
- 小数据集测试包含磁盘 IO,且每次启动前清缓存。
- 文中给出两库加载与切换数据表/数据库的示例操作。
- 计时工具:DolphinDB 使用 timer,MongoDB 使用 explain()。
- 包含分区字段的范围查询中,两者差距在 4 倍以内(叙述)。
- 某些点查询在 MongoDB 复合索引下更快,DolphinDB 可能略慢(叙述)。
- 大数据量且均分区情况下,DolphinDB 仍比 MongoDB 快约 5–20 倍(叙述)。
小结
总结 DolphinDB 在结构化时序数据处理上的整体优势,以及 MongoDB 在模型多变与非结构化数据场景的优势。
- 结构化时序数据处理方面,文中结论认为 DolphinDB 整体优于 MongoDB。
- 在数据模型多变与非结构化数据方面,文中认为 MongoDB 更有优势。
附录(配置与脚本链接)
提供环境配置、分区脚本与查询脚本的参考链接资源。
- 附录列出 DolphinDB 配置文件链接:controller.cfg、agent.cfg、cluster.cfg、cluster.nodes。
- 附录列出 MongoDB 配置文件链接:master_mongos.txt。
- 附录列出分区脚本链接:DolphinDB 与 MongoDB 各自的 partition 脚本。
- 附录列出 MongoDB 查询脚本链接资源。
Facts Index
| Entity | Attribute | Value | Confidence |
|---|---|---|---|
| DolphinDB与MongoDB在时序数据上的对比测试 | publication_date | 2021-08-05 | high |
| Author | name | Junxi | high |
| DolphinDB | description | 列式存储的多模型数据库,主要用于结构化时序数据的高速存储、查询和分析 | high |
| MongoDB | description | 文档型的NoSQL数据库,可用于处理非结构化和结构化的数据,可根据键值快速查找或写入一个文档 | high |
| Benchmark purpose | goal | 评估MongoDB是否适合海量结构化时序数据集(物联网与金融领域等) | high |
| Import performance conclusion | relative_performance | DolphinDB的数据导入速度比MongoDB高出两个数量级;数据量越大差距越明显 | medium |
| Export performance conclusion | relative_performance | 数据导出方面,DolphinDB比MongoDB快50倍左右 | medium |
| Disk usage conclusion | relative_usage | MongoDB占用磁盘是DolphinDB的2~3倍 | medium |
| Query performance conclusion | relative_performance | DolphinDB在4个查询性能测试中速度比MongoDB快30倍;在5个查询性能测试中速度比MongoDB快10~30倍;在12个查询性能测试中速度比MongoDB快数倍;仅在两个点查询测试中慢于MongoDB | medium |
| Test setup | execution_mode | 单机测试 | high |
| Test host | model | DELL OptiPlex 7060 | high |
| Test host CPU | spec | Intel(R) Core(TM) i7-8700 CPU@3.20GHZ,6核12线程 | high |
| Test host memory | spec | 32 GB (8GB x 4, 2,666 MHz) | high |
| Test host disk | spec | 2T HDD (222MB/s读取;210MB/s写入) | high |
| Operating system | name_version | Ubuntu 18.04 LTS | high |
| DolphinDB | test_version | Linux0.89 | high |
| DolphinDB cluster (test) | max_connections_per_node | 128 | high |
| DolphinDB cluster (test) | replication_factor | 2 | high |
| DolphinDB cluster (test) | node_composition | 1个控制节点,1个代理节点,3个数据节点 | high |
| MongoDB | test_version | Linux4.0.5社区版 | high |
| MongoDB shard cluster (test) | threads | 12 | high |
| MongoDB cluster (test) | max_connections_per_server | 128 | high |
| MongoDB sharded deployment (test) | node_composition | 1个config服务器,1个mongos路由服务器,3个分片服务器 | high |
| MongoDB config server replica set (test) | replica_composition | 1个主节点和2个从节点 | high |
| MongoDB shard replica set (each shard, test) | replica_composition | 1个主节点,1个从节点,1个仲裁节点 | high |
| Datasets tested | sizes | 小数据量级4.2GB;大数据量级62.4GB | high |
| Benchmark method | cache_clearing | 测试前通过sync与echo 1,2,3 | tee /proc/sys/vm/drop_caches清空页面缓存、目录缓存和硬盘缓存 | high |
| Benchmark method | query_batch | 随后依次执行13条查询并记录时间 | high |
| Small dataset | name_and_size | 设备传感器信息小数据集(CSV文件,4.2G, 3千万条数据) | high |
| readings数据集时间范围 | coverage | 2016.11.15-2016.11.19 | high |
| readings数据集 | device_count | 3,000个设备 | high |
| readings数据集 | time_intervals | 10,000个时间间隔 | high |
| info数据集 | device_count | 3,000个设备 | high |
| Small dataset source | provider | TimescaleDB官网提供的devices_readings_big.csv与device_info_big.csv | high |
| Small dataset source URL | link | https://docs.timescale.com/v1.1/tutorials/other-sample-datasets | high |
| Small dataset total records | count | 3千万条数据 | high |
| Small dataset total size | size | 4.2G | high |
| device_id字段(readings数据集) | data_characteristic | 有3000个不同值且重复出现;使用string类型占用大量空间且查询效率低;DolphinDB的symbol类型可改善空间与效率 | medium |
| DolphinDB small dataset partitioning | method | 组合分区:time按天分为4个区;device_id作为第二维度;每天分10个区;每分区原始数据约100MB | high |
| MongoDB small dataset sharding/partitioning | method | 组合分区:time按日期范围分区;设备ID按范围分区;chunkSize为1024时性能最佳;readings数据集最终分为17个分区 | high |
| MongoDB partitioning requirement | index_required | 分区字段必须建立索引 | high |
| MongoDB readings复合索引 | index_name_and_cost | time_1_device_id_1增序索引耗时5分钟,占用空间1.1G | high |
| Large dataset | name_and_size | 股票交易大数据集(CSV文件,62.4G,16亿条数据) | high |
| TAQ数据集 | provider_and_content | NYSE提供的2007.08.07-2007.08.10四天Level1报价数据,包含8,000多支股票的报价信息 | high |
| TAQ数据集文件 | file_count_and_sizes | 4个CSV文件;每个14G到17G;总共62.4G | high |
| TAQ数据集 | record_count | 大约16亿条数据 | high |
| TAQ数据集来源URL | link | https://www.nyse.com/market-data/historical | high |
| DolphinDB TAQ partitioning | method | 组合分区:date为第一维度每天1分区共4分区;symbol为第二维度范围分区,每天100分区;总共400分区;每分区约40MB | high |
| MongoDB TAQ sharding/partitioning | method | 组合分区与DolphinDB相同;chunkSize=1024;总共385个分区 | high |
| MongoDB TAQ复合索引 | time_and_size_cost | date_1_symbol_1增序索引耗时53分钟,占用空间19G | high |
| DolphinDB import method (TAQ) | script_feature | 使用submitJob与loadTextEx{db, `taq, `date`symbol, fp}进行导入并用timer计时 | medium |
| MongoDB import method (TAQ) | data_preprocessing | 将约63G数据分为16个小文件导入,每个3.5G~4.4G | high |
| MongoDB import method (TAQ) | command | 使用mongoimport并设置--numInsertionWorkers 12,指定字段类型(symbol.string(), date.date(20060102), time.date(15:04:05)等) | medium |
| Import benchmark result (table described) | dolphindb_rate_and_time_on_16亿_records | 每秒导入记录数约231.8万条;导入总耗时691秒;性能倍数最高达到MongoDB的286倍 | medium |
| Import performance interpretation | dataset_type_effect | readings多字符串、TAQ多数值;数值类型导入更快,因此两库导入TAQ速率更快 | medium |
| MongoDB import scaling (observed) | time_vs_records | 导入3千万条记录约需1小时;导入16亿条记录约需55小时;在字段相差不大时导入时间与记录条数大约成正比 | medium |
| DolphinDB import scaling (observed) | time_vs_size | 导入4.2G需63秒;导入62.4G需11分30秒;在列字段类型和数量相差不大时导入时间与文件大小大约成正比 | medium |
| MongoDB slower import reasons | reason_1 | 文档型逐条导入,记录条数大时导入时长增加、性能下降 | medium |
| MongoDB slower import reasons | reason_2 | sharding集群必须开启journaling日志,先写入记录再导入操作,降低导入速度 | medium |
| MongoDB slower import reasons | reason_3 | 无主键概念;为保证唯一性需自动生成唯一索引且导入与索引同时进行,从而降低导入速度 | medium |
| DolphinDB export method | command | timer saveText((select * from t), "/media/xllu/aa/device/device_readings_out.csv") | high |
| MongoDB export method | command | mongoexport -h localhost:40000 -d db_nopt -c device_readings -o /media/xllu/aa/device/ device_readings_mongo_out.csv | high |
| Export benchmark result (small dataset, table described) | relative_performance | DolphinDB导出速度每秒150万条、耗时20秒;MongoDB需16分钟;DolphinDB约为MongoDB的49倍 | medium |
| Disk usage measurement | method | DolphinDB读取所有列式数据文件大小;MongoDB通过db.stats()获得;两库均有一个备份;MongoDB存储大小包括索引大小 | high |
| Disk usage result | relative_usage | 相同数据量下MongoDB磁盘占用约为DolphinDB的2~3倍 | medium |
| DolphinDB storage/compression | details | 列式存储;每列固定类型;使用LZ4压缩;针对symbol类型采用位图压缩提高压缩率 | medium |
| MongoDB storage/compression | details | 本次测试使用WiredTiger存储引擎与snappy压缩算法 | high |
| Index overhead on disk usage | details | readings对time与device_id索引大小1.1G;TAQ对date与symbol索引大小19G,导致MongoDB存储空间变大 | high |
| Query benchmark scope | query_types | 对比8种常用SQL查询:点查询、范围查询、聚合查询、精度查询(hour/minute)、关联查询、对比查询、抽样查询、经典查询 | high |
| Query timing methodology | time_unit_and_scope | 执行时间以毫秒为单位;指标为服务器执行时间,不包括结果传输与显示时间 | high |
| Small dataset query test | io_and_cache_policy | 测试磁盘分区数据且时间包含磁盘IO;每次启动前sync并drop_caches;启动后执行样例一遍并记录时间 | high |
| DolphinDB small dataset handle | script | dp_readings = "dfs://db_range_dfs";device_readings=loadTable(dp_readings, `readings_pt) | high |
| MongoDB small dataset setup | database_switch | 执行use device_pt切换至device_pt数据库 | high |
| Join query setup (small dataset) | info_dataset_loaded_to_memory | MongoDB:db.device_info.find({})加载3,000条设备记录;DolphinDB:loadText(dp_info)加载3,000条设备记录 | high |
| Timing tools | dolphindb_vs_mongodb | DolphinDB用timer计算查询耗时;MongoDB用explain()获取执行时间 | high |
| Range query observation | partition_field_included | 包含分区字段的范围查询中(如查询3、4),MongoDB可调用复合索引、DolphinDB可用分区加快;差距在4倍以内 | medium |
| Range query observation | non_partition_field | 包含未分区字段的查询(如查询5)中,MongoDB无法调用未分区字段索引需全字段搜索过滤;DolphinDB无需搜索不在where过滤条件中的字段;差距进一步扩大 | medium |
| Point query observation | case_1 | 查询1在MongoDB有time+device_id索引下可快速找到时间点记录;DolphinDB按日期分区需选定分区再检索,因此DolphinDB慢于MongoDB | medium |
| Composite index rule (MongoDB) | leftmost_prefix | 查询字段必须包括复合索引的首字段索引才起作用;仅按设备ID过滤不含time时不会调用复合索引 | medium |
| Join capability comparison | mongodb_limitations | MongoDB仅支持左外连接;无主键约束;表连接只能用内嵌文档方式且不利于计算与聚合 | medium |
| DolphinDB joins | supported_join_types | 支持等值连接、左连接、全连接、asof连接、窗口连接和交叉连接 | high |
| Sampling query comparison | not_compared_reason | MongoDB可用$sample实现抽样但方式依赖集合大小、N与pipeline位置;DolphinDB不支持全表抽样仅支持分区字段抽样;实现差别大因此不做比较 | high |
| DolphinDB interpolation | supported_methods | 支持4种插值:ffill、bfill、lfill、nullFill | high |
| MongoDB interpolation | support | 没有内置函数实现插值查询 | high |
| MongoDB pivot/crosstab | support | 由于文档/BSON无行列概念,无法实现选择两个维度将表字段整理为表格(pivot)功能;因此不做比较 | high |
| DolphinDB pivot | support | 内置pivot by函数,可将指定内容按维度整理为表 | high |
| Large dataset query test setup | database_handles | DolphinDB:taq_pt_db="dfs://db_compound_dfs";taq_pt_col=loadTable(taq_pt_db, `readings_pt);MongoDB:use taq_pt_db切换数据库 | medium |
| Large dataset query result (narrative) | relative_performance | 在大数据量且均分区情况下,DolphinDB仍比MongoDB快约5-20倍;点查询(日期+股票代码)差距不大且DolphinDB略慢;复杂过滤/排序/聚合差距约10-20倍 | medium |
| Overall conclusion | structured_time_series | 处理结构化时序数据时(导入导出、磁盘占用、查询速度),DolphinDB整体优于MongoDB | medium |
| Overall conclusion | mongodb_advantage | MongoDB在数据模型多变场景与处理非结构化数据方面更有优势 | medium |
| Appendix: DolphinDB config links | resources | controller.cfg、agent.cfg、cluster.cfg、cluster.nodes(GitHub Tutorials_CN benchmark路径) | high |
| Appendix: MongoDB config link | resource | master_mongos.txt(路由服务器配置) | high |
| Appendix: DolphinDB partition scripts | resources | dolphindb_readings_partitioned.txt、dolphindb_taq_partitioned.txt | high |
| Appendix: MongoDB partition scripts | resources | mongodb_readings_partitioned.txt、mongodb_taq_partitioned.txt | high |
| Appendix: MongoDB query scripts | resources | mongodb_readings_query.txt、mongodb_taq_query.txt | high |