DB-MongoDB-00002--Workload Generator for MongoDB

news2025/5/23 19:42:11

##

DB-MongoDB-00002–Workload Generator for MongoDB

1、介绍

Workload Generator for MongoDB was designed to help MongoDB users effortlessly generate data and simulate workloads for both sharded and non-sharded clusters. The generated workloads include standard CRUD operations, reflecting real-world usage patterns of a MongoDB environment.

Additionally, the tool supports the creation of realistic workloads by incorporating all CRUD operations through a set of queries that simulate common usage scenarios. Users can also define custom queries to run against collections created by the tool, further enhancing its flexibility and applicability.

While the tool provides extensive configuration capabilities, it requires minimal setup — only basic connection details are needed. It is user-friendly, does not require compilation, and offers a high level of flexibility.

The application was developed and tested using Python 3. As such, Python 3 is recommended for optimal compatibility. If upgrading is not feasible, modifications to the scripts may be necessary to support older Python versions.

The tool is optimized to leverage as many available CPU cores as you wish and supports configuration of an arbitrary number of threads among, enabling high parallelism and making it ideal for generating large-scale workloads and conducting effective stress tests on MongoDB clusters.

一句话:另一个YCSB

2、安装
[root@mongodb01 ~]# python --version
Python 3.9.18
[root@mongodb01 ~]# pip --version
-bash: pip: command not found
[root@mongodb01 ~]# pip3 --version
-bash: pip3: command not found
Error: Unable to find a match: install
[root@mongodb01 ~]# dnf install -y python3-pip

[root@mongodb01 ~]# pip3 install faker joblib pymongo
Collecting faker
  Downloading faker-37.3.0-py3-none-any.whl (1.9 MB)
     |████████████████████████████████| 1.9 MB 382 kB/s
Collecting joblib
  Downloading joblib-1.5.0-py3-none-any.whl (307 kB)
     |████████████████████████████████| 307 kB 10.2 MB/s
Collecting pymongo
  Downloading pymongo-4.13.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (937 kB)
     |████████████████████████████████| 937 kB 564 kB/s
Collecting tzdata
  Downloading tzdata-2025.2-py2.py3-none-any.whl (347 kB)
     |████████████████████████████████| 347 kB 11.2 MB/s
Collecting dnspython<3.0.0,>=1.16.0
  Downloading dnspython-2.7.0-py3-none-any.whl (313 kB)
     |████████████████████████████████| 313 kB 1.9 MB/s
Installing collected packages: tzdata, dnspython, pymongo, joblib, faker
Successfully installed dnspython-2.7.0 faker-37.3.0 joblib-1.5.0 pymongo-4.13.0 tzdata-2025.2
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead:                     https://pip.pypa.io/warnings/venv

[root@mongodb01 ~]# wget https://github.com/Percona-Lab/mongoDB-workload-generator/archive/refs/tags/0.1.zip
--2025-05-18 21:10:06--  https://github.com/Percona-Lab/mongoDB-workload-generator/archive/refs/tags/0.1.zip
Connecting to 192.168.5.18:7890... connected.
Proxy request sent, awaiting response... 302 Found
Location: https://codeload.github.com/Percona-Lab/mongoDB-workload-generator/zip/refs/tags/0.1 [following]
--2025-05-18 21:10:07--  https://codeload.github.com/Percona-Lab/mongoDB-workload-generator/zip/refs/tags/0.1
Connecting to 192.168.5.18:7890... connected.
Proxy request sent, awaiting response... 200 OK
Length: unspecified [application/zip]
Saving to: ‘0.1.zip’

0.1.zip                                            [ <=>                                                                                                ]  23.48K  --.-KB/s    in 0.06s

2025-05-18 21:10:09 (420 KB/s) - ‘0.1.zip’ saved [24040]

[root@mongodb01 ~]# mv 0.1.zip mongoDB-workload-generator-0.1.zip
[root@mongodb01 ~]# unzip mongoDB-workload-generator-0.1.zip
[root@mongodb01 ~]# cd mongoDB-workload-generator-0.1/
3、配置

基本配置就需要配置mongodbCreds.py这个文件就可以了

