Hello everybody.
Last week we created an account of Mongodb Atlas Service. We are doing do some stress tests to see the performance of one part of our system using Mongo.
Context:
- Mongo version 5.0.18
- Test 1
Resources M30 (azure) with 1 shards - Test 2
Resources M30 (azure) with 2 shards
How the test works?
We are processing in parallel 40 items and then we wait 1s to process 40 items more. The total items to process is 1600.
Every item is not going to be a register in the database, one sigle item will create more than 100 registers inside the database.
The process we followed to create the sharded collections:
1- sh.enableSharding(âdb-nameâ)
2- db.createCollection(âcollection-nameâ)
3- db.getCollection(âcollection-nameâ).createIndex({ PartitionKey: âhashedâ });
4- sh.shardCollection(âdb-name.collection nameâ, { PartitionKey: âhashedâ });
5- sh.status() to see if the collections are well created and distributed in the 2 shards.
After that we run a script in our system that creates several registers inside the collections but the time to process these data doesnât dicrease if we add a new shard.
What we are doing wrong? Why is the total time of the process not dicreasing with one more shard?
Here you can see some data from sh.status after we run our script:
"db-name.collection2": {
shardKey: { PartitionKey: "hashed" },
unique: false,
balancing: true,
chunkMetadata: [
{ shard: "atlas-7dz9ng-shard-0", nChunks: 2 },
{ shard: "atlas-7dz9ng-shard-1", nChunks: 2 },
],
chunks: [
{
min: { PartitionKey: MinKey() },
max: { PartitionKey: -4611686018427388000 },
"on shard": "atlas-7dz9ng-shard-0",
"last modified": Timestamp({ t: 1, i: 0 }),
},
{
min: { PartitionKey: -4611686018427388000 },
max: { PartitionKey: 0 },
"on shard": "atlas-7dz9ng-shard-0",
"last modified": Timestamp({ t: 1, i: 1 }),
},
{
min: { PartitionKey: 0 },
max: { PartitionKey: 4611686018427388000 },
"on shard": "atlas-7dz9ng-shard-1",
"last modified": Timestamp({ t: 1, i: 2 }),
},
{
min: { PartitionKey: 4611686018427388000 },
max: { PartitionKey: MaxKey() },
"on shard": "atlas-7dz9ng-shard-1",
"last modified": Timestamp({ t: 1, i: 3 }),
},
],
tags: [],
},
"db-name.collection2": {
shardKey: { PartitionKey: "hashed" },
unique: false,
balancing: true,
chunkMetadata: [
{ shard: "atlas-7dz9ng-shard-0", nChunks: 2 },
{ shard: "atlas-7dz9ng-shard-1", nChunks: 2 },
],
chunks: [
{
min: { PartitionKey: MinKey() },
max: { PartitionKey: -4611686018427388000 },
"on shard": "atlas-7dz9ng-shard-0",
"last modified": Timestamp({ t: 1, i: 0 }),
},
{
min: { PartitionKey: -4611686018427388000 },
max: { PartitionKey: 0 },
"on shard": "atlas-7dz9ng-shard-0",
"last modified": Timestamp({ t: 1, i: 1 }),
},
{
min: { PartitionKey: 0 },
max: { PartitionKey: 4611686018427388000 },
"on shard": "atlas-7dz9ng-shard-1",
"last modified": Timestamp({ t: 1, i: 2 }),
},
{
min: { PartitionKey: 4611686018427388000 },
max: { PartitionKey: MaxKey() },
"on shard": "atlas-7dz9ng-shard-1",
"last modified": Timestamp({ t: 1, i: 3 }),
},
],
tags: [],
}
Thank you for your time