Skip to content

Commit 4949905

Browse files
committed
feat: add body-parser load test (#77)
1 parent 57593c9 commit 4949905

File tree

7 files changed

+207
-1
lines changed

7 files changed

+207
-1
lines changed

package-lock.json

Lines changed: 24 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/requests/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
"exports": {
55
"./get-basic-paths": "./get-basic-paths.mjs",
66
"./get-slash": "./get-slash.mjs",
7-
"./get-query": "./get-query.mjs"
7+
"./get-query": "./get-query.mjs",
8+
"./post-json": "./post-json.mjs"
89
},
910
"scripts": {
1011
"test": "echo \"Error: no test specified\" && exit 1",

packages/requests/post-json.mjs

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
export default [
2+
{
3+
method: 'POST',
4+
path: '/json',
5+
headers: {
6+
'content-type': 'application/json'
7+
},
8+
// small json body
9+
body: JSON.stringify({
10+
small: 'json body'
11+
})
12+
},
13+
14+
{
15+
method: 'POST',
16+
path: '/json',
17+
headers: {
18+
'content-type': 'application/json'
19+
},
20+
// medium json body
21+
// (yes I stole this from the first google result for "example json payload")
22+
body: JSON.stringify({
23+
rowset: {
24+
coldesc: [{
25+
type: 'string',
26+
name: 'Identifier'
27+
}, {
28+
type: 'string',
29+
name: 'Node'
30+
}, {
31+
type: 'string',
32+
name: 'Manager'
33+
}, {
34+
type: 'string',
35+
name: 'Agent'
36+
}, {
37+
type: 'string',
38+
name: 'AlertKey'
39+
}, {
40+
type: 'integer',
41+
name: 'Severity'
42+
}, {
43+
type: 'integer',
44+
name: 'Type'
45+
}, {
46+
type: 'string',
47+
name: 'Summary'
48+
}, {
49+
type: 'integer',
50+
name: 'Acknowledged'
51+
}, {
52+
type: 'string',
53+
name: 'Location'
54+
}, {
55+
type: 'utc',
56+
name: 'FirstOccurrence'
57+
}, {
58+
type: 'utc',
59+
name: 'LastOccurrence'
60+
}, {
61+
type: 'integer',
62+
name: 'OwnerUID'
63+
}, {
64+
type: 'integer',
65+
name: 'OwnerGID'
66+
}],
67+
rows: [{
68+
FirstOccurrence: 1341412087,
69+
Node: 'localhost',
70+
AlertKey: 'JUnitEventInstance',
71+
Agent: 'createEventNew()',
72+
Summary: 'This is a test event generated by the JUnit REST Event Tests.(0)',
73+
LastOccurrence: 1341412087,
74+
Acknowledged: 0,
75+
Identifier: 'JUnitEventTestInstance####0',
76+
Manager: 'com.ibm.netcool.omnibus.ws.junit.rest.schema.utils.TableRowEvent',
77+
OwnerGID: 0,
78+
Location: 'NOT UPDATED',
79+
Type: 1,
80+
Severity: 4,
81+
OwnerUID: 0
82+
}],
83+
affectedRows: 0
84+
}
85+
})
86+
},
87+
88+
{
89+
method: 'POST',
90+
path: '/json',
91+
headers: {
92+
'content-type': 'application/json'
93+
},
94+
// large json body
95+
body: JSON.stringify((() => {
96+
const body = {};
97+
for (let i = 0; i++; i < 1000) {
98+
body[`${i}k`] = { [i]: 'v'.repeat(i) };
99+
}
100+
return body;
101+
})())
102+
}
103+
];

perf/load/body-parser/index.mjs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
export async function requests () {
2+
return (await import('@expressjs/perf-requests/post-json')).default;
3+
}
4+
5+
export function server () {
6+
return import('@expressjs/perf-servers-express-body-parser');
7+
}
8+
9+
if (import.meta.main || import.meta.filename === process.argv[1]) {
10+
await server();
11+
}

perf/load/body-parser/package.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"name": "@expressjs/perf-load-body-parser",
3+
"version": "1.0.0",
4+
"main": "index.mjs",
5+
"scripts": {
6+
"setup": "npm i --no-workspaces --install-links"
7+
},
8+
"keywords": [],
9+
"author": "",
10+
"license": "ISC",
11+
"description": "",
12+
"dependencies": {
13+
"@expressjs/perf-requests": "file:../../../packages/requests",
14+
"@expressjs/perf-servers-express-helloworld": "file:../../../servers/express-helloworld"
15+
}
16+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
const start = process.hrtime();
2+
const express = require('express');
3+
const expressVersion = require('express/package.json').version;
4+
5+
const app = express();
6+
app.use(express.json());
7+
app.use(express.urlencoded());
8+
app.use(express.text());
9+
app.use(express.raw());
10+
app.post(expressVersion.startsWith('4.') ? '*' : '*path', (req, res) => {
11+
res.status(200).json({
12+
hello: 'body!',
13+
url: req.url,
14+
headers: req.headers,
15+
body: req.body
16+
});
17+
});
18+
app.use((req, res) => {
19+
console.log('404:', req.url.toString());
20+
res.status(404).json({
21+
what: 'world?',
22+
url: req.url,
23+
headers: req.headers,
24+
query: req.query
25+
});
26+
});
27+
app.use((err, req, res) => {
28+
console.log(err);
29+
console.log('500:', req.url.toString());
30+
res.status(500).json({
31+
goodbye: 'cruel world!',
32+
url: req.url,
33+
headers: req.headers,
34+
query: req.query
35+
});
36+
});
37+
38+
app.listen(process.env.PORT || 3000, () => {
39+
console.log(`startup: ${process.hrtime(start)}`);
40+
});
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"name": "@expressjs/perf-servers-express-body-parser",
3+
"version": "1.0.0",
4+
"main": "index.js",
5+
"scripts": {
6+
"setup": "npm i"
7+
},
8+
"dependencies": {
9+
"express": "^5.1.0"
10+
}
11+
}

0 commit comments

Comments
 (0)