Skip to content

Test IOPS limits on a running mongodb instance

Notifications You must be signed in to change notification settings

vladsf/mongotest

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MongoDB IOPS Test Program

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.

Features

  • 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.

Requirements

  • Go 1.18 or later.
  • A running MongoDB instance.

Setup

Environment Variables

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 to 27017).

To set these environment variables:

On Linux/MacOS

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 27017

On Windows (Command Prompt)

Run the following commands:

set MONGO_USERNAME=<your_username>
set MONGO_PASSWORD=<your_password>
set MONGO_PORT=<your_port> # Optional, defaults to 27017

Example Configuration

For example, to connect to a MongoDB instance running on localhost:

export MONGO_USERNAME=admin
export MONGO_PASSWORD=admin123
export MONGO_PORT=27017

How to Run the Program

  1. Clone this repository:

    git clone https://github.com/vladsf/mongotest.git
    cd mongotest
  2. Install dependencies:

    go mod tidy
  3. Run the program:

    go run main.go

Output

The program outputs the following:

  1. Current RPS: Prints the current Requests Per Second every second.
  2. Overall RPS: Prints the overall RPS after all documents have been written.
  3. Database and Collection Creation: Automatically creates the database or collection if they do not exist, and logs the creation.

Sample Output

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

Notes

  • Ensure the MongoDB instance is running and accessible before executing the program.
  • The MongoDB instance must allow connections using the provided MONGO_USERNAME and MONGO_PASSWORD.

License

This project is licensed under the MIT License. See the LICENSE file for details.

About

Test IOPS limits on a running mongodb instance

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published