Skip to content
Open
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
18 changes: 10 additions & 8 deletions benchmark/quic/h3-request.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const bench = common.createBenchmark(main, {
'--no-warnings'] });

async function main({ mode, n }) {
const { listen, connect } = require('node:quic');
const { listen, connect, Http3Session } = require('node:quic');
const { bytes } = require('stream/iter');

const key = createPrivateKey(fixtures.readKey('agent1-key.pem'));
Expand All @@ -37,11 +37,13 @@ async function main({ mode, n }) {
':authority': 'localhost',
};

const endpoint = await listen((session) => {
const endpoint = await listen((quicSession) => {
const session = new Http3Session(quicSession);
session.opened.catch(() => {});
session.closed.catch(() => {});
session.onstream = (stream) => { stream.closed.catch(() => {}); };
}, {
alpn: ['h3'],
sni: { '*': { keys: [key], certs: [cert] } },
onheaders() {
this.sendHeaders({ ':status': '200' });
Expand All @@ -63,12 +65,12 @@ async function main({ mode, n }) {
// A full handshake, one request, one response. When resume is supplied the
// request goes out in the first flight, before the handshake completes.
async function exchange(resume) {
const session = await connect(address, {
const session = new Http3Session(await connect(address, {
servername: 'localhost',
verifyPeer: 'manual',
alpn: 'h3',
...resume,
});
}));
const stream = await session.createBidirectionalStream({
headers: request,
onheaders,
Expand All @@ -89,7 +91,7 @@ async function main({ mode, n }) {
const { promise, resolve } = Promise.withResolvers();
let ticket;
let token;
const session = await connect(address, {
const session = new Http3Session(await connect(address, {
servername: 'localhost',
verifyPeer: 'manual',
alpn: 'h3',
Expand All @@ -101,7 +103,7 @@ async function main({ mode, n }) {
token ??= value;
if (ticket !== undefined) resolve();
},
});
}));
await session.opened;
await promise;
session.close();
Expand All @@ -115,12 +117,12 @@ async function main({ mode, n }) {
// otherwise a ticket the server stopped accepting would quietly turn this
// into a measurement of the 1-RTT path.
async function checkEarlyDataAccepted() {
const session = await connect(address, {
const session = new Http3Session(await connect(address, {
servername: 'localhost',
verifyPeer: 'manual',
alpn: 'h3',
...resume,
});
}));
const stream = await session.createBidirectionalStream({
headers: request,
onheaders,
Expand Down
15 changes: 9 additions & 6 deletions benchmark/quic/handshake.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,23 @@ const { createPrivateKey } = require('crypto');

const bench = common.createBenchmark(main, {
// 'raw' negotiates a non-HTTP ALPN and does no application work.
// 'h3' negotiates HTTP/3, so the server also builds an nghttp3 connection
// and its control/QPACK streams for every session.
// 'h3' installs HTTP/3 on every session, so each peer also builds an
// nghttp3 connection and its control/QPACK streams.
protocol: ['raw', 'h3'],
concurrency: [1, 10],
n: [1000],
}, { flags: ['--experimental-quic', '--no-warnings'] });

async function main({ protocol, concurrency, n }) {
const { listen, connect } = require('node:quic');
const { listen, connect, Http3Session } = require('node:quic');

const key = createPrivateKey(fixtures.readKey('agent1-key.pem'));
const cert = fixtures.readKey('agent1-cert.pem');
const alpn = protocol === 'h3' ? 'h3' : 'quic-bench';
const http3 = protocol === 'h3';
const alpn = http3 ? 'h3' : 'quic-bench';

const endpoint = await listen((session) => {
const endpoint = await listen((quicSession) => {
const session = http3 ? new Http3Session(quicSession) : quicSession;
// A benchmark peer never reads these; swallow so a torn-down session
// cannot produce an unhandled rejection.
session.opened.catch(() => {});
Expand All @@ -46,11 +48,12 @@ async function main({ protocol, concurrency, n }) {
const address = endpoint.address;

async function handshake() {
const session = await connect(address, {
const quicSession = await connect(address, {
servername: 'localhost',
verifyPeer: 'manual',
alpn,
});
const session = http3 ? new Http3Session(quicSession) : quicSession;
await session.opened;
session.close();
await session.closed.catch(() => {});
Expand Down
Loading
Loading