MongoDB性能测试(Windows环境)

一、测试环境

Server硬件环境:

mongodb性能压力测试 mongodb 性能测试_json


Client硬件环境:

mongodb性能压力测试 mongodb 性能测试_Server_02

MongoDB版本:mongodb 5.0.14

二、性能测试

2-1 测试方式一

测试json长度:251个字符

实验目的:往MongoDB中插入10000条json,统计花费的时间(即QPS)
条件:连接-->插入一条-->断开,三个过程算一轮插入

实验次序

插入数量

花费时间

QPS

第一次

10000

23s

235

第二次

10000

19s

526

第三次

20000

123s

162

第四次

20000

124s

161

第五次

30000

187s

160

第六次

50000

318s

157

Bug

测试Bug:几次测试过后,后面的测试基本每插入10000多条就会报错,报错提示如下:

mongodb性能压力测试 mongodb 性能测试_json_03

初步猜测是由于内存释放不干净导致,释放函数没有返回值,无法确认是否释放成功。

/* free bson_t memory */
bson_destroy(doc);
/* free mongoc_collection_t */
mongoc_collection_destroy(collection);
/* free mongoc_client_t */
mongoc_client_destroy(client);

💡 解决方法:
在下一轮插入document前,无脑Sleep(10). 发现Bug不再出现,甚至插入30000+ document,都没有出现bug

mongodb性能压力测试 mongodb 性能测试_Server_04

2-2 测试方式二

测试json长度:251个字符

实验目的:往MongoDB中插入10000条json,统计花费的时间(即QPS)
条件:连接-->插入10000条-->断开

实验次序

插入数量

花费时间

QPS

第一次

10000

15.86s

631

第二次

10000

14.02s

713

第三次

30000

40.83s

735

第四次

30000

43.88s

684

第五次

30000

41.21s

728

2-3 测试方式三

测试json长度:535个字符

实验目的:json长度和通过ODBC 插入长度一致,用于对比两者的QPS
条件:连接-->插入10000条(或30000)-->断开

实验次序

插入数量

花费时间

QPS

第一次

30000

44.38s

676

第二次

30000

46.15s

650

第三次

30000

46.89s

640