Skip to content
Draft
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
8 changes: 5 additions & 3 deletions benchmark/_test-double-benchmarker.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,17 @@ if (!['http', 'https', 'http2'].includes(myModule)) {
throw new Error(`Invalid module for benchmark test double: ${myModule}`);
}

const url = process.env.test_url;

let options;
if (myModule === 'https') {
if (myModule === 'https' ||
(myModule === 'http2' && url.startsWith('https:'))) {
options = { rejectUnauthorized: false };
}

const http = require(myModule);

const duration = +process.env.duration;
const url = process.env.test_url;

const start = process.hrtime();
let throughput = 0;
Expand Down Expand Up @@ -45,7 +47,7 @@ function run() {
http.get(url, request);
}
} else { // HTTP/2
const client = http.connect(url);
const client = http.connect(url, options);
client.on('error', () => {});
request(client.request(), client);
}
Expand Down
51 changes: 51 additions & 0 deletions benchmark/http/fetch-server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
'use strict';

// Benchmarks the fetch() handler of the experimental Fetch Server API
// (http.fetchServer) over HTTP/1.1, with and without TLS.

const common = require('../common.js');
const { default_http_benchmarker } = require('../_http-benchmarkers.js');

const bench = common.createBenchmark(main, {
tls: [0, 1],
len: [4, 1024, 102400],
c: [50, 500],
duration: 5,
}, { flags: ['--experimental-http-serve', '--no-warnings'] });

function main({ tls, len, c, duration }) {
const { serve, ServerResponse } = require('http').fetchServer;
const body = Buffer.alloc(len, 'x');
const options = { port: 0, hostname: '127.0.0.1' };
if (tls) {
const fixtures = require('../../test/common/fixtures');
options.tls = {
key: fixtures.readKey('rsa_private.pem'),
cert: fixtures.readKey('rsa_cert.crt'),
};
}
const server = serve({
fetch() {
return new ServerResponse(body, {
headers: { 'content-type': 'text/plain' },
});
},
}, options);

server.ready.then(() => {
const [listener] = server;
// The test double for plain HTTP cannot speak TLS.
const benchmarker = tls && default_http_benchmarker === 'test-double-http' ?
'test-double-https' : undefined;
bench.http({
path: '/',
port: listener.address.port,
scheme: tls ? 'https' : 'http',
connections: c,
duration,
benchmarker,
}, () => {
server.destroy();
});
});
}
53 changes: 53 additions & 0 deletions benchmark/http2/fetch-server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
'use strict';

// Benchmarks the fetch() handler of the experimental Fetch Server API
// (http.fetchServer) over HTTP/2, with prior knowledge (h2c) and over TLS.

const common = require('../common.js');

const bench = common.createBenchmark(main, {
tls: [0, 1],
len: [4, 1024, 102400],
requests: [100, 1000, 5000],
streams: [1, 10, 100],
clients: [2],
benchmarker: ['test-double-http2'],
duration: 5,
}, { flags: ['--experimental-http-serve', '--no-warnings'] });

function main({ tls, len, requests, streams, clients, duration }) {
const { serve, ServerResponse } = require('http').fetchServer;
const body = Buffer.alloc(len, 'x');
const options = { port: 0, hostname: '127.0.0.1' };
if (tls) {
const fixtures = require('../../test/common/fixtures');
options.tls = {
key: fixtures.readKey('rsa_private.pem'),
cert: fixtures.readKey('rsa_cert.crt'),
alpn: ['h2'],
};
}
const server = serve({
fetch() {
return new ServerResponse(body, {
headers: { 'content-type': 'text/plain' },
});
},
}, options);

server.ready.then(() => {
const [listener] = server;
bench.http({
path: '/',
port: listener.address.port,
scheme: tls ? 'https' : 'http',
requests,
maxConcurrentStreams: streams,
clients,
threads: clients,
duration,
}, () => {
server.destroy();
});
});
}
12 changes: 12 additions & 0 deletions doc/api/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -1470,6 +1470,16 @@ added:

Enable exposition of [EventSource Web API][] on the global scope.

### `--experimental-http-serve`

<!-- YAML
added: REPLACEME
-->

> Stability: 1.0 - Early development

Enable the experimental [Fetch Server API][] exposed as `http.fetchServer`.

### `--experimental-import-meta-resolve`

<!-- YAML
Expand Down Expand Up @@ -4317,6 +4327,7 @@ one is included in the list below.
* `--experimental-detect-module`
* `--experimental-dtls`
* `--experimental-eventsource`
* `--experimental-http-serve`
* `--experimental-import-meta-resolve`
* `--experimental-import-text`
* `--experimental-json-modules`
Expand Down Expand Up @@ -4932,6 +4943,7 @@ node --stack-trace-limit=12 -p -e "Error.stackTraceLimit" # prints 12
[EventSource Web API]: https://html.spec.whatwg.org/multipage/server-sent-events.html#server-sent-events
[ExperimentalWarning: `vm.measureMemory` is an experimental feature]: vm.md#vmmeasurememoryoptions
[FIPS mode]: crypto.md#fips-mode
[Fetch Server API]: http.md#fetch-server-api
[File System Permissions]: permissions.md#file-system-permissions
[Loading ECMAScript modules using `require()`]: modules.md#loading-ecmascript-modules-using-require
[Module resolution and loading]: packages.md#module-resolution-and-loading
Expand Down
Loading