Skip to content

Commit 4e9a3fb

Browse files
committed
Added projection to mongo db benchmarks
1 parent a80eca9 commit 4e9a3fb

File tree

3 files changed

+59
-48
lines changed

3 files changed

+59
-48
lines changed

readme.md

+30-30
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Test runs autoncannon requests from 100 connections over 30 seconds on a 2022 Ma
2525

2626
| Subject | Time |
2727
| --- | --- |
28-
| MongoDB🥇 | 21.7s |
28+
| MongoDB🥇 | 21.9s |
2929
| MySQL JSON🥈 | 24.3s |
3030
| MySQL EAV | 2m 57.8s |
3131
| PostgreSQL JSONB🥉 | 25.6s |
@@ -101,57 +101,57 @@ Test runs autoncannon requests from 100 connections over 30 seconds on a 2022 Ma
101101
#### 10 connections over 30 seconds
102102
| Stat | MongoDB | MySQL JSON🥇 | MySQL EAV🥉 | PostgreSQL JSONB🥈 |
103103
| --- | --- | --- | --- | --- |
104-
| Latency | 5ms | 2ms | 2ms | 2ms |
105-
| Req/Sec | 3979 | 4948 | 4275 | 4294 |
106-
| Bytes/Sec | 2.66 | 3.31 | 2.85 | 2.87 |
107-
| Total Requests | 119K | 148K | 128K | 129K |
104+
| Latency | 2ms | 2ms | 2ms | 2ms |
105+
| Req/Sec | 4181 | 4948 | 4275 | 4294 |
106+
| Bytes/Sec | 2.93 | 3.31 | 2.85 | 2.87 |
107+
| Total Requests | 125K | 148K | 128K | 129K |
108108
| Server errors | - | - | - | - |
109109

110110
#### 50 connections over 20 seconds
111-
| Stat | MongoDB🥉 | MySQL JSON🥈 | MySQL EAV | PostgreSQL JSONB🥇 |
111+
| Stat | MongoDB🥇 | MySQL JSON🥉 | MySQL EAV | PostgreSQL JSONB🥈 |
112112
| --- | --- | --- | --- | --- |
113-
| Latency | 8ms | 7ms | 9ms | 7ms |
114-
| Req/Sec | 5606 | 6410 | 5383 | 6532 |
115-
| Bytes/Sec | 3.75 | 4.29 | 3.59 | 4.37 |
116-
| Total Requests | 112K | 128K | 108K | 131K |
113+
| Latency | 7ms | 7ms | 9ms | 7ms |
114+
| Req/Sec | 6748 | 6410 | 5383 | 6532 |
115+
| Bytes/Sec | 4.72 | 4.29 | 3.59 | 4.37 |
116+
| Total Requests | 135K | 128K | 108K | 131K |
117117
| Server errors | - | - | - | - |
118118

119119
#### 100 connections over 10 seconds
120-
| Stat | MongoDB🥉 | MySQL JSON🥈 | MySQL EAV | PostgreSQL JSONB🥇 |
120+
| Stat | MongoDB🥇 | MySQL JSON🥉 | MySQL EAV | PostgreSQL JSONB🥈 |
121121
| --- | --- | --- | --- | --- |
122-
| Latency | 17ms | 15ms | 18ms | 15ms |
123-
| Req/Sec | 5707 | 6443 | 5501 | 6504 |
124-
| Bytes/Sec | 3.81 | 4.31 | 3.67 | 4.35 |
125-
| Total Requests | 57K | 64K | 55K | 65K |
122+
| Latency | 14ms | 15ms | 18ms | 15ms |
123+
| Req/Sec | 6687 | 6443 | 5501 | 6504 |
124+
| Bytes/Sec | 4.68 | 4.31 | 3.67 | 4.35 |
125+
| Total Requests | 67K | 64K | 55K | 65K |
126126
| Server errors | - | - | - | - |
127127

128128
### Get random by ID (bulk 100 documents, partial document 10 fields)
129129

130130
#### 10 connections over 30 seconds
131-
| Stat | MongoDB🥉 | MySQL JSON🥈 | MySQL EAV | PostgreSQL JSONB🥇 |
131+
| Stat | MongoDB🥇 | MySQL JSON🥉 | MySQL EAV | PostgreSQL JSONB🥈 |
132132
| --- | --- | --- | --- | --- |
133-
| Latency | 53ms | 24ms | 133ms | 23ms |
134-
| Req/Sec | 188 | 403 | 75 | 432 |
135-
| Bytes/Sec | 9.52 | 20.46 | 3.79 | 21.89 |
136-
| Total Requests | 6K | 12K | 2K | 13K |
133+
| Latency | 15ms | 24ms | 133ms | 23ms |
134+
| Req/Sec | 650 | 403 | 75 | 432 |
135+
| Bytes/Sec | 32.98 | 20.46 | 3.79 | 21.89 |
136+
| Total Requests | 20K | 12K | 2K | 13K |
137137
| Server errors | - | - | - | - |
138138

