|
| 1 | +--- |
| 2 | +title: MongoDB Baseline Testing |
| 3 | +weight: 5 |
| 4 | + |
| 5 | +### FIXED, DO NOT MODIFY |
| 6 | +layout: learningpathall |
| 7 | +--- |
| 8 | + |
| 9 | + |
| 10 | +### Baseline testing of MongoDB |
| 11 | +Perform baseline testing by verifying MongoDB is running, logging into the shell, executing a few test queries, and monitoring live performance. This ensures the database is functioning correctly before starting any benchmarks. |
| 12 | + |
| 13 | +1. Verify Installation & Service Health |
| 14 | + |
| 15 | +```console |
| 16 | +ps -ef | grep mongod |
| 17 | +mongod --version |
| 18 | +netstat -tulnp | grep 27017 |
| 19 | +``` |
| 20 | +- **ps -ef | grep mongod** – Checks if the MongoDB server process is running. |
| 21 | +- **mongod --version** – Shows the version of MongoDB installed. |
| 22 | +- **netstat -tulnp | grep 27017** – Checks if MongoDB is listening for connections on its default port 27017. |
| 23 | + |
| 24 | +You should see an output similar to: |
| 25 | + |
| 26 | +```output |
| 27 | +mongod --version |
| 28 | +netstat -tulnp | grep 27017 |
| 29 | +ubuntu 4288 1 0 10:40 ? 00:00:01 mongod --dbpath /var/lib/mongo --logpath /var/log/mongodb/mongod.log --fork |
| 30 | +ubuntu 4545 1764 0 10:43 pts/0 00:00:00 grep --color=auto mongod |
| 31 | +db version v8.0.12 |
| 32 | +Build Info: { |
| 33 | + "version": "8.0.12", |
| 34 | + "gitVersion": "b60fc6875b5fb4b63cc0dbbd8dda0d6d6277921a", |
| 35 | + "openSSLVersion": "OpenSSL 3.0.13 30 Jan 2024", |
| 36 | + "modules": [], |
| 37 | + "allocator": "tcmalloc-google", |
| 38 | + "environment": { |
| 39 | + "distmod": "ubuntu2404", |
| 40 | + "distarch": "aarch64", |
| 41 | + "target_arch": "aarch64" |
| 42 | + } |
| 43 | +} |
| 44 | +(Not all processes could be identified, non-owned process info |
| 45 | + will not be shown, you would have to be root to see it all.) |
| 46 | +tcp 0 0 127.0.0.1:27017 0.0.0.0:* LISTEN 4288/mongod |
| 47 | +``` |
| 48 | + |
| 49 | +2. Storage and Health Check |
| 50 | + |
| 51 | +Run the command below to check how fast your storage can **randomly read small 4KB chunks** from a 100 MB file for 30 seconds, using one job, and then show a summary report: |
| 52 | + |
| 53 | +```console |
| 54 | +fio --name=baseline --rw=randread --bs=4k --size=100M --numjobs=1 --time_based --runtime=30 --group_reporting |
| 55 | +``` |
| 56 | +You should see an output similar to: |
| 57 | + |
| 58 | +```output |
| 59 | +baseline: (g=0): rw=randread, bs=(R) 4096B-4096B, (W) 4096B-4096B, (T) 4096B-4096B, ioengine=psync, iodepth=1 |
| 60 | +fio-3.36 |
| 61 | +Starting 1 process |
| 62 | +Jobs: 1 (f=1): [r(1)][100.0%][r=14.8MiB/s][r=3799 IOPS][eta 00m:00s] |
| 63 | +baseline: (groupid=0, jobs=1): err= 0: pid=3753: Mon Sep 1 10:25:07 2025 |
| 64 | + read: IOPS=4255, BW=16.6MiB/s (17.4MB/s)(499MiB/30001msec) |
| 65 | + clat (usec): min=88, max=46246, avg=234.23, stdev=209.81 |
| 66 | + lat (usec): min=88, max=46246, avg=234.28, stdev=209.81 |
| 67 | + clat percentiles (usec): |
| 68 | + | 1.00th=[ 99], 5.00th=[ 111], 10.00th=[ 126], 20.00th=[ 167], |
| 69 | + | 30.00th=[ 190], 40.00th=[ 229], 50.00th=[ 243], 60.00th=[ 253], |
| 70 | + | 70.00th=[ 269], 80.00th=[ 289], 90.00th=[ 318], 95.00th=[ 330], |
| 71 | + | 99.00th=[ 416], 99.50th=[ 490], 99.90th=[ 799], 99.95th=[ 1106], |
| 72 | + | 99.99th=[ 3884] |
| 73 | + bw ( KiB/s): min=14536, max=19512, per=100.00%, avg=17046.10, stdev=1359.69, samples=59 |
| 74 | + iops : min= 3634, max= 4878, avg=4261.53, stdev=339.92, samples=59 |
| 75 | + lat (usec) : 100=1.27%, 250=56.61%, 500=41.65%, 750=0.34%, 1000=0.06% |
| 76 | + lat (msec) : 2=0.04%, 4=0.01%, 10=0.01%, 20=0.01%, 50=0.01% |
| 77 | + cpu : usr=0.33%, sys=2.93%, ctx=127668, majf=0, minf=8 |
| 78 | + IO depths : 1=100.0%, 2=0.0%, 4=0.0%, 8=0.0%, 16=0.0%, 32=0.0%, >=64=0.0% |
| 79 | + submit : 0=0.0%, 4=100.0%, 8=0.0%, 16=0.0%, 32=0.0%, 64=0.0%, >=64=0.0% |
| 80 | + complete : 0=0.0%, 4=100.0%, 8=0.0%, 16=0.0%, 32=0.0%, 64=0.0%, >=64=0.0% |
| 81 | + issued rwts: total=127661,0,0,0 short=0,0,0,0 dropped=0,0,0,0 |
| 82 | + latency : target=0, window=0, percentile=100.00%, depth=1 |
| 83 | +
|
| 84 | +Run status group 0 (all jobs): |
| 85 | + READ: bw=16.6MiB/s (17.4MB/s), 16.6MiB/s-16.6MiB/s (17.4MB/s-17.4MB/s), io=499MiB (523MB), run=30001-30001msec |
| 86 | +
|
| 87 | +Disk stats (read/write): |
| 88 | + sda: ios=127195/29, sectors=1017560/552, merge=0/15, ticks=29133/8, in_queue=29151, util=96.37% |
| 89 | +``` |
| 90 | +The output shows how fast it read data (**16.6 MB/s**) and how many reads it did per second (**~4255 IOPS**), which tells you how responsive your storage is for random reads. |
| 91 | + |
| 92 | +3. Connectivity and CRUD Sanity Check |
| 93 | + |
| 94 | +```console |
| 95 | +mongosh --host localhost --port 27017 |
| 96 | +``` |
| 97 | + |
| 98 | +Inside shell: |
| 99 | + |
| 100 | +```javascript |
| 101 | +use baselineDB |
| 102 | +db.testCollection.insertOne({ name: "baseline-check", value: 1 }) |
| 103 | +db.testCollection.find() |
| 104 | +db.testCollection.updateOne({ name: "baseline-check" }, { $set: { value: 2 } }) |
| 105 | +db.testCollection.deleteOne({ name: "baseline-check" }) |
| 106 | +exit |
| 107 | +``` |
| 108 | +These commands create a test record, read it, update its value, and then delete it a simple way to check if MongoDB’s basic **add, read, update, and delete** operations are working. |
| 109 | + |
| 110 | +You should see an output similar to: |
| 111 | + |
| 112 | +```output |
| 113 | +test> use baselineDB |
| 114 | +switched to db baselineDB |
| 115 | +baselineDB> db.testCollection.insertOne({ name: "baseline-check", value: 1 }) |
| 116 | +{ |
| 117 | + acknowledged: true, |
| 118 | + insertedId: ObjectId('689acdae6a86b49bca74e39a') |
| 119 | +} |
| 120 | +baselineDB> db.testCollection.find() |
| 121 | +[ |
| 122 | + { |
| 123 | + _id: ObjectId('689acdae6a86b49bca74e39a'), |
| 124 | + name: 'baseline-check', |
| 125 | + value: 1 |
| 126 | + } |
| 127 | +] |
| 128 | +baselineDB> db.testCollection.updateOne({ name: "baseline-check" }, { $set: { value: 2 } }) |
| 129 | +... |
| 130 | +{ |
| 131 | + acknowledged: true, |
| 132 | + insertedId: null, |
| 133 | + matchedCount: 1, |
| 134 | + modifiedCount: 1, |
| 135 | + upsertedCount: 0 |
| 136 | +} |
| 137 | +baselineDB> db.testCollection.deleteOne({ name: "baseline-check" }) |
| 138 | +... |
| 139 | +{ acknowledged: true, deletedCount: 1 } |
| 140 | +``` |
| 141 | + |
| 142 | +4. Basic Query Performance Test |
| 143 | + |
| 144 | +```console |
| 145 | +mongosh --eval ' |
| 146 | +db = db.getSiblingDB("baselineDB"); |
| 147 | +for (let i=0; i<1000; i++) { db.perf.insertOne({index:i, value:Math.random()}) }; |
| 148 | +var start = new Date(); |
| 149 | +db.perf.find({ value: { $gt: 0.5 } }).count(); |
| 150 | +print("Query Time (ms):", new Date() - start); |
| 151 | +' |
| 152 | +``` |
| 153 | +The command connected to MongoDB, switched to the **baselineDB** database, inserted **1,000 documents** into the perf collection, and then measured the execution time for counting documents where **value > 0.5**. The final output displayed the **query execution time** in milliseconds. |
| 154 | + |
| 155 | +You should see an output similar to: |
| 156 | + |
| 157 | +```output |
| 158 | +Query Time (ms): 2 |
| 159 | +``` |
| 160 | + |
| 161 | +5. Index Creation Speed Test |
| 162 | + |
| 163 | +```console |
| 164 | +mongosh --eval ' |
| 165 | +db = db.getSiblingDB("baselineDB"); |
| 166 | +var start = new Date(); |
| 167 | +db.perf.createIndex({ value: 1 }); |
| 168 | +print("Index Creation Time (ms):", new Date() - start); |
| 169 | +' |
| 170 | +``` |
| 171 | +The test connected to MongoDB, switched to the **baselineDB** database, and created an index on the **value** field in the **perf** collection. The index creation process completed in **22 milliseconds**, indicating relatively fast index building for the dataset size. |
| 172 | + |
| 173 | +You should see an output similar to: |
| 174 | + |
| 175 | +```output |
| 176 | +Index Creation Time (ms): 22 |
| 177 | +``` |
| 178 | + |
| 179 | +6. Concurrency Smoke Test |
| 180 | + |
| 181 | +```console |
| 182 | +for i in {1..5}; do |
| 183 | + /usr/bin/mongosh --eval 'use baselineDB; db.concurrent.insertMany([...Array(1000).keys()].map(k => ({ test: k, ts: new Date() })))' & |
| 184 | +done |
| 185 | +wait |
| 186 | +``` |
| 187 | +This command runs **five MongoDB insert jobs at the same time**, each adding **1,000 new records** to the **baselineDB.concurrent** collection. |
| 188 | +It’s a quick way to test how MongoDB handles **multiple users writing data at once**. |
| 189 | + |
| 190 | +You should see an output similar to: |
| 191 | + |
| 192 | +```output |
| 193 | +[1] 3818 |
| 194 | +[2] 3819 |
| 195 | +[3] 3820 |
| 196 | +[4] 3821 |
| 197 | +[5] 3822 |
| 198 | +switched to db baselineDB; |
| 199 | +[1] Done mongosh --eval 'use baselineDB; db.concurrent.insertMany([...Array(1000).keys()].map(k => ({ test: k, ts: new Date() })))' |
| 200 | +switched to db baselineDB; |
| 201 | +switched to db baselineDB; |
| 202 | +switched to db baselineDB; |
| 203 | +[2] Done mongosh --eval 'use baselineDB; db.concurrent.insertMany([...Array(1000).keys()].map(k => ({ test: k, ts: new Date() })))' |
| 204 | +[4]- Done mongosh --eval 'use baselineDB; db.concurrent.insertMany([...Array(1000).keys()].map(k => ({ test: k, ts: new Date() })))' |
| 205 | +[3]- Done mongosh --eval 'use baselineDB; db.concurrent.insertMany([...Array(1000).keys()].map(k => ({ test: k, ts: new Date() })))' |
| 206 | +switched to db baselineDB; |
| 207 | +[5]+ Done mongosh --eval 'use baselineDB; db.concurrent.insertMany([...Array(1000).keys()].map(k => ({ test: k, ts: new Date() })))' |
| 208 | +``` |
| 209 | + |
| 210 | +**Five parallel MongoDB shell sessions** were executed, each inserting **1,000** test documents into the baselineDB.concurrent collection. All sessions completed successfully, confirming that concurrent data insertion works as expected. |
| 211 | + |
| 212 | +The above operations confirm that MongoDB is installed successfully and is functioning as expected on the Azure Cobalt 100 (Arm64) environment. |
| 213 | + |
| 214 | +Now, your MongoDB instance is ready for further benchmarking and production use. |
0 commit comments