Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions frameworks/fulmine-tuned/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# fulmine-tuned
# fulmine.js-tuned

The same entry as [`fulmine`](../fulmine/), differing in three settings and nothing else. Diff the
The same entry as [`fulmine.js`](../fulmine/), differing in three settings and nothing else. Diff the
two `app.js` and that is all there is to see: same routes, same middleware, same compression, same
`express.static()`. What the tuning buys is measured by the arena, not claimed here.

Expand Down
35 changes: 18 additions & 17 deletions frameworks/fulmine-tuned/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -404,14 +404,15 @@ app.get('/api/me', async (req, res) => {
}
});

// express.raw() is the framework's parser for a body that is bytes: it takes the whole body off
// uWS in one piece, content-length or chunked alike, where a handler on 'data' pays a stream per
// request. The type function reads the body whatever the content type says, as an echo must.
const readRaw = express.raw({ type: () => true, limit: '1mb' });

function registerEchoRoute(target) {
target.post('/echo', (req, res) => {
const chunks = [];
req.on('data', chunk => chunks.push(chunk));
req.on('end', () => {
// one chunk is the whole body at this size, and concat of one still copies
res.type('application/octet-stream').send(chunks.length === 1 ? chunks[0] : Buffer.concat(chunks));
});
target.post('/echo', readRaw, (req, res) => {
// an empty body leaves req.body unset, and the echo of nothing is nothing
res.type('application/octet-stream').send(Buffer.isBuffer(req.body) ? req.body : Buffer.alloc(0));
});
}

Expand All @@ -429,16 +430,16 @@ app.get('/baseline11', (req, res) => {
res.type('text/plain').send(String(sumQuery(req.query)));
});

app.post('/baseline11', (req, res) => {
const querySum = sumQuery(req.query);
let body = '';
req.on('data', chunk => body += chunk);
req.on('end', () => {
let total = querySum;
const n = parseInt(body.trim(), 10);
if (n === n) total += n;
res.type('text/plain').send(String(total));
});
// express.text() is the framework's parser for a text body, and it is cheaper than assembling
// the chunks by hand for the same reason as the echo above. The type function is there because
// the load generator sends no Content-Type, and without one the parser would step over the body.
const readText = express.text({ type: () => true });

app.post('/baseline11', readText, (req, res) => {
let total = sumQuery(req.query);
const n = parseInt(typeof req.body === 'string' ? req.body.trim() : '', 10);
if (n === n) total += n;
res.type('text/plain').send(String(total));
});

// shared by the plaintext listener and the TLS one on 8081, as the JSON route is: static-tls
Expand Down
2 changes: 1 addition & 1 deletion frameworks/fulmine-tuned/meta.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"display_name": "fulmine-tuned",
"display_name": "fulmine.js-tuned",
"language": "JS",
"type": "emerging",
"mode": "tuned",
Expand Down
2 changes: 1 addition & 1 deletion frameworks/fulmine/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# fulmine
# fulmine.js

A drop-in replacement for Express 5 running on uWebSockets.js, with its own `cluster` option for multi-core scaling.

Expand Down
35 changes: 18 additions & 17 deletions frameworks/fulmine/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -405,14 +405,15 @@ app.get('/api/me', async (req, res) => {
}
});

// express.raw() is the framework's parser for a body that is bytes: it takes the whole body off
// uWS in one piece, content-length or chunked alike, where a handler on 'data' pays a stream per
// request. The type function reads the body whatever the content type says, as an echo must.
const readRaw = express.raw({ type: () => true, limit: '1mb' });

function registerEchoRoute(target) {
target.post('/echo', (req, res) => {
const chunks = [];
req.on('data', chunk => chunks.push(chunk));
req.on('end', () => {
// one chunk is the whole body at this size, and concat of one still copies
res.type('application/octet-stream').send(chunks.length === 1 ? chunks[0] : Buffer.concat(chunks));
});
target.post('/echo', readRaw, (req, res) => {
// an empty body leaves req.body unset, and the echo of nothing is nothing
res.type('application/octet-stream').send(Buffer.isBuffer(req.body) ? req.body : Buffer.alloc(0));
});
}

Expand All @@ -430,16 +431,16 @@ app.get('/baseline11', (req, res) => {
res.type('text/plain').send(String(sumQuery(req.query)));
});

app.post('/baseline11', (req, res) => {
const querySum = sumQuery(req.query);
let body = '';
req.on('data', chunk => body += chunk);
req.on('end', () => {
let total = querySum;
const n = parseInt(body.trim(), 10);
if (n === n) total += n;
res.type('text/plain').send(String(total));
});
// express.text() is the framework's parser for a text body, and it is cheaper than assembling
// the chunks by hand for the same reason as the echo above. The type function is there because
// the load generator sends no Content-Type, and without one the parser would step over the body.
const readText = express.text({ type: () => true });

app.post('/baseline11', readText, (req, res) => {
let total = sumQuery(req.query);
const n = parseInt(typeof req.body === 'string' ? req.body.trim() : '', 10);
if (n === n) total += n;
res.type('text/plain').send(String(total));
});

// shared by the plaintext listener and the TLS one on 8081, as the JSON route is: static-tls
Expand Down
2 changes: 1 addition & 1 deletion frameworks/fulmine/meta.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"display_name": "fulmine",
"display_name": "fulmine.js",
"language": "JS",
"type": "emerging",
"mode": "standard",
Expand Down
4 changes: 2 additions & 2 deletions site/data/frameworks.json
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,7 @@
"response": false
}
},
"fulmine-tuned": {
"fulmine.js-tuned": {
"dir": "fulmine-tuned",
"description": "fulmine.js with the caches its standard entry has to leave off: the in-memory small-file cache and the stat cache, both shipped settings, both forbidden to a standard entry because they keep a static request off the disk.",
"repo": "https://github.com/nigrosimone/fulmine.js",
Expand All @@ -596,7 +596,7 @@
"response": true
}
},
"fulmine": {
"fulmine.js": {
"dir": "fulmine",
"description": "fulmine.js (drop-in Express 5 on uWebSockets.js) with its own cluster option for multi-core scaling.",
"repo": "https://github.com/nigrosimone/fulmine.js",
Expand Down
Loading