139139
#### 50 connections over 20 seconds
140-
| Stat | MongoDB🥈 | MySQL JSON | MySQL EAV🥉 | PostgreSQL JSONB🥇 |
140+
| Stat | MongoDB🥇 | MySQL JSON | MySQL EAV🥉 | PostgreSQL JSONB🥈 |
141141
| --- | --- | --- | --- | --- |
142-
| Latency | 262ms | 14ms | 516ms | 118ms |
143-
| Req/Sec | 190 | 3544 | 96 | 421 |
144-
| Bytes/Sec | 9.61 | 12.03 | 4.84 | 21.38 |
145-
| Total Requests | 4K | 71K | 2K | 8K |
142+
| Latency | 80ms | 14ms | 516ms | 118ms |
143+
| Req/Sec | 619 | 3544 | 96 | 421 |
144+
| Bytes/Sec | 31.41 | 12.03 | 4.84 | 21.38 |
145+
| Total Requests | 12K | 71K | 2K | 8K |
146146
| Server errors | - | ❌ 66611 | - | - |
147147

148148
#### 100 connections over 10 seconds
149-
| Stat | MongoDB🥈 | MySQL JSON | MySQL EAV🥉 | PostgreSQL JSONB🥇 |
149+
| Stat | MongoDB🥇 | MySQL JSON | MySQL EAV🥉 | PostgreSQL JSONB🥈 |
150150
| --- | --- | --- | --- | --- |
151-
| Latency | 523ms | 14ms | 877ms | 233ms |
152-
| Req/Sec | 187 | 7072 | 109 | 424 |
153-
| Bytes/Sec | 9.46 | 2.55 | 5.49 | 21.52 |
154-
| Total Requests | 2K | 71K | 1K | 4K |
151+
| Latency | 159ms | 14ms | 877ms | 233ms |
152+
| Req/Sec | 621 | 7072 | 109 | 424 |
153+
| Bytes/Sec | 31.51 | 2.55 | 5.49 | 21.52 |
154+
| Total Requests | 6K | 71K | 1K | 4K |
155155
| Server errors | - | ❌ 70707 | - | - |
156156

157157
<!-- tablestop -->

src/benchmarks/get-random-by-id-bulk-obj-part/mongo.js

+20-12
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,32 @@ const {FIELDS} = require('./constants');
88
runApp(async (app) => {
99
const collection = await getCollection();
1010

11+
const projection = FIELDS.reduce(
12+
(acc, field) => {
13+
// @ts-ignore
14+
acc[field] = 1;
15+
16+
return acc;
17+
},
18+
{}
19+
);
20+
1121
app.get('/benchmark', async (request, reply) => {
1222
const productIds = Array.from({length: 100}, () =>
1323
faker.datatype.number({min: 1, max: 100000})
1424
);
1525

16-
const cursor = collection.find({
17-
product_id: {
18-
$in: productIds,
26+
const cursor = collection.find(
27+
{
28+
product_id: {
29+
$in: productIds,
30+
},
1931
},
20-
});
21-
22-
return (await cursor.toArray()).map((product) => {
23-
return FIELDS.reduce((acc, field) => {
24-
// @ts-ignore
25-
acc[field] = product[field];
32+
{
33+
projection,
34+
}
35+
);
2636

27-
return acc;
28-
}, {});
29-
});
37+
return await cursor.toArray();
3038
});
3139
});

src/benchmarks/get-random-by-id-obj-part/mongo.js

+9-6
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ const {FIELDS} = require('./constants');
77
runApp(async (app) => {
88
const collection = await getCollection();
99

10+
const projection = FIELDS.reduce((acc, field) => {
11+
// @ts-ignore
12+
acc[field] = 1;
13+
14+
return acc;
15+
}, {});
16+
1017
app.get('/benchmark', async (request, reply) => {
1118
const productId = faker.datatype.number({min: 1, max: 100000});
1219

@@ -15,15 +22,11 @@ runApp(async (app) => {
1522
product_id: productId,
1623
},
1724
{
25+
projection,
1826
limit: 1,
1927
}
2028
);
2129

22-
return FIELDS.reduce((acc, field) => {
23-
// @ts-ignore
24-
acc[field] = product[field];
25-
26-
return acc;
27-
}, {});
30+
return product;
2831
});
2932
});

0 commit comments

Comments
 (0)