This repository has been archived by the owner on Aug 11, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[WIP] benchmark: add basic QUIC benchmark
- Loading branch information
Showing
1 changed file
with
73 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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,73 @@ | ||
// Test the speed of .pipe() with QUIC sockets | ||
'use strict'; | ||
|
||
const common = require('../common.js'); | ||
const quic = require('quic'); | ||
const fixtures = require('../../test/common/fixtures'); | ||
|
||
const key = fixtures.readKey('agent1-key.pem', 'binary'); | ||
const cert = fixtures.readKey('agent1-cert.pem', 'binary'); | ||
const ca = fixtures.readKey('ca1-cert.pem', 'binary'); | ||
|
||
const bench = common.createBenchmark(main, { | ||
dur: [5], | ||
}); | ||
|
||
function main({ dur, len, type }) { | ||
const server = quic.createSocket({ port: 0, validateAddress: true }); | ||
|
||
server.listen({ | ||
key, | ||
cert, | ||
ca, | ||
rejectUnauthorized: false, | ||
alpn: 'meow' | ||
}); | ||
|
||
server.on('session', (session) => { | ||
session.on('stream', (stream) => { | ||
stream.pipe(stream); | ||
}); | ||
}); | ||
|
||
const buffer = Buffer.alloc(102400); | ||
let received = 0; | ||
|
||
server.on('ready', () => { | ||
const client = quic.createSocket({ | ||
port: 0, | ||
client: { | ||
key, | ||
cert, | ||
ca, | ||
alpn: 'meow' | ||
} | ||
}); | ||
|
||
const req = client.connect({ | ||
address: 'localhost', | ||
port: server.address.port | ||
}); | ||
|
||
req.on('secure', () => { | ||
const stream = req.openStream({ halfOpen: false }); | ||
stream.on('data', (chunk) => received += chunk.length); | ||
|
||
function write() { | ||
stream.write(buffer, write); | ||
} | ||
|
||
bench.start(); | ||
write(); | ||
|
||
setTimeout(() => { | ||
// Multiply by 2 since we're sending it first one way | ||
// then then back again. | ||
const bytes = received * 2; | ||
const gbits = (bytes * 8) / (1024 * 1024 * 1024); | ||
bench.end(gbits); | ||
process.exit(0); | ||
}, dur * 1000); | ||
}); | ||
}); | ||
} |