[root@mongodb01 mongoDB-workload-generator-0.1]# cat mongodbCreds.py
# Configuration for MongoDB connection
dbconfig = {
    "username": "login_here",
    "password": "password_here",
    "port": 27017,
    "hosts": [
        "mongos00",
        "mongos01"
    ],
    "serverSelectionTimeoutMS": 5000, # We need this to fail faster, otherwise the default is 30 seconds
    "connectTimeoutMS": 3000,  # Example timeout setting
    "maxPoolSize": 500, # Example pool setting
    # Leave replicaSet: None if connecting to mongos. Enter the appropriate replicaSet name if connecting to replicaSet instead of Mongos
    "replicaSet": None,
    "authSource": "admin",  # Adjust for authentication
    "tls": "false",  # Example tls setting
}[root@mongodb01 mongoDB-workload-generator-0.1]#
3.1、常见错误

如果连接信息配置错误或者在MongoDB没有开启认证的时候,就会出现这个错误

CRITICAL:root:Unable to connect to MongoDB, please make sure your configuration is correct.
Error: mongos01:27017: [Errno -2] Name or service not known (configured timeouts: socketTimeoutMS: 3000.0ms, connectTimeoutMS: 3000.0ms),mongos00:27017: [Errno -2] Name or service not known (configured timeouts: socketTimeoutMS: 3000.0ms, connectTimeoutMS: 3000.0ms), Timeout: 5.0s, Topology Description: <TopologyDescription id: 6829e152d0087848897bc0a8, topology_type: Unknown, servers: [<ServerDescription ('mongos00', 27017) server_type: Unknown, rtt: None, error=AutoReconnect('mongos00:27017: [Errno -2] Name or service not known (configured timeouts: socketTimeoutMS: 3000.0ms, connectTimeoutMS: 3000.0ms)')>, <ServerDescription ('mongos01', 27017) server_type: Unknown, rtt: None, error=AutoReconnect('mongos01:27017: [Errno -2] Name or service not known (configured timeouts: socketTimeoutMS: 3000.0ms, connectTimeoutMS: 3000.0ms)')>]>
3.2、配置无认证模式

如果MongoDB没有开启认证,如何连接数据库呢

3.2.1、配置mongodbCreds.py文件

旧文件

