This program is a Go-based tool to test the IOPS (Input/Output Operations Per Second) limits of a running MongoDB instance. It creates parallel connections, writes random documents to the database, calculates the Requests Per Second (RPS), and provides detailed statistics during and after execution.
- Creates 50 parallel connections to the MongoDB instance.
- Writes 100,000 random documents to a specified MongoDB collection.
- Ensures a write speed of 100 requests per second.
- Dynamically calculates and prints the current Requests Per Second (RPS) every second.
- Reports the overall RPS after the program completes.
- Automatically creates the database or collection if they do not exist.
- Go 1.18 or later.
- A running MongoDB instance.
The program uses the following environment variables for configuration:
MONGO_USERNAME: The username for the MongoDB instance (required).MONGO_PASSWORD: The password for the MongoDB instance (required).MONGO_PORT: The port number for the MongoDB instance (optional, defaults to27017).
To set these environment variables:
Run the following commands in your terminal:
export MONGO_USERNAME=<your_username>
export MONGO_PASSWORD=<your_password>
export MONGO_PORT=<your_port> # Optional, defaults to 27017Run the following commands:
set MONGO_USERNAME=<your_username>
set MONGO_PASSWORD=<your_password>
set MONGO_PORT=<your_port> # Optional, defaults to 27017For example, to connect to a MongoDB instance running on localhost:
export MONGO_USERNAME=admin
export MONGO_PASSWORD=admin123
export MONGO_PORT=27017-
Clone this repository:
git clone https://github.com/vladsf/mongotest.git cd mongotest -
Install dependencies:
go mod tidy
-
Run the program:
go run main.go
The program outputs the following:
- Current RPS: Prints the current Requests Per Second every second.
- Overall RPS: Prints the overall RPS after all documents have been written.
- Database and Collection Creation: Automatically creates the database or collection if they do not exist, and logs the creation.
Database 'testdb' does not exist. It will be created automatically upon first write.
Collection 'testcollection' created successfully.
Current RPS: 98.76
Current RPS: 99.12
...
Finished writing 100000 documents. Overall RPS: 100.45
- Ensure the MongoDB instance is running and accessible before executing the program.
- The MongoDB instance must allow connections using the provided
MONGO_USERNAMEandMONGO_PASSWORD.
This project is licensed under the MIT License. See the LICENSE file for details.