A high-performance MongoDB benchmarking tool written in Go that tests various operations (insert, update, delete) using concurrent goroutines.
- Concurrent operations using configurable number of threads
- Support for multiple operation types (insert, update, delete)
- Option to run all tests sequentially
- Support for large document testing
- Detailed performance metrics (operations/second, average latency)
- Graceful shutdown handling
- Go 1.16 or later
- MongoDB instance (local or remote)
git clone <repository-url>
cd mongodb-benchmark
go mod tidyBuild and run the benchmark tool:
go build -o benchmark cmd/benchmark/main.go
./benchmark [flags]-uri string: MongoDB URI (default "mongodb://localhost:27017")-threads int: Number of concurrent threads (default 10)-ops int: Number of operations to perform (default 1000)-type string: Test type (insert, update, delete) (default "insert")-all: Run all test types-large: Use large documents-dropDb: Drop database before running tests (default true)-db string: Database name (default "benchmark")-coll string: Collection name (default "testdata")
- Run insert benchmark with 20 threads and 10000 operations:
./benchmark -threads 20 -ops 10000 -type insert- Run all tests with large documents:
./benchmark -all -large- Run update benchmark with custom database and collection:
./benchmark -type update -db mydb -coll mycollThe tool provides detailed output including:
- Configuration settings
- Progress updates
- Final results with:
- Total operations completed
- Total time taken
- Operations per second
- Average latency
The application follows clean architecture principles with the following structure:
.
├── cmd/
│ └── benchmark/
│ └── main.go
├── pkg/
│ ├── config/
│ │ └── config.go
│ ├── models/
│ │ └── document.go
│ ├── repository/
│ │ └── mongodb.go
│ └── services/
│ └── benchmark_service.go
└── README.md
Contributions are welcome! Please feel free to submit a Pull Request.