dbconfig = {
    "username": "login_here",
    "password": "password_here",
    "port": 27017,
    "hosts": [
        "mongos00",
        "mongos01"
    ],

新文件,把username/password删了,并且修改hosts

[root@mongodb01 mongoDB-workload-generator-0.1]# cat mongodbCreds.py
# Configuration for MongoDB connection
dbconfig = {
    "port": 27017,
    "hosts": [
        "mongodb01"
    ],
    "serverSelectionTimeoutMS": 5000, # We need this to fail faster, otherwise the default is 30 seconds
    "connectTimeoutMS": 3000,  # Example timeout setting
    "maxPoolSize": 500, # Example pool setting
    # Leave replicaSet: None if connecting to mongos. Enter the appropriate replicaSet name if connecting to replicaSet instead of Mongos
    "replicaSet": None,
    "authSource": "admin",  # Adjust for authentication
    "tls": "false",  # Example tls setting
}
3.2.2、配置app.py文件

旧连接串

[root@mongodb01 mongoDB-workload-generator-0.1]# more app.py
# Start building the base connection URI
connection_uri = f"mongodb://{dbconfig['username']}:{dbconfig['password']}@{hosts}"

新连接串,这个地方还可以加localhost

[root@mongodb01 mongoDB-workload-generator-0.1]# more app.py
# Start building the base connection URI
#connection_uri = f"mongodb://{dbconfig['username']}:{dbconfig['password']}@{hosts}"
connection_uri = f"mongodb://{hosts}"
3.3、负载测试
[root@mongodb01 mongoDB-workload-generator-0.1]# ./mongodbWorkload.py
2025-05-18 21:38:28 - INFO - Configuring Workload
2025-05-18 21:38:28 - INFO -

Duration: 60 seconds
CPUs: 1
Threads: (Per CPU: 4 | Total: 4)
Collections: 1
Configure Sharding: False
Insert batch size: 10
Optimized workload: False
Workload ratio: SELECTS: 60% | INSERTS: 10% | UPDATES: 20% | DELETES: 10%
Report frequency: 5 seconds
Report logfile: None

===================================================================================================================
                                                 Workload Started
===================================================================================================================

2025-05-18 21:38:38 - INFO - AVG Operations last 5s (1 CPUs): 264.20 (SELECTS: 154.20, INSERTS: 31.00, UPDATES: 50.40, DELETES: 28.60)
2025-05-18 21:38:43 - INFO - AVG Operations last 5s (1 CPUs): 303.40 (SELECTS: 187.40, INSERTS: 30.80, UPDATES: 54.80, DELETES: 30.40)
2025-05-18 21:38:48 - INFO - AVG Operations last 5s (1 CPUs): 243.00 (SELECTS: 138.00, INSERTS: 30.00, UPDATES: 53.00, DELETES: 22.00)
2025-05-18 21:38:53 - INFO - AVG Operations last 5s (1 CPUs): 326.00 (SELECTS: 201.40, INSERTS: 29.40, UPDATES: 60.40, DELETES: 34.80)
2025-05-18 21:38:58 - INFO - AVG Operations last 5s (1 CPUs): 271.20 (SELECTS: 162.60, INSERTS: 30.00, UPDATES: 53.20, DELETES: 25.40)
2025-05-18 21:39:03 - INFO - AVG Operations last 5s (1 CPUs): 322.80 (SELECTS: 191.80, INSERTS: 29.40, UPDATES: 67.60, DELETES: 34.00)
2025-05-18 21:39:08 - INFO - AVG Operations last 5s (1 CPUs): 276.20 (SELECTS: 167.60, INSERTS: 28.80, UPDATES: 49.20, DELETES: 30.60)
2025-05-18 21:39:13 - INFO - AVG Operations last 5s (1 CPUs): 260.40 (SELECTS: 149.20, INSERTS: 30.60, UPDATES: 51.20, DELETES: 29.40)
2025-05-18 21:39:18 - INFO - AVG Operations last 5s (1 CPUs): 290.20 (SELECTS: 172.20, INSERTS: 28.40, UPDATES: 59.60, DELETES: 30.00)
2025-05-18 21:39:23 - INFO - AVG Operations last 5s (1 CPUs): 282.60 (SELECTS: 168.00, INSERTS: 29.20, UPDATES: 54.60, DELETES: 30.80)
2025-05-18 21:39:28 - INFO - AVG Operations last 5s (1 CPUs): 245.80 (SELECTS: 145.00, INSERTS: 29.00, UPDATES: 48.40, DELETES: 23.40)
2025-05-18 21:39:33 - INFO - AVG Operations last 5s (1 CPUs): 266.60 (SELECTS: 158.20, INSERTS: 26.40, UPDATES: 54.40, DELETES: 27.60)
2025-05-18 21:39:38 - INFO - AVG Operations last 5s (1 CPUs): 266.60 (SELECTS: 158.20, INSERTS: 26.40, UPDATES: 54.40, DELETES: 27.60)
2025-05-18 21:39:38 - INFO -
===================================================================================================================
                                                Workload Finished
===================================================================================================================

2025-05-18 21:39:38 - INFO -
================================================================================
|                               Collection Stats                               |
================================================================================
|            Name         |     Sharded      |      Size      |    Documents   |
================================================================================
|         flights_1       |      False       |   115.40 MB    |      47407     |
================================================================================

2025-05-18 21:39:38 - INFO -
===================================================================================================================
                                        Workload Stats (All CPUs Combined)
===================================================================================================================
Workload Runtime: 1.17 minutes
CPUs Used: 1
Total Operations: 16762 (SELECT: 9978, INSERT: 1765, UPDATE: 3284, DELETE: 1735)
AVG QPS: 238.79 (SELECTS: 142.15, INSERTS: 25.14, UPDATES: 46.78, DELETES: 24.72)
Documents Inserted: 17650, Matching Documents Selected: 9865, Documents Updated: 2995, Documents Deleted: 1573
===================================================================================================================
4、Ref

https://www.percona.com/blog/mongodb-benchmarking-made-effortless-with-mongodb-workload-generator/

https://github.com/Percona-Lab/mongoDB-workload-generator

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/2384105.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

3.8.1 利用RDD实现词频统计

在本次实战中&#xff0c;我们通过Spark的RDD实现了词频统计功能。首先&#xff0c;准备了包含单词的文件并上传至HDFS。接着&#xff0c;采用交互式方式逐步完成词频统计&#xff0c;包括创建RDD、单词拆分、映射为二元组、按键归约以及排序等操作。此外&#xff0c;还通过创建…

Spring Ioc和Aop,Aop的原理和实现案例,JoinPoint,@Aspect,@Before,@AfterReturning

DAY25.2 Java核心基础 Spring两大核心&#xff1a;Ioc和Aop IOC Ioc容器&#xff1a;装载bean的容器&#xff0c;自动创建bean 三种方式&#xff1a; 1、基于xml配置&#xff1a;通过在xml里面配置bean&#xff0c;然后通过反射机制创建bean&#xff0c;存入进Ioc容器中 …

[解决conda创建新的虚拟环境没用python的问题]

问题复现 使用conda create -n env的时候&#xff0c;在对应的虚拟环境的文件里面找不到对应的python文件 为什么 首先&#xff0c;我们来看一下创建环境时的触发链路&#xff1a; 这表明当前环境中找不到Python可执行文件。 解决方法 所以很明显&#xff0c;我们需要指定…

【C++】控制台小游戏

移动&#xff1a;W向上&#xff0c;S上下&#xff0c;A向左&#xff0c;D向右 程序代码&#xff1a; #include <iostream> #include <conio.h> #include <windows.h> using namespace std;bool gameOver; const int width 20; const int height 17; int …

配合本专栏前端文章对应的后端文章——从模拟到展示:一步步搭建传感器数据交互系统

对应文章&#xff1a;进一步完善前端框架搭建及vue-konva依赖的使用&#xff08;Vscode&#xff09;-CSDN博客 目录 一、后端开发 1.模拟传感器数据 2.前端页面呈现数据后端互通 2.1更新模拟传感器数据程序&#xff08;多次请求&#xff09; 2.2&#x1f9e9; 功能目标 …

springboot IOC

springboot IOC IoC Inversion of Control Inversion 反转 依赖注入 DI &#xff08;dependency injection &#xff09; dependency 依赖 injection 注入 Qualifier 预选赛 一文带你快速理解JavaWeb中分层解耦的思想及其实现&#xff0c;理解 IOC和 DI https://zhuanlan.…

Ajax01-基础

一、AJAX 1.AJAX概念 使浏览器的XMLHttpRequest对象与服务器通信 浏览器网页中&#xff0c;使用 AJAX技术&#xff08;XHR对象&#xff09;发起获取省份列表数据的请求&#xff0c;服务器代码响应准备好的省份列表数据给前端&#xff0c;前端拿到数据数组以后&#xff0c;展…

生成树协议(STP)配置详解:避免网络环路的最佳实践

生成树协议&#xff08;STP&#xff09;配置详解&#xff1a;避免网络环路的最佳实践 生成树协议&#xff08;STP&#xff09;配置详解&#xff1a;避免网络环路的最佳实践一、STP基本原理二、STP 配置示例&#xff08;华为交换机&#xff09;1. 启用生成树协议2. 配置根桥3. 查…

面向 C 语言项目的系统化重构实战指南

摘要: 在实际开发中,C 语言项目往往随着功能演进逐渐变得混乱:目录不清、宏滥用、冗余代码、耦合高、测试少……面对这样的“技术债积累”,盲目大刀阔斧只会带来更多混乱。本文结合 C 语言的特点,从项目评估、目录规划、宏与内联、接口封装、冗余剔除、测试与 CI、迭代重构…

Python Pandas库简介及常见用法

Python Pandas库简介及常见用法 一、 Pandas简介1. 简介2. 主要特点&#xff08;一&#xff09;强大的数据结构&#xff08;二&#xff09;灵活的数据操作&#xff08;三&#xff09;时间序列分析支持&#xff08;四&#xff09;与其他库的兼容性 3.应用场景&#xff08;一&…

第十六届蓝桥杯复盘

文章目录 1.数位倍数2.IPv63.变换数组4.最大数字5.小说6.01串7.甘蔗8.原料采购 省赛过去一段时间了&#xff0c;现在复盘下&#xff0c;省赛报完名后一直没准备所以没打算参赛&#xff0c;直到比赛前两天才决定参加&#xff0c;赛前两天匆匆忙忙下载安装了比赛要用的编译器ecli…

【已解决】HBuilder X编辑器在外接显示器或者4K显示器怎么界面变的好小问题

触发方式&#xff1a;主要涉及DPI缩放问题&#xff0c;可能在电脑息屏有概率触发 修复方式&#xff1a; 1.先关掉软件直接更改屏幕缩放&#xff0c;然后打开软件&#xff0c;再关掉软件恢复原来的缩放&#xff0c;再打开软件就好了 2.(不推荐&#xff09;右键HBuilder在属性里…

直线型绝对值位移传感器:精准测量的科技利刃

在科技飞速发展的今天&#xff0c;精确测量成为了众多领域不可或缺的关键环节。无论是工业自动化生产线上的精细操作&#xff0c;还是航空航天领域中对零部件位移的严苛把控&#xff0c;亦或是科研实验中对微小位移变化的精准捕捉&#xff0c;都离不开一款高性能的测量设备——…

Ansible模块——管理100台Linux的最佳实践

使用 Ansible 管理 100 台 Linux 服务器时&#xff0c;推荐遵循以下 最佳实践&#xff0c;以提升可维护性、可扩展性和安全性。以下内容结合实战经验进行总结&#xff0c;适用于中大型环境&#xff08;如 100 台服务器&#xff09;&#xff1a; 一、基础架构设计 1. 分组与分层…

从0开始学习大模型--Day09--langchain初步使用实战

众所周知&#xff0c;一味地学习知识&#xff0c;所学的东西和概念都是空中楼阁&#xff0c;大部分情况下&#xff0c;实战都是很有必要的&#xff0c;今天就通过微调langchain来更深刻地理解它。 中间如何进入到langchain界面请参考结尾视频链接。 首先&#xff0c;进入界面…

C++中的菱形继承问题

假设有一个问题&#xff0c;类似于鸭子这样的动物有很多种&#xff0c;如企鹅和鱿鱼&#xff0c;它们也可能会有一些共同的特性。例如&#xff0c;我们可以有一个叫做 AquaticBird &#xff08;涉禽&#xff0c;水鸟的一类&#xff09;的类&#xff0c;它又继承自 Animal 和 Sw…

网络-MOXA设备基本操作

修改本机IP和网络设备同网段&#xff0c;输入设备IP地址进入登录界面&#xff0c;交换机没有密码&#xff0c;路由器密码为moxa 修改设备IP地址 交换机 路由器 环网 启用Turbo Ring协议&#xff1a;在设备的网络管理界面中&#xff0c;找到环网配置选项&#xff0c;启用Turb…

飞桨paddle import fluid报错【已解决】

跟着飞桨的安装指南安装了paddle之后 pip install paddlepaddle有一个验证&#xff1a; import paddle.fluid as fluid fluid.install check.run check()报错情况如下&#xff0c;但是我在pip list中&#xff0c;确实看到了paddle安装上了 我import paddle别的包&#xff0c…

测试工程师要如何开展单元测试

单元测试是软件开发过程中至关重要的环节&#xff0c;它通过验证代码的最小可测试单元(如函数、方法或类)是否按预期工作&#xff0c;帮助开发团队在早期发现和修复缺陷&#xff0c;提升代码质量和可维护性。以下是测试工程师开展单元测试的详细步骤和方法&#xff1a; 一、理…

IPv4 地址嵌入 IPv6 的前缀转换方式详解

1. 概述 在 IPv4 和 IPv6 网络共存的过渡期&#xff0c;NAT64&#xff08;Network Address Translation 64&#xff09;是一种关键技术&#xff0c;用于实现 IPv6-only 网络与 IPv4-only 网络的互操作。NAT64 前缀转换通过将 IPv4 地址嵌入到 IPv6 地址中&#xff0c;允许 IPv…