-
-
Notifications
You must be signed in to change notification settings - Fork 36.6k
quic: reuse TLS pause machinery to drop event deferral & improve 0RTT #65522
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
pimterry
wants to merge
5
commits into
nodejs:main
Choose a base branch
from
pimterry:pause-for-quic-0rtt
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
63deaf9
quic: reuse TLS pause machinery to drop event deferral & improve 0RTT
pimterry a9abbf9
Handle review comments
pimterry 151ec9d
quic: don't allow servers to configure an empty ALPN list
pimterry 0eb48bf
Update docs to mention that ALPN must be non-empty
pimterry e641814
quic: add benchmarks for single request & connection setup
pimterry File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,150 @@ | ||
| 'use strict'; | ||
|
|
||
| // Measures a complete HTTP/3 exchange: establish a session, send one request | ||
| // and read the whole response. Run in two modes, so the cost of a resumed | ||
| // 0-RTT session can be compared against a full handshake. | ||
| // | ||
| // The 0-RTT mode needs a session ticket, which can only come from an earlier | ||
| // connection. That first connection is made during warmup, outside the | ||
| // measured region, so what is timed is only the resumed exchange. | ||
|
|
||
| const common = require('../common.js'); | ||
| const fixtures = require('../../test/common/fixtures'); | ||
| const { createPrivateKey } = require('crypto'); | ||
|
|
||
| const bench = common.createBenchmark(main, { | ||
| // '0rtt' resumes from a ticket and sends the request in the very first | ||
| // flight; '1rtt' is a fresh session each time. 0-RTT is listed first so | ||
| // that it is the mode the benchmark CI test exercises. | ||
| mode: ['0rtt', '1rtt'], | ||
| n: [500], | ||
| }, { flags: ['--experimental-quic', '--experimental-stream-iter', | ||
| '--no-warnings'] }); | ||
|
|
||
| async function main({ mode, n }) { | ||
| const { listen, connect } = require('node:quic'); | ||
| const { bytes } = require('stream/iter'); | ||
|
|
||
| const key = createPrivateKey(fixtures.readKey('agent1-key.pem')); | ||
| const cert = fixtures.readKey('agent1-cert.pem'); | ||
| const body = new TextEncoder().encode('x'.repeat(256)); | ||
| const decoder = new TextDecoder(); | ||
|
|
||
| const request = { | ||
| ':method': 'GET', | ||
| ':path': '/', | ||
| ':scheme': 'https', | ||
| ':authority': 'localhost', | ||
| }; | ||
|
|
||
| const endpoint = await listen((session) => { | ||
| session.opened.catch(() => {}); | ||
| session.closed.catch(() => {}); | ||
| session.onstream = (stream) => { stream.closed.catch(() => {}); }; | ||
| }, { | ||
| sni: { '*': { keys: [key], certs: [cert] } }, | ||
| onheaders() { | ||
| this.sendHeaders({ ':status': '200' }); | ||
| this.writer.writeSync(body); | ||
| this.writer.endSync(); | ||
| }, | ||
| endpoint: { | ||
| maxConnectionsPerHost: 0xFFFF, | ||
| maxConnectionsTotal: 0xFFFF, | ||
| sessionCreationRate: 1_000_000, | ||
| sessionCreationBurst: 1_000_000, | ||
| }, | ||
| }); | ||
|
|
||
| const address = endpoint.address; | ||
| let received = 0; | ||
| const onheaders = () => { received++; }; | ||
|
|
||
| // 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, { | ||
| servername: 'localhost', | ||
| verifyPeer: 'manual', | ||
| alpn: 'h3', | ||
| ...resume, | ||
| }); | ||
| const stream = await session.createBidirectionalStream({ | ||
| headers: request, | ||
| onheaders, | ||
| }); | ||
| if (resume === undefined) await session.opened; | ||
| const response = decoder.decode(await bytes(stream)); | ||
| if (response.length !== body.length) { | ||
| throw new Error(`short response: ${response.length}`); | ||
| } | ||
| session.close(); | ||
| await session.closed.catch(() => {}); | ||
| return session; | ||
| } | ||
|
|
||
| // Collect a ticket for the 0-RTT mode from a connection that is not timed. | ||
| let resume; | ||
| if (mode === '0rtt') { | ||
| const { promise, resolve } = Promise.withResolvers(); | ||
| let ticket; | ||
| let token; | ||
| const session = await connect(address, { | ||
| servername: 'localhost', | ||
| verifyPeer: 'manual', | ||
| alpn: 'h3', | ||
| onsessionticket(value) { | ||
| ticket ??= value; | ||
| if (token !== undefined) resolve(); | ||
| }, | ||
| onnewtoken(value) { | ||
| token ??= value; | ||
| if (ticket !== undefined) resolve(); | ||
| }, | ||
| }); | ||
| await session.opened; | ||
| await promise; | ||
| session.close(); | ||
| await session.closed.catch(() => {}); | ||
| resume = { sessionTicket: ticket, token }; | ||
| } | ||
|
|
||
| // The timed 0-RTT exchanges deliberately never await session.opened, since | ||
| // waiting for the handshake is exactly what 0-RTT avoids. That leaves no | ||
| // opportunity to notice early data being refused, so check separately - | ||
| // 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, { | ||
| servername: 'localhost', | ||
| verifyPeer: 'manual', | ||
| alpn: 'h3', | ||
| ...resume, | ||
| }); | ||
| const stream = await session.createBidirectionalStream({ | ||
| headers: request, | ||
| onheaders, | ||
| }); | ||
| const info = await session.opened; | ||
| await bytes(stream); | ||
| session.close(); | ||
| await session.closed.catch(() => {}); | ||
| if (!info.earlyDataAccepted) { | ||
| throw new Error('0-RTT was not accepted, benchmark would be invalid'); | ||
| } | ||
| } | ||
|
|
||
| for (let i = 0; i < 20; i++) await exchange(resume); | ||
| if (mode === '0rtt') await checkEarlyDataAccepted(); | ||
|
|
||
| received = 0; | ||
| bench.start(); | ||
| for (let i = 0; i < n; i++) await exchange(resume); | ||
| bench.end(n); | ||
|
|
||
| if (received !== n) throw new Error(`missing responses: ${received}/${n}`); | ||
| // The ticket is reused for every iteration, so confirm it was still being | ||
| // accepted at the end of the run and not just at the start. | ||
| if (mode === '0rtt') await checkEarlyDataAccepted(); | ||
| await endpoint.close(); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| 'use strict'; | ||
|
|
||
| // Measures the cost of establishing QUIC sessions: how many complete | ||
| // handshakes per second a single endpoint can serve, for raw QUIC and for | ||
| // HTTP/3. Nothing is sent on the session beyond what the protocol itself | ||
| // requires, so this isolates connection setup rather than data transfer. | ||
|
|
||
| const common = require('../common.js'); | ||
| const fixtures = require('../../test/common/fixtures'); | ||
| 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. | ||
| 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 key = createPrivateKey(fixtures.readKey('agent1-key.pem')); | ||
| const cert = fixtures.readKey('agent1-cert.pem'); | ||
| const alpn = protocol === 'h3' ? 'h3' : 'quic-bench'; | ||
|
|
||
| const endpoint = await listen((session) => { | ||
| // A benchmark peer never reads these; swallow so a torn-down session | ||
| // cannot produce an unhandled rejection. | ||
| session.opened.catch(() => {}); | ||
| session.closed.catch(() => {}); | ||
| }, { | ||
| sni: { '*': { keys: [key], certs: [cert] } }, | ||
| alpn: [alpn], | ||
| // The defaults rate-limit session creation per host, which a benchmark | ||
| // hammering a single address would otherwise trip. | ||
| endpoint: { | ||
| maxConnectionsPerHost: 0xFFFF, | ||
| maxConnectionsTotal: 0xFFFF, | ||
| sessionCreationRate: 1_000_000, | ||
| sessionCreationBurst: 1_000_000, | ||
| }, | ||
| }); | ||
|
|
||
| const address = endpoint.address; | ||
|
|
||
| async function handshake() { | ||
| const session = await connect(address, { | ||
| servername: 'localhost', | ||
| verifyPeer: 'manual', | ||
| alpn, | ||
| }); | ||
| await session.opened; | ||
| session.close(); | ||
| await session.closed.catch(() => {}); | ||
| } | ||
|
|
||
| async function run(count) { | ||
| for (let i = 0; i < count; i += concurrency) { | ||
| const batch = Math.min(concurrency, count - i); | ||
| await Promise.all(Array.from({ length: batch }, handshake)); | ||
| } | ||
| } | ||
|
|
||
| // Warm up the TLS and QUIC machinery before measuring. | ||
| await run(Math.min(100, n)); | ||
|
|
||
| bench.start(); | ||
| await run(n); | ||
| bench.end(n); | ||
|
|
||
| await endpoint.close(